$('#zero-config').DataTable({
    "dom": "<'dt--top-section'<'row'<'col-12 col-sm-6 d-flex justify-content-sm-start justify-content-center'l><'col-12 col-sm-6 d-flex justify-content-sm-end justify-content-center mt-sm-0 mt-3'f>>>" +
        "<'table-responsive'tr>" +
        "<'dt--bottom-section d-sm-flex justify-content-sm-between text-center'<'dt--pages-count  mb-sm-0 mb-3'i><'dt--pagination'p>>",
    "oLanguage": {
        "oPaginate": { "sPrevious": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-left"><line x1="19" y1="12" x2="5" y2="12"></line><polyline points="12 19 5 12 12 5"></polyline></svg>', "sNext": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-right"><line x1="5" y1="12" x2="19" y2="12"></line><polyline points="12 5 19 12 12 19"></polyline></svg>' },
        "sInfo": "Showing page _PAGE_ of _PAGES_",
        "sSearch": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-search"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>',
        "sSearchPlaceholder": "Search...",
        "sLengthMenu": "Results :  _MENU_",
    },
    "stripeClasses": [],
    "lengthMenu": [7, 10, 20, 50],
    "pageLength": 10
});

// For Archive

$(document).on("click", ".rest_archive_btn", function () {
    var data_id = $(this).data('id');
    $('#restaurants_id').val(data_id);
});

$(document).on("click", ".restaurants_archive", function (e) {
    e.preventDefault();
    let base_url = url_path;
    var archive_id = $('#restaurants_id').val();
    $.ajaxSetup({
        headers: {
            "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
        },
    });
    $.ajax({
        type: "DELETE",
        url: base_url + "/manage_restaurants_archive/" + archive_id,
        success: function (response) {
            if (response.status == 200) {
                toastr.success('Record has been archive');
                setTimeout(function () {
                    window.location.href = base_url + "/restaurant_users";
                }, 1000);
            } else {
                toastr.error("Something went wrong");
            }
        },
    });
});

// For Un-archive

$(document).on("click", ".rest_unarchive_btn", function () {
    var data_id = $(this).data('id');
    $('#unarchive_id').val(data_id);
});

$(document).on("click", ".restaurant_unarchive", function (e) {
    e.preventDefault();
    let base_url = url_path;
    var archive_id = $('#unarchive_id').val();
    $.ajaxSetup({
        headers: {
            "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
        },
    });
    $.ajax({
        type: "POST",
        url: base_url + "/manage_restaurants_unarchive/" + archive_id,
        success: function (response) {
            if (response.status == 200) {
                toastr.success('Record has been');
                setTimeout(function () {
                    window.location.href = base_url + "/restaurant_users";
                }, 1000);
            } else {
                toastr.error("Something went wrong");
            }
        },
    });
});

//old code for change status

    // $(".rest_users_table").on("change", ".active_rest_user", function () {
    //     let base_url = url_path;
    //     var status = $(this).prop("checked") == true ? 1 : 0;
    //     var rest_user_id = $(this).data("id");

    //     $.ajax({
    //         type: "GET",
    //         dataType: "json",
    //         url: base_url + '/change_rest_status',
    //         data: {
    //             status: status,
    //             rest_user_id: rest_user_id,
    //         },
    //         success: function (data) {
    //             if (status == 1) {
    //                 toastr.options = {
    //                     "timeOut": 500
    //                 }
    //                 toastr.success("Status Activate successfully. !!");
    //             } else {
    //                 toastr.error("Status Deactivate successfully. !!");
    //             }
    //         },
    //     });
    // });

    // $(document).ready(function () {
    //     // Handle approve button click
    //     $(".approve-btn").on("click", function () {
    //         let base_url = url_path;
    //         var rest_user_id = $(this).data("id");
    //         var status = 1;

    //         $.ajax({
    //             type: "GET",
    //             dataType: "json",
    //             url: base_url + '/change_rest_status',
    //             data: {
    //                 status: status,
    //                 rest_user_id: rest_user_id,
    //             },
    //             success: function (data) {
    //                 toastr.options = {
    //                     "timeOut": 500
    //                 }
    //                 toastr.success("User approved and status activated successfully. !!");

    //                 // Update the switch to active
    //                 $('#switch' + rest_user_id).prop('checked', true);
    //             },
    //         });
    //     });

    //     // Handle disapprove button click
    //     $(".disapprove-btn").on("click", function () {
    //         let base_url = url_path;
    //         var rest_user_id = $(this).data("id");
    //         var status = 0;

    //         $.ajax({
    //             type: "GET",
    //             dataType: "json",
    //             url: base_url + '/change_rest_status',
    //             data: {
    //                 status: status,
    //                 rest_user_id: rest_user_id,
    //             },
    //             success: function (data) {
    //                 toastr.error("User disapproved and status deactivated successfully. !!");

    //                 // Update the switch to inactive
    //                 $('#switch' + rest_user_id).prop('checked', false);
    //             },
    //         });
    //     });


    //     $(".rest_users_table").on("change", ".active_rest_user", function () {
    //         // Revert the switch change
    //         var rest_user_id = $(this).data("id");
    //         var currentStatus = $(this).prop("checked");

    //         // Revert the switch state
    //         $(this).prop("checked", !currentStatus);

    //         toastr.options = {
    //             "timeOut": 6000
    //         }
    //         toastr.error("You can only change the status using Approve/Disapprove buttons.");
    //     });

    // });
   
    // $(document).ready(function() {
    //     // console.log('dfkjb');
    //         $('#rest_user_form').validate({
    //             ignore: [],
    //             debug: false,
    //             rules: {
    //                 first_name: {
    //                     required: true,
    //                     fullNameCharactersOnly: true
    //                 },
    //                 last_name:{
    //                     required: true,
    //                 },
    //                 user_birth:{
    //                     required: true,
    //                 },

    //                 restaurant_email: {
    //                     required: true,
    //                     email: true,
    //                 },

    //                 restaurant_phone: {
    //                     required: true,
    //                     numericCharactersOnly: true
    //                 },

    //             },
    //             messages: {
    //                 first_name: {
    //                     required: "Please enter first name",
    //                     alphaCharactersOnly: "Please enter only alphabetical characters"
    //                 },
    //                 last_name:{
    //                     required: "Please enter last name",
    //                 },
    //                 user_birth:{
    //                     required: "Please enter date of birth",
    //                 },

    //                 restaurant_email: {
    //                     required: "Enter email address",
    //                     email: "Please enter a valid email address"
    //                 },

    //                 restaurant_phone: {
    //                     required: "Enter Phone Number",
    //                     numericCharactersOnly: "Please enter only numeric characters"
    //                 },

    //             },
    //             errorClass: 'error-message',
    //             submitHandler: function(form) {
    //                 let base_url = url_path;
    //                 var formData = new FormData(form);
    //                 // console.log(formData);
    //                 $('#restaturant_btn').text('Please wait...');
    //                 $('#restaturant_btn').attr('disabled', true);

    //                 $.ajaxSetup({
    //                     headers: {
    //                         'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    //                     }
    //                 });
    //                 $.ajax({
    //                     url: base_url + '/update_restaurant',
    //                     type: 'POST',
    //                     data: formData,
    //                     processData: false,
    //                     contentType: false,
    //                     success: function(result) {
    //                         if (result.status_code == 200) {
    //                             toastr.success('Restaurant Updated Sucessfully');
    //                             setTimeout(function() {
    //                                 window.location.href = base_url + "/restaurant_users";
    //                             }, 2000);
    //                         } else {
    //                             toastr.error('Something Went Wrong');
    //                             setTimeout(function() {
    //                                 window.location.href = base_url + "/restaurant_users";
    //                             }, 2000);
    //                         }
    //                         $('#restaturant_btn').attr('disabled', false);
    //                         $('#restaturant_btn').text('Submit');
    //                     },
    //                     error: function() {
    //                         toastr.error('Something Went Wrong');
    //                         $('#restaturant_btn').attr('disabled', false);
    //                         $('#restaturant_btn').text('Submit');
    //                     }
    //                 });
    //             }
    //         });
    //     })


