<!doctype html>
<html lang="<?php echo e(str_replace('_', '-', app()->getLocale())); ?>">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="author" content="Ali">
    <meta name="description" content="<?php echo e(getSettingsOf("admin_title")); ?>| E-commerce Application">
    <meta name="csrf-token" content="<?php echo e(csrf_token()); ?>">
    <link rel="shortcut icon" href="<?php echo e(url("img/favicon.png")); ?>" type="image/x-icon">
    <link rel="icon" href="<?php echo e(url("img/favicon.png")); ?>" type="image/x-icon">
    <title><?php echo e(getSettingsOf("admin_title")); ?> | <?php echo $__env->yieldContent('title', __('Dashboard')); ?></title>
    <!-- Fonts -->
    <link href="<?php echo e(url('backend/vendor/fontawesome-free/css/all.min.css')); ?>" rel="stylesheet" type="text/css">
    <link href="<?php echo e(url('backend/vendor/fontawesome-free/css/v4-shims.css')); ?>" rel="stylesheet" type="text/css">
    <link href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i" rel="stylesheet">
    <!-- Styles -->
    
    <link href="<?php echo e(url('backend/css/sb-admin-2.css')); ?>" rel="stylesheet">
    
    <link rel="stylesheet" href="<?php echo e(url('backend/vendor/bootstrap-fileinput/css/fileinput.min.css')); ?>">
    <link rel="stylesheet" href="<?php echo e(url('backend/vendor/summernote/summernote-bs4.min.css')); ?>">
    <link rel="stylesheet" href="<?php echo e(url('backend/css/custom.css')); ?>">

    <!-- Jquery JS-->
    <script src="<?php echo e(url('vendor/jquery-3.2.1.min.js')); ?>"></script>

    <!-- Multi Select CSS== -->
    <link rel="stylesheet" type="text/css" href="<?php echo e(url("vendor/bootstrap-multiselect/bootstrap-multiselect.css")); ?>">

    <!-- Multi Select CSS== -->
    <link rel="stylesheet" type="text/css" href="<?php echo e(url("vendor/datepicker/datepicker.css")); ?>">

    <!-- Bootstrap form widzard Css Plugin== -->
    <link rel="stylesheet" href="<?php echo e(url('vendor/bootstrap-form-widzard/bs-form-widzard.css')); ?>">

    <link rel="stylesheet" href="<?php echo e(url('backend/vendor/select2/css/select2.min.css')); ?>">

    <link rel="stylesheet" href="<?php echo e(url('vendor/swal2-style.css')); ?>">
    <link rel="stylesheet" href="<?php echo e(config('sweetalert.animatecss')); ?>">
    <link rel="stylesheet" href="<?php echo e(url('vendor/util.css')); ?>">
    <link rel="stylesheet" href="<?php echo e(url('vendor/preloader.css')); ?>">
    <?php echo \Livewire\Livewire::styles(); ?>


    <?php echo $__env->yieldContent('styles'); ?>

    

    <link href="<?php echo e(url("vendor/bootstrap/bootstrap5.0.2.min.css")); ?>" rel="stylesheet">

    <link
        href="https://cdn.jsdelivr.net/npm/bootstrap5-toggle@5.0.6/css/bootstrap5-toggle.min.css"
        rel="stylesheet" />
    <script src="https://cdn.jsdelivr.net/npm/bootstrap5-toggle@5.0.6/js/bootstrap5-toggle.jquery.min.js"></script>

    <style>
        :root {
            --app-green: #619848 !important;
            --app-green-olive: #41ad49 !important;
            --blue: #4e73df !important;
            --indigo: #6610f2 !important;
            --purple: #6f42c1 !important;
            --pink: #e83e8c !important;
            --red: #e74a3b !important;
            --orange: #fd7e14 !important;
            --yellow: #f6c23e !important;
            --green: #1cc88a !important;
            --teal: #20c9a6 !important;
            --cyan: #36b9cc !important;
            --white: #fff !important;
            --gray: #858796 !important;
            --gray-dark: #5a5c69 !important;
            --primary: #4e73df !important;
            --secondary: #858796 !important;
            --success: #1cc88a !important;
            --info: #36b9cc !important;
            --warning: #f6c23e !important;
            --danger: #e74a3b !important;
            --light: #f8f9fc !important;
            --dark: #5a5c69 !important;
            --black: #222 !important;

        }

        .text-red{color: var(--red) !important;}
        .text-green{color: var(--green) !important;}
        .text-blue{ color: var(--blue) !important;}
        .text-pink{color: var(--pink) !important;}
        .text-indigo{ color: var(--indigo) !important;}
        .text-purple{ color: var(--purple) !important;}
        .text-cyan{color: var(--cyan) !important;}
        .text-orange{ color: var(--orange) !important;}
        .text-yellow{ color: var(--yellow) !important;}

        .bg-red{background: var(--red) !important; color: var(--white) !important;}
        .bg-green{background: var(--green) !important; color: var(--white) !important;}
        .bg-blue{ background: var(--blue) !important; color: var(--white) !important;}
        .bg-pink{background: var(--pink) !important; color: var(--white) !important;}
        .bg-indigo{ background: var(--indigo) !important; color: var(--white) !important;}
        .bg-purple{ background: var(--purple) !important; color: var(--white) !important;}
        .bg-cyan{background: var(--cyan) !important; color: var(--white) !important;}
        .bg-orange{ background: var(--orange) !important; color: var(--white) !important;}
        .bg-yellow{ background: var(--yellow) !important; color: var(--white) !important;}
        .bg-teal{ background: var(--teal) !important; color: var(--white) !important;}


    </style>

    <?php echo $__env->make("shared.datatables-assets-css", \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>

</head>
<body id="page-top">

<div id="app">
    <div id="wrapper">
        <?php echo $__env->make('partials.backend.sidebar', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
        <div id="content-wrapper" class="d-flexs flex-columns">
            <div id="content">
            <?php echo $__env->make('partials.backend.navbar', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
            <!-- Begin Page Content -->
                <div class="container-fluid">
                    <?php echo $__env->make('partials.backend.flash', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                    <?php echo $__env->yieldContent('content'); ?>
                </div>
            </div>

            <?php echo $__env->make('partials.backend.offcanvas-settings-app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
            <?php echo $__env->make('partials.backend.footer', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
        </div>
    </div>
    <!-- Scroll to Top Button-->
    <a class="scroll-to-top rounded" href="#page-top">
        <i class="fas fa-angle-up"></i>
    </a>
    <?php echo $__env->make('partials.backend.modal', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
</div>


<script defer src="<?php echo e(url("vendor/alpinejs3.x.x.min.js")); ?>"></script>

<?php echo \Livewire\Livewire::scripts(); ?>



<script src="<?php echo e(asset('backend/vendor/jquery-easing/jquery.easing.min.js')); ?>"></script>
<script src="<?php echo e(asset('backend/vendor/bootstrap/js/bootstrap.bundle.js')); ?>"></script>
<script src="<?php echo e(asset('backend/js/sb-admin-2.min.js')); ?>"></script>
<script src="<?php echo e(asset('backend/js/custom.js')); ?>"></script>
<!-- file input -->
<script src="<?php echo e(asset('backend/vendor/bootstrap-fileinput/js/plugins/piexif.min.js')); ?>"></script>
<script src="<?php echo e(asset('backend/vendor/bootstrap-fileinput/js/plugins/sortable.min.js')); ?>"></script>
<script src="<?php echo e(asset('backend/vendor/bootstrap-fileinput/js/fileinput.min.js')); ?>"></script>
<script src="<?php echo e(asset('backend/vendor/bootstrap-fileinput/themes/fas/theme.min.js')); ?>"></script>
<!-- summernote -->
<script src="<?php echo e(asset('backend/vendor/summernote/summernote-bs4.min.js')); ?>"></script>

<script type="text/javascript" src="<?php echo e(url('vendor/bootstrap-multiselect/bootstrap-multiselect.js')); ?>"></script>
<script src="<?php echo e(url('vendor/datepicker/bootstrap-datepicker.js')); ?>"></script>

<script src="<?php echo e(asset('vendor/sweetalert/sweetalert.all.js')); ?>"></script>

<script src="<?php echo e(asset('backend/vendor/select2/js/select2.full.min.js')); ?>"></script>

<script  src="<?php echo e(url("vendor/xpeedy.js")); ?>"></script>



<script src="<?php echo e(url("vendor/bootstrap/bootstrap.5.0.2.bundle.min.js")); ?>" type="text/javascript"></script>
<?php echo $__env->yieldContent('scripts'); ?>

<?php echo $__env->make('shared.services-js', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<?php echo $__env->make('shared.datatable-assets-js', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>

<script>
    document.addEventListener("alpine:init", e=> {

        Alpine.data('displayable_orders' , (param = {})=>({

            init (){
                const that = this;
                const td_index = param?.td_index ?? 0;
                const displayed_into_offcanvas = param?.displayed_into_offcanvas ?? true;
                const initialized = param?.table?.initialized ?? true;
                const processAfterOpen = ('processAfterOpen' in param) ? param.processAfterOpen : ()=>{}

                that.$nextTick(async () => {

                    if(!initialized){
                        initDataTable(that.table_id,that.table_options);
                    }

                    $("table.table").on("click","tbody tr td .btn-action-click",async (e)=>{
                        // const table  = $table.DataTable(); // <button></button>
                        const $button = $(e.target); // <button></button>
                        const $td = $button.closest("td"); // <td></td>
                        const $table = $td.closest("table"); // 1er parent '<table>'
                        const  index = $td.index();  // l'index de la colonne [1]
                        const table_id = $table.attr('id');
                        const dataTable = $table.DataTable(); // DataTable
                        const rowData = dataTable.row($td).data(); // Les données de la ligne

                        $table.find("td").removeClass("selected")

                        if(index === td_index){ //
                            $td.addClass("selected")

                            if(displayed_into_offcanvas){
                                showOffcanvas("offcanvas-displayed-invoice",true)
                            }
                            await that.$store.invoice.open(rowData.ref_id);
                            processAfterOpen();
                        }else{
                            $table.find("td").removeClass("selected")
                            $td.removeClass("selected")
                        }
                    })

                    const time = 1000 * 60; // 1min
                    //that.timer = setInterval( () => refresh_datatable(that.table_id,getUrl('<?php echo e(route("admin.orders.traitments.list")); ?>')), time)

                })
            },
            destroy(){
                clearInterval(this.timer)
            },

            timer : null ,
            table_id : param?.table?.id ?? "table-sales",

            get table_options(){
                return param?.table?.options ?? {};
            },

            initDataTable(){
                let table_id = this.table_id;
                return  ($.fn.dataTable.isDataTable('#'+table_id))
                    ? $("#"+table_id).DataTable()
                    : new DataTable("#"+table_id,this.table_options)
            },

            refreshOrdersList(){
                refresh_datatable(this.table_id,getUrl())
            },

        }))


        Alpine.store('invoice' , {
            order : null,
            loading : false,

            async open(order, is_online = true){
                this.loading = true;
                this.setOrder(null);

                if (is_online){
                    let ref_id = order;
                    if(isObject(order) && ('ref_id' in order)) {
                        ref_id = order.ref_id;
                    }
                    const response = await request("<?php echo e(route("admin.orders.traitments.show")); ?>?ref_id="+ref_id);
                    if ( ('ref_id' in response) ){
                        order = response;
                    }else{
                        order = null;
                    }
                }
                this.loading = false;
                if(filled(order))  order.is_online = is_online;
                this.setOrder(order)
            },
            close(){
                this.setOrder(null);
            },
            print(){
                if(filled(this.order)){
                    return  printHtmlBlock('invoice-block','INVOICE-'+this.order.ref_id)
                }
                return null;
            },
            setOrder(order){
                if(filled(order)){
                    order.reference = order?.ref_id ?? order?.ref ?? null;
                }
                this.order = order;
            },

            changeOrderStatus (order , status,callback = ()=> {}) {
                const that = this;
                let next_status_code = status;
                let  status_name = status;
                let status_badge_dot = "";
                const {ref_id,id} = order

                if (isObject(status)) {
                    next_status_code = status.code;
                    status_badge_dot = status.badge_label;
                    status_name = status.name;
                }

                const canceled_statuses = <?php echo json_encode(\App\Models\OrderManagement\Order::getStatusesRequiredRaesons(), 15, 512) ?>;

                const cancel = canceled_statuses.find(s=> s === next_status_code)
                let  body = {   status_code : next_status_code,};

                const editor = DataTableEditor( {
                    ajax : { url :"<?php echo e(route("admin.orders.set-status")); ?>/"+id, type : 'put' },
                    fields: [
                        {
                            label: "<?php echo e(__('Reason')); ?> : ",
                            name: "reason" ,
                            
                            type: "textarea",
                           // message: null,
                            processing : "<div class='loader'></div>",
                            attr : {  rows: 3, cols : 3},
                            fieldInfo : "<?php echo e(__("Ajouter une raison a ce changement de statut")); ?>",
                        },
                    ]
                } );

                let title = "<?php echo e(__("Add Reason before to set in this Status")); ?>"

                const confirmMessage = "<div class='fs-14 font-weight-bold text-center'> Set '"+ref_id+"' to "+status_badge_dot+" ?</div>";
                if ( blank(cancel)){
                    editor.field("reason").hide();
                    title = "<?php echo e(__("Confirmation")); ?>";
                }

                editor.field('reason').input().on("input", (e)=>{

                })

                return editor.create({
                    title ,
                    message : confirmMessage,
                    buttons: {
                        label: "<?php echo e(__('OK')); ?>",
                        className : "btn-success",
                        fn :  function (e) {
                            body.reason = editor.field("reason").get();

                            this.submit(
                                (response) => {
                                    if ('success' in response){
                                        if(response.success){
                                            console.log("request successfully" );
                                            callback();
                                        }
                                        else{
                                            swal.showValidationMessage(`${response.message}`);
                                            console.log("request failed" );
                                        }
                                    }
                                },
                                (error) => {
                                    // console.log(error)

                                    const fieldErrors = error.fieldErrors ?? [];

                                    if (blank(fieldErrors)){
                                        swal.fire({
                                            icon : "error" ,
                                            title : "Oops...!",
                                            html : error.message,
                                            willClose : ()=>{
                                                editor.close();
                                            }
                                        });
                                    }
                                },
                                (data) => {
                                    let d = data.data;
                                    $.each(d , (index,val)=>{
                                        // data.data[index] = {
                                        //     scheduled_at : val.scheduled_at,
                                        //     amount_is_reserved : val.amount_is_reserved,
                                        // }
                                    });

                                    //parametre signifiant à la requete qu'on veut supprimer définitivement
                                    data.reason = body.reason;
                                    data.status_code = body.status_code;
                                    // return body
                                },
                            )
                        },
                    },
                } );

            },

        })
    })
</script>

<?php echo $__env->yieldPushContent('js'); ?>
</body>
</html>
<?php /**PATH /home/lekruu/public_html/resources/views/layouts/admin.blade.php ENDPATH**/ ?>