@extends('app.app')

@section('title')
    Assuransi
@endsection

@section('customcss')
    <style>
        /* .select2-container {
                                    z-index: 99999;
                                } */
    </style>
@endsection

@section('content')
    <div class="container-fluid">
        <div class="content">
            <div class="card">
                <div class="card-header">
                    <div class="row d-flex align-items-center">
                        <div class="col-3">
                            <p class="card-title text-bold mb-0">Asuransi (<span id="count_insurances">0</span>)</p>
                        </div>
                        <div class="col text-end">
                            <button id="btnMdlNewInsurance" class="btn btn-sm btn-danger">Buat Asuransi Baru</button>
                        </div>
                        <div class="col-auto text-end ps-0">
                            {{-- <button class="btn btn-sm btn-danger">Upload</button> --}}
                            {{-- <button class="btn btn-sm btn-danger">Download</button> --}}
                        </div>
                    </div>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table id="tInsurances" class="table table-hover dataTable">
                            <thead>
                                <tr class="">
                                    <th class="">#</th>
                                    <th class="text-center">Action</th>
                                    <th class="">Nama Premi</th>
                                    <th class="text-end">Range (Rp)</th>
                                    <th class="text-end">Harga Premi (Rp)</th>
                                    <th class="">Keterangan</th>
                                    <th class="text-center">Status</th>
                                </tr>
                            </thead>
                            <tbody>

                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" data-bs-backdrop="static" data-bs-keyboard="false" id="mdlNewInsurance" aria-labelledby="mdlNewInsuranceLabel" aria-hidden="true">
        <div class="modal-dialog modal-dialog modal-dialog-centered modal-dialog-scrollable modal-xl">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="mdlNewInsuranceLabel">Buat Asuransi Baru</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <form>
                        {{-- Primary --}}
                        <div class="mb-3">
                            <div class="border-bottom">
                                <h6>Data Premi</h6>
                            </div>
                            <div class="row">
                                <div class="col-sm-6">
                                    <label for="add-name" class="col-form-label">Nama Premi<span class="text-danger">*</span></label>
                                    <input type="text" name="add-name" id="add-name" class="form-control">
                                </div>
                                <div class="col-sm-6">
                                    <label for="add-price" class="col-form-label">Harga Premi<span class="text-danger">*</span></label>
                                    <input type="text" name="add-price" id="add-price" class="form-control">
                                </div>
                                <div class="col-sm-6">
                                    <label for="add-min_price" class="col-form-label">Jumlah Minimal Pertangguhan<span class="text-danger">*</span></label>
                                    <input type="text" name="add-min_price" id="add-min_price" class="form-control">
                                </div>
                                <div class="col-sm-6">
                                    <label for="add-max_price" class="col-form-label">Jumlah Maksimal Pertangguhan<span class="text-danger">*</span></label>
                                    <input type="text" name="add-max_price" id="add-max_price" class="form-control">
                                </div>
                                <div class="col-sm-12">
                                    <label for="add-desc" class="col-form-label">Keterangan</label>
                                    <textarea name="add-desc" id="add-desc" class="form-control"></textarea>
                                </div>
                            </div>
                        </div>
                        {{-- Utilites --}}
                        <div class="mb-3">
                            <div class="border-bottom">
                                <h6>Utilities</h6>
                            </div>
                            <div class="row">
                                <div class="col-sm-6 col-md-3">
                                    <label for="add-status" class="form-label">Status<span class="text-danger">*</span></label>
                                    <div class="form-check form-switch">
                                        <input class="form-check-input" type="checkbox" id="add-status">
                                        <label class="form-check-label" for="add-status"><span class="text-dark" id="add-txtStatus">Inactive</span></label>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-sm btn-secondary" data-bs-dismiss="modal">Close</button>
                    <button id="btnSubmitNewInsurance" type="button" class="btn btn-sm btn-danger">Submit data</button>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" data-bs-backdrop="static" data-bs-keyboard="false" id="mdlEdtInsurances" aria-labelledby="mdlEdtInsurancesLabel" aria-hidden="true">
        <div class="modal-dialog modal-dialog modal-dialog-centered modal-dialog-scrollable modal-xl">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="mdlEdtInsurancesLabel">Edit Asuransi</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <form>
                        {{-- Primary --}}
                        <div class="mb-3">
                            <div class="border-bottom">
                                <h6>Data Premi</h6>
                            </div>
                            <div class="row">
                                <div class="col-sm-6">
                                    <label for="updt-name" class="col-form-label">Nama Premi<span class="text-danger">*</span></label>
                                    <input type="text" name="updt-name" id="updt-name" class="form-control">
                                </div>
                                <div class="col-sm-6">
                                    <label for="updt-price" class="col-form-label">Harga Premi<span class="text-danger">*</span></label>
                                    <input type="text" name="updt-price" id="updt-price" class="form-control">
                                </div>
                                <div class="col-sm-6">
                                    <label for="updt-min_price" class="col-form-label">Jumlah Minimal Pertangguhan<span class="text-danger">*</span></label>
                                    <input type="text" name="updt-min_price" id="updt-min_price" class="form-control">
                                </div>
                                <div class="col-sm-6">
                                    <label for="updt-max_price" class="col-form-label">Jumlah Maksimal Pertangguhan<span class="text-danger">*</span></label>
                                    <input type="text" name="updt-max_price" id="updt-max_price" class="form-control">
                                </div>
                                <div class="col-sm-12">
                                    <label for="updt-desc" class="col-form-label">Keterangan</label>
                                    <textarea name="updt-desc" id="updt-desc" class="form-control"></textarea>
                                </div>
                            </div>
                        </div>
                        {{-- Utilites --}}
                        <div class="mb-3">
                            <div class="border-bottom">
                                <h6>Utilities</h6>
                            </div>
                            <div class="row">
                                <div class="col-sm-6 col-md-3">
                                    <label for="updt-status" class="form-label">Status<span class="text-danger">*</span></label>
                                    <div class="form-check form-switch">
                                        <input class="form-check-input" type="checkbox" id="updt-status">
                                        <label class="form-check-label" for="updt-status"><span class="text-dark" id="updt-txtStatus">Inactive</span></label>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" id="btnDelInsurance_updt" class="btn btn-sm btn-warning">Hapus ?</button>
                    <button type="button" class="btn btn-sm btn-secondary" data-bs-dismiss="modal">Close</button>
                    <button id="btnSubmitEdtInsurances" type="button" class="btn btn-sm btn-danger">Update Data</button>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" data-bs-backdrop="static" data-bs-keyboard="false" id="mdlDelInsurance" aria-labelledby="mdlDelInsuranceLabel" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered modal-sm">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="mdlDelInsuranceLabel">Delete Asuransi</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <div class="d-flex justify-content-center">
                        <p class="mb-0">
                            Kamu yakin ingin menghapus asuransi
                            <a href="#" class="text-danger">
                                <span id="del-name"></span>
                            </a>
                            ?
                        </p>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-sm btn-danger" data-bs-dismiss="modal">Close</button>
                    <button id="btnSubmitDelInsurance" type="button" class="btn btn-sm btn-secondary">Iya, hapus</button>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('customjs')
    <script src="{{ asset('assets/js/load-image.all.min.js') }}"></script>
    <script>
        'use strict';
        const State = {
            file_jimp_worker: "{{ asset('assets/js/worker/jimp.js') }}",
            storage_lara: "{{ asset('storage') }}/",
            stts_isact: {
                active: "{{ App\Models\Insurances::IS_ACTIVE }}",
                inactive: "{{ App\Models\Insurances::IS_INACTIVE }}",
            },
            delay_typing_front: 1000,
        };

        const Wrapper = {
            activate: function() {
                Wrapper.event();
                DTable.activate();
                ANew.activate();
                AUpdt.activate();
                ADel.activate();
            },
            event: function() {
                $('#add-status').bind('change', function() {
                    if ($(this).is(':checked'))
                        $('#add-txtStatus').html('Active')
                    else
                        $('#add-txtStatus').html('Inactive')
                });
                $('#updt-status').bind('change', function() {
                    if ($(this).is(':checked'))
                        $('#updt-txtStatus').html('Active')
                    else
                        $('#updt-txtStatus').html('Inactive')
                });
            },
        };

        const DTable = {
            activate: function() {
                DTable.reload();
            },
            reload: function() {
                // $('#tInsurances').DataTable();
                // if (Driver.Table.firstInitDataTable == 1) { loadTableSkeletonLoading() } else { Driver.Table.firstInitDataTable = 1; }
                $('#tInsurances').DataTable({
                    processing: true,
                    serverSide: false,
                    bLengthChange: true,
                    deferRender: true,
                    destroy: true,
                    ajax: {
                        url: "{{ route('api_list_insurances') }}",
                        type: 'GET',
                        complete: function(jqXHR, textStatus, c) {
                            let count = jqXHR.responseJSON.count;
                            if (typeof count != 'undefined') {
                                $('#count_insurances').text(count);
                            }
                            // removeTableSkeletonLoading()
                        },
                    },
                    deferRender: true,
                    columns: [{
                            data: 'DT_RowIndex',
                            className: 'text-end',
                            visible: true,
                            orderable: true,
                            searchable: true,
                        },
                        {
                            data: 'action',
                            className: 'text-center',
                            visible: true,
                            orderable: true,
                            searchable: true,
                            render: function(data, type, row, meta) {
                                let action = `
									<a href="#" class="text-decoration-none me-1 btnUpdtInsurance">
										<span class="icon ion-edit fz-16"></span>
									</a>
                                    `;
                                // <a href="#" class="text-decoration-none text-danger btnDelInsurance">
                                //     <span class="icon ion-trash-b fz-16"></span>
                                // </a>
                                return action;
                            }
                        },
                        {
                            data: 'premi_name',
                            className: 'text-start text-nowrap',
                            visible: true,
                            orderable: true,
                            searchable: true,
                            createdCell: function(td, cellData, rowData, row, col) {
                                $(td).attr('data-iid', rowData.id);
                                $(td).attr('data-premi_name', rowData.premi_name);
                                $(td).attr('data-premi_price', rowData.premi_price);
                            },
                        },
                        {
                            data: 'premi_min_price',
                            className: 'text-end text-nowrap',
                            visible: true,
                            orderable: true,
                            searchable: true,
                            render: function(data, type, row, meta) {
                                return (new Intl.NumberFormat('id-ID')).format(data) + ' - ' + (
                                    new Intl.NumberFormat('id-ID')).format(row.premi_max_price);
                            }
                        },
                        {
                            data: 'premi_price',
                            className: 'text-end text-nowrap',
                            visible: true,
                            orderable: true,
                            searchable: true,
                            render: function(data, type, row, meta) {
                                return (new Intl.NumberFormat('id-ID')).format(data);
                            }
                        },
                        {
                            data: 'desc',
                            className: 'text-start',
                            visible: true,
                            orderable: true,
                            searchable: true,
                            render: function(data, type, row, meta) {
                                if (!data) return '-';
                                return data;
                            }
                        },
                        {
                            data: 'is_active',
                            className: 'text-center text-nowrap',
                            visible: true,
                            orderable: true,
                            searchable: true,
                            render: function(data, type, row, meta) {
                                if (data == State.stts_isact.active)
                                    return '<span class="badge rounded-pill bg-success">Active</span>';
                                return '<span class="badge rounded-pill bg-danger">Inactive</span>';
                            }
                        },
                    ],
                });
            },
        };

        const ANew = {
            activate: function() {
                ANew.event();
            },
            event: function() {
                // modal
                $('#btnMdlNewInsurance').on('click', function() {
                    $('#mdlNewInsurance').modal('show');
                });
                $('#mdlNewInsurance').on('shown.bs.modal', function() {

                });
                // button
                $('#btnSubmitNewInsurance').on('click', function() {
                    let data = ANew.getData();
                    ANew.submitData(data);
                });
                // input
                $('#add-price').on('keyup', function(e) {
                    let price = '';
                    if ($('#add-price').val().length < 1) {
                        price = '';
                    } else {
                        price = Number($('#add-price').val().split('.').join(''))
                        price = (new Intl.NumberFormat('id-ID')).format(price);
                    }
                    $('#add-price').val(price);
                });
                $('#add-min_price').on('keyup', function(e) {
                    let min_price = '';
                    if ($('#add-min_price').val().length < 1) {
                        min_price = '';
                    } else {
                        min_price = Number($('#add-min_price').val().split('.').join(''))
                        min_price = (new Intl.NumberFormat('id-ID')).format(min_price);
                    }
                    $('#add-min_price').val(min_price);
                });
                $('#add-max_price').on('keyup', function(e) {
                    let max_price = '';
                    if ($('#add-max_price').val().length < 1) {
                        max_price = '';
                    } else {
                        max_price = Number($('#add-max_price').val().split('.').join(''))
                        max_price = (new Intl.NumberFormat('id-ID')).format(max_price);
                    }
                    $('#add-max_price').val(max_price);
                });
            },
            getData: function() {
                let data = {};
                data.name = $('#add-name').val();
                data.desc = $('#add-desc').val();

                data.price = $('#add-price').val().split('.').join('');
                data.min_price = $('#add-min_price').val().split('.').join('');
                data.max_price = $('#add-max_price').val().split('.').join('');

                if ($('#add-status').prop('checked')) {
                    data.status = State.stts_isact.active;
                } else {
                    data.status = State.stts_isact.inactive;
                }

                return data;
            },
            submitData: async function(data) {
                return new Promise((resolve, reject) => {
                    if (typeof $('#btnSubmitNewInsurance').attr('disabed') != 'undefined') {
                        resolve({
                            type: 'fail'
                        });
                        return false;
                    }
                    $('#btnSubmitNewInsurance').attr('disabed', true);
                    $.ajax({
                        url: "{{ route('api_add_insurance') }}",
                        method: 'POST',
                        crossDomain: true,
                        processData: true,
                        headers: {
                            'x-api-key': Helper.getCookie('_trtk'),
                            'x-csrf-token': $('meta[name="csrf-token"]').attr('content'),
                        },
                        data: data,
                        success: (data, textStatus, jqXHR) => {
                            $('#btnSubmitNewInsurance').removeAttr('disabed');
                            if (data.meta.type != 'success') {
                                resolve({
                                    type: 'fail'
                                });
                                Helper.toast('Warning', 'just now', data.meta.message);
                                return false;
                            }
                            Helper.toast('Success', 'just now', 'success add new insurance');
                            $('#mdlNewInsurance').modal('hide');
                            DTable.reload();
                            resolve({
                                type: 'success'
                            });
                        },
                        error: (jqXHR, textStatus, error) => {
                            $('#btnSubmitNewInsurance').removeAttr('disabed');
                            if (jqXHR.status >= 500) {
                                Helper.toast('Error', 'just now', 'Please try again');
                            } else {
                                Helper.toast('Error', 'just now', jqXHR.responseJSON.meta
                                    .message);
                            }
                            resolve({
                                type: 'error'
                            });
                        }
                    })
                })
            },
        }

        const AUpdt = {
            activate: function() {
                AUpdt.event();
            },
            event: function() {
                // modal
                $('#tInsurances').on('click', '.btnUpdtInsurance', async function(e) {
                    let iid = $(e.target).closest('tr').find('td[data-iid]').data('iid');
                    let resp = await AUpdt.reqData({
                        iid
                    });
                    if (resp.type != 'success') {
                        Helper.toast('Insurance Not Found', 'just now', 'please try again');
                        return false;
                    }
                    AUpdt.passDataToView(resp.data);
                });
                $('#mdlEdtInsurances').on('shown.bs.modal', function() {

                });
                // button
                $('#btnSubmitEdtInsurances').on('click', function() {
                    let data = AUpdt.getData();
                    AUpdt.submitData(data);
                });
                // input
                $('#updt-price').on('keyup', function(e) {
                    let price = '';
                    if ($('#updt-price').val().length < 1) {
                        price = '';
                    } else {
                        price = Number($('#updt-price').val().split('.').join(''))
                        price = (new Intl.NumberFormat('id-ID')).format(price);
                    }
                    $('#updt-price').val(price);
                });
                $('#updt-min_price').on('keyup', function(e) {
                    let min_price = '';
                    if ($('#updt-min_price').val().length < 1) {
                        min_price = '';
                    } else {
                        min_price = Number($('#updt-min_price').val().split('.').join(''))
                        min_price = (new Intl.NumberFormat('id-ID')).format(min_price);
                    }
                    $('#updt-min_price').val(min_price);
                });
                $('#updt-max_price').on('keyup', function(e) {
                    let max_price = '';
                    if ($('#updt-max_price').val().length < 1) {
                        max_price = '';
                    } else {
                        max_price = Number($('#updt-max_price').val().split('.').join(''))
                        max_price = (new Intl.NumberFormat('id-ID')).format(max_price);
                    }
                    $('#updt-max_price').val(max_price);
                });
            },
            reqData: function(params) {
                return new Promise((resolve, reject) => {
                    $.ajax({
                        url: "{{ route('api_show_insurance', '') }}/" + params.iid,
                        method: 'GET',
                        crossDomain: true,
                        processData: true,
                        headers: {
                            'x-api-key': Helper.getCookie('_trtk'),
                        },
                        data: params,
                        success: (data, textStatus, jqXHR) => {
                            if (data.meta.type != 'success') {
                                resolve({
                                    type: 'fail'
                                });
                                Helper.toast('Warning', 'just now', data.meta.message);
                                return false;
                            }
                            resolve({
                                type: 'success',
                                data: data.data
                            });
                        },
                        error: (jqXHR, textStatus, error) => {
                            if (jqXHR.status >= 500) {
                                Helper.toast('Error', 'just now', 'please try again');
                            } else {
                                Helper.toast('Error', 'just now', jqXHR.responseJSON.meta
                                    .message);
                            }
                            resolve({
                                type: 'error'
                            });
                        }
                    })
                });
            },
            passDataToView: async function(data) {
                $('#updt-name').val(data.premi_name);
                $('#updt-desc').val(data.desc);

                $('#updt-price').val((new Intl.NumberFormat('id-ID').format(data.premi_price)));
                $('#updt-min_price').val((new Intl.NumberFormat('id-ID').format(data.premi_min_price)));
                $('#updt-max_price').val((new Intl.NumberFormat('id-ID').format(data.premi_max_price)));

                if (data.is_active == State.stts_isact.active) {
                    $('#updt-status').prop('checked', true);
                } else {
                    $('#updt-status').prop('checked', false);
                }

                $('#mdlEdtInsurances').data('id', data.id);
                $('#mdlEdtInsurances').modal('show');
            },
            getData: function() {
                let data = {};
                data.iid = $('#mdlEdtInsurances').data('id');

                data.name = $('#updt-name').val();
                data.desc = $('#updt-desc').val();

                data.price = $('#updt-price').val().split('.').join('');
                data.min_price = $('#updt-min_price').val().split('.').join('');
                data.max_price = $('#updt-max_price').val().split('.').join('');

                if ($('#updt-status').prop('checked')) {
                    data.status = State.stts_isact.active;
                } else {
                    data.status = State.stts_isact.inactive;
                }

                return data;
            },
            submitData: async function(data) {
                return new Promise((resolve, reject) => {
                    if (typeof $('#btnSubmitEdtInsurances').attr('disabed') != 'undefined') {
                        resolve({
                            type: 'fail'
                        });
                        return false;
                    }
                    $('#btnSubmitEdtInsurances').attr('disabed', true);
                    $.ajax({
                        url: "{{ route('api_edit_insurance', '') }}/" + data.iid,
                        method: 'PUT',
                        crossDomain: true,
                        processData: true,
                        headers: {
                            'x-api-key': Helper.getCookie('_trtk'),
                            'x-csrf-token': $('meta[name="csrf-token"]').attr('content'),
                        },
                        data: data,
                        success: (data, textStatus, jqXHR) => {
                            $('#btnSubmitEdtInsurances').removeAttr('disabed');
                            if (data.meta.type != 'success') {
                                resolve({
                                    type: 'fail'
                                });
                                Helper.toast('Warning', 'just now', data.meta.message);
                                return false;
                            }
                            Helper.toast('Success', 'just now', 'success update insurance');
                            $('#mdlEdtInsurances').modal('hide');
                            DTable.reload();
                            resolve({
                                type: 'success'
                            });
                        },
                        error: (jqXHR, textStatus, error) => {
                            $('#btnSubmitEdtInsurances').removeAttr('disabed');
                            if (jqXHR.status >= 500) {
                                Helper.toast('Error', 'just now', 'Please try again');
                            } else {
                                Helper.toast('Error', 'just now', jqXHR.responseJSON.meta
                                    .message);
                            }
                            resolve({
                                type: 'error'
                            });
                        }
                    })
                })
            },
        }

        const ADel = {
            activate: function() {
                ADel.event();
            },
            event: function() {
                // on table
                $('#tInsurances').on('click', '.btnDelInsurance', function(e) {
                    let row = $(e.target).closest('tr');
                    let iid = row.find('td[data-iid]').data('iid');
                    let premi_name = row.find('td[data-premi_name]').data('premi_name');
                    let premi_price = row.find('td[data-premi_price]').data('premi_price');
                    ADel.passDataToView({
                        iid,
                        name: premi_name,
                        price: premi_price,
                    });
                    $('#mdlDelInsurance').data('id', iid);
                    $('#mdlDelInsurance').modal('show');
                });
                $('#btnSubmitDelInsurance').on('click', function() {
                    let data = {
                        iid: $('#mdlDelInsurance').data('id'),
                    };
                    ADel.submitData(data);
                });
                // on modal update
                $('#btnDelInsurance_updt').on('click', function(e) {
                    let data = AUpdt.getData();
                    ADel.passDataToView({
                        iid: data.iid,
                        name: data.name,
                        price: data.price,
                    });
                    $('#mdlDelInsurance').data('id', data.iid);
                    $('#mdlDelInsurance').modal('show');
                });
            },
            passDataToView: function(data) {
                $('#del-name').text(data.name);
                $('#del-price').text(data.price);
            },
            submitData: async function(data) {
                return new Promise((resolve, reject) => {
                    if (typeof $('#btnSubmitDelInsurance').attr('disabed') != 'undefined') {
                        resolve({
                            type: 'fail'
                        });
                        return false;
                    }
                    $('#btnSubmitDelInsurance').attr('disabed', true);
                    $.ajax({
                        url: "{{ route('api_del_insurance', '') }}/" + data.iid,
                        method: 'DELETE',
                        crossDomain: true,
                        processData: true,
                        headers: {
                            'x-api-key': Helper.getCookie('_trtk'),
                            'x-csrf-token': $('meta[name="csrf-token"]').attr('content'),
                        },
                        data: data,
                        success: (data, textStatus, jqXHR) => {
                            $('#btnSubmitDelInsurance').removeAttr('disabed');
                            if (data.meta.type != 'success') {
                                resolve({
                                    type: 'fail'
                                });
                                Helper.toast('Warning', 'just now', data.meta.message);
                                return false;
                            }
                            Helper.toast('Success', 'just now', 'success delete insurance');
                            $('#mdlDelInsurance').modal('hide');
                            $('#mdlEdtInsurances').modal('hide');
                            DTable.reload();
                            resolve({
                                type: 'success'
                            });
                        },
                        error: (jqXHR, textStatus, error) => {
                            $('#btnSubmitDelInsurance').removeAttr('disabed');
                            if (jqXHR.status >= 500) {
                                Helper.toast('Error', 'just now', 'Please try again');
                            } else {
                                Helper.toast('Error', 'just now', jqXHR.responseJSON.meta
                                    .message);
                            }
                            resolve({
                                type: 'error'
                            });
                        }
                    })
                })
            },
        }

        Wrapper.activate();
    </script>
@endsection
