<?php $__env->startSection('title', 'Station : Add'); ?>
<?php $__env->startSection('content'); ?>
    <div class="middle-part-wrap location-list-page-wrap list_view">
        <div class="leadership-list-wrap location-list-wrap">
            <div class="leadership-top-header">
                <h3>Stations Requests</h3>
                <a href="javascript::void()" class="backBtn common-btn deletemultiplerequests">Delete Multiple Requests</a>
            </div>
            <div class="leadership-list-data scroll">
                <ul class="listRecordsUl">
                    <div class="card">
                        <div class="card-body">
                            <div id="errormsg" class="text-center animated fadeIn" style="display: none; color:red">
                                <strong class="errormsg">Please select atlease one request</strong>
                            </div>
                            <div id="successMsg" class="text-center animated fadeIn" style="display: none; color:green">
                                <strong class="successMsg"></strong>
                            </div>
                            <table id="list" class="table table-striped table-bordered viewdatatable dt-responsive nowrap" style="width:100%">
                                <thead>
                                    <tr>
                                        <th class="text-center">
                                            <span class="deletespanclass"> 
                                                Delete Request<input type="checkbox" name="select" id="select_all" style="zoom:1.7">
                                            </span>
                                        </th>
                                        <th>Name</th>
                                        <th>Address</th>
                                        <th>Latitude</th>
                                        <th>Longitude</th>
                                        <th>Company</th>
                                        <th>Action</th>
                                    </tr>
                                </thead>
                            </table>
                        </div>
                    </div>
                </ul>
            </div>
        </div>
    </div>
    <div class="middle-part-wrap location-list-page-wrap details_view" style="display:none">
        <div class="leadership-list-wrap location-list-wrap">
            <div class="leadership-top-header">
                <h3>Stations Details</h3>
                <a href="javascript::void()" class="backBtn common-btn">Back</a>
            </div>
            <div class="leadership-list-data scroll">
                <ul class="listRecordsUl">
                    <div class="card">
                        <div class="card-body">
                            <div class="container">
                                <form class="needs-validation" id="stationForm" novalidate>
                                    <?php echo csrf_field(); ?>
                                    <input type="hidden" name="station_id" value="">
                                    <input type="hidden" name="request_id" value="">
                                    <div class="row">
                                        <div class="col-md-12 order-md-1">
                                            <div class="row">
                                                <div class="col-md-6 mb-3">
                                                    <label for="name">Name</label>
                                                    <input type="text" class="form-control" id="name" name="name" placeholder="" value="" required>
                                                </div>
                                                <div class="col-md-6 mb-3">
                                                    <label for="company">Company</label>
                                                    <input type="text" class="form-control" id="company" name="company" placeholder="" value="" required>
                                                </div>
                                            </div>
                                            <div class="row">
                                                <div class="col-md-6 mb-3">
                                                    <label for="latitude">Latitude</label>
                                                    <input type="text" class="form-control" id="latitude" name="latitude" placeholder="" value="" required>
                                                </div>
                                                <div class="col-md-6 mb-3">
                                                    <label for="longitude">Longitude</label>
                                                    <input type="text" class="form-control" id="longitude" name="longitude" placeholder="" value="" required>
                                                </div>
                                            </div>
                                            <div class="mb-3">
                                                <label for="address">Adresse</label>
                                                <textarea type="text" class="form-control" id="address" name="address" placeholder=""></textarea>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="d-flex align-items-center mb-3 gap-4">
                                            <label for="dognapent" class="mr-2">Døgnåpent</label>
                                            <div class="dognapent-switch">
                                                <input type="checkbox" id="toggle" class="toggleCheckbox" name="dognapent" />
                                                <label for="toggle" class='toggleContainer'>
                                                    <div>Yes</div>
                                                    <div>No</div>
                                                </label>
                                            </div>
                                        </div>
                                        <div class="col-md-6 order-md-2 mb-4">
                                            <div class="week-day">
                                                <ul class="list-group mb-3">
                                                    
                                                    <li class="list-group-item d-flex align-items-center gap-4 lh-condensed">
                                                        <div class="week-day-name">
                                                            <h6 class="my-0">Mandag</h6>
                                                        </div>
                                                        <div class="start-day-time">
                                                            <input type="text" name="startMonday" class="form-control timepicker" id="start-monday" placeholder="Start Time">
                                                        </div>
                                                        <div class="start-day-time">
                                                            <input type="text" name="endMonday" class="form-control timepicker" id="end-monday" placeholder="End Time">
                                                        </div>
                                                        <label class="hour_text_lable">24 Hours</label>
                                                    </li>
                                                    <li class="list-group-item d-flex align-items-center gap-4 lh-condensed">
                                                        <div class="week-day-name">
                                                            <h6 class="my-0">Tirsdag</h6>
                                                        </div>
                                                        <div class="start-day-time">
                                                            <input type="text" name="startTuesday" class="form-control timepicker" id="start-tuesday" placeholder="Start Time">
                                                        </div>
                                                        <div class="start-day-time">
                                                            <input type="text" name="endTuesday" class="form-control timepicker" id="end-tuesday" placeholder="End Time">
                                                        </div>
                                                        <label class="hour_text_lable">24 Hours</label>
                                                    </li>
                                                    <li class="list-group-item d-flex align-items-center gap-4 lh-condensed">
                                                        <div class="week-day-name">
                                                            <h6 class="my-0">Onsdag</h6>
                                                        </div>
                                                        <div class="start-day-time">
                                                            <input type="text" name="startWednesday" class="form-control timepicker" id="start-wednesday" placeholder="Start Time">
                                                        </div>
                                                        <div class="start-day-time">
                                                            <input type="text" name="endWednesday" class="form-control timepicker" id="end-wednesday" placeholder="End Time">
                                                        </div>
                                                        <label class="hour_text_lable">24 Hours</label>
                                                    </li>
                                                    <li class="list-group-item d-flex align-items-center gap-4 lh-condensed">
                                                        <div class="week-day-name">
                                                            <h6 class="my-0">Torsdag</h6>
                                                        </div>
                                                        <div class="start-day-time">
                                                            <input type="text" name="startThursday" class="form-control timepicker" id="start-thursday" placeholder="Start Time">
                                                        </div>
                                                        <div class="start-day-time">
                                                            <input type="text" name="endThursday" class="form-control timepicker" id="end-thursday" placeholder="End Time">
                                                        </div>
                                                        <label class="hour_text_lable">24 Hours</label>
                                                    </li>
                                                    <li class="list-group-item d-flex align-items-center gap-4 lh-condensed">
                                                        <div class="week-day-name">
                                                            <h6 class="my-0">Fredag</h6>
                                                        </div>
                                                        <div class="start-day-time">
                                                            <input type="text" name="startFriday" class="form-control timepicker" id="start-friday" placeholder="Start Time">
                                                        </div>
                                                        <div class="start-day-time">
                                                            <input type="text" name="endFriday" class="form-control timepicker" id="end-friday" placeholder="End Time">
                                                        </div>
                                                        <label class="hour_text_lable">24 Hours</label>
                                                    </li>
                                                    <li class="list-group-item d-flex align-items-center gap-4 lh-condensed">
                                                        <div class="week-day-name">
                                                            <h6 class="my-0">Lørdag</h6>
                                                        </div>
                                                        <div class="start-day-time">
                                                            <input type="text" name="startSaturday" class="form-control timepicker" id="start-saturday" placeholder="Start Time">
                                                        </div>
                                                        <div class="start-day-time">
                                                            <input type="text" name="endSaturday" class="form-control timepicker" id="end-saturday" placeholder="End Time">
                                                        </div>
                                                        <label class="hour_text_lable">24 Hours</label>
                                                    </li>
                                                    <li class="list-group-item d-flex align-items-center gap-4 lh-condensed">
                                                        <div class="week-day-name">
                                                            <h6 class="my-0">Søndag</h6>
                                                        </div>
                                                        <div class="start-day-time">
                                                            <input type="text" name="startSunday" class="form-control timepicker" id="start-sunday" placeholder="Start Time">
                                                        </div>
                                                        <div class="start-day-time">
                                                            <input type="text" name="endSunday" class="form-control timepicker" id="end-sunday" placeholder="End Time">
                                                        </div>
                                                        <label class="hour_text_lable">24 Hours</label>
                                                    </li>
                                                </ul>
                                            </div>
                                        </div>
                                        <div class="col-md-6 order-md-2 mb-4">
                                            <div class="station-services">
                                                <ul class="list-group mb-3">
                                                    <li class="list-group-item lh-condensed">
                                                        <div class="d-flex align-items-center justify-content-between">
                                                            <div class="service-title d-flex align-items-center">
                                                                <div class="service-icon">
                                                                    <img src="<?php echo e(asset('images/InfoToalet.png')); ?>">
                                                                </div>
                                                                <label for="Kundetoaletter" class="mr-2">Kundetoaletter</label>
                                                            </div>
                                                            <input type="checkbox" class="form-check-input" id="Kundetoaletter" name="Kundetoaletter">
                                                        </div>
                                                    </li>
                                                    <li class="list-group-item lh-condensed">
                                                        <div class="d-flex align-items-center justify-content-between">
                                                            <div class="service-title d-flex align-items-center">
                                                                <div class="service-icon">
                                                                    <img src="<?php echo e(asset('images/InfoHandi.png')); ?>">
                                                                </div>
                                                                <label for="Handikaptoalett" class="mr-2">Handikaptoalett</label>
                                                            </div>
                                                            <input type="checkbox" class="form-check-input" id="Handikaptoalett" name="Handikaptoalett">
                                                        </div>
                                                    </li>
                                                    <li class="list-group-item lh-condensed">
                                                        <div class="d-flex align-items-center justify-content-between">
                                                            <div class="service-title d-flex align-items-center">
                                                                <div class="service-icon">
                                                                    <img src="<?php echo e(asset('images/InfoMaskin.png')); ?>">
                                                                </div>
                                                                <label for="Bilvask_Maskin" class="mr-2">Bilvask(Maskin)</label>
                                                            </div>
                                                            <input type="checkbox" class="form-check-input" id="Bilvask_Maskin" name="Bilvask_Maskin">
                                                        </div>
                                                    </li>
                                                    <li class="list-group-item lh-condensed">
                                                        <div class="d-flex align-items-center justify-content-between">
                                                            <div class="service-title d-flex align-items-center">
                                                                <div class="service-icon">
                                                                    <img src="<?php echo e(asset('images/InfoSelvask.png')); ?>">
                                                                </div>
                                                                <label for="Bilvask_Selvvask" class="mr-2">Bilvask(Selvvask)</label>
                                                            </div>
                                                            <input type="checkbox" class="form-check-input" id="Bilvask_Selvvask" name="Bilvask_Selvvask">
                                                        </div>
                                                    </li>
                                                    <li class="list-group-item lh-condensed">
                                                        <div class="d-flex align-items-center justify-content-between">
                                                            <div class="service-title d-flex align-items-center">
                                                                <div class="service-icon">
                                                                    <img src="<?php echo e(asset('images/InfoGass.png')); ?>">
                                                                </div>
                                                                <label for="Gass" class="mr-2">Gass</label>
                                                            </div>
                                                            <input type="checkbox" class="form-check-input" id="Gass" name="Gass">
                                                        </div>
                                                    </li>
                                                    <li class="list-group-item lh-condensed">
                                                        <div class="d-flex align-items-center justify-content-between">
                                                            <div class="service-title d-flex align-items-center">
                                                                <div class="service-icon">
                                                                    <img src="<?php echo e(asset('images/InfoEliectric.png')); ?>">
                                                                </div>
                                                                <label for="Landestasjoner" class="mr-2">Landestasjoner</label>
                                                            </div>
                                                            <input type="checkbox" class="form-check-input" id="Landestasjoner" name="Landestasjoner">
                                                        </div>
                                                    </li>
                                                    <li class="list-group-item lh-condensed">
                                                        <div class="d-flex align-items-center justify-content-between">
                                                            <div class="service-title d-flex align-items-center">
                                                                <div class="service-icon">
                                                                    <img src="<?php echo e(asset('images/InfoTilheng.png')); ?>">
                                                                </div>
                                                                <label for="Tilhengerleie" class="mr-2">Tilhengerleie</label>
                                                            </div>
                                                            <input type="checkbox" class="form-check-input" id="Tilhengerleie">
                                                        </div>
                                                    </li>
                                                </ul>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="service-save-button">
                                        <button class="btn btn-primary btn-lg btn-block common-btn" type="submit">Save</button>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </ul>
            </div>
        </div>
    </div>
    <div class="commanpopup dltuser" style="display: none;">
        <div class="overlaybg"></div>
        <div class="main-box">
            <p class="titlemsg mt-0">Are you sure you want to <br><span class="warning_text">delete this station request?</span></p>
            <button class="rejectbtn yesbtn common-btn" data-id="18">Yes</button>
            <button class="cancelbtn">Cancel</button>
        </div>
    </div>

    <link rel="stylesheet" type="text/css" media="screen" href="<?php echo asset('plugin/datatable/dataTables.bootstrap5.css'); ?>">
    <script type="text/javascript" src="<?php echo asset('plugin/datatable/dataTables.js'); ?>"></script>
    <script type="text/javascript" src="<?php echo asset('plugin/datatable/dataTables.bootstrap5.js'); ?>"></script>
    <!-- Bootstrap Timepicker CSS -->
    <script type="text/javascript" src="<?php echo e(asset('js/jquery.validate.min.js')); ?>"></script>
    <script src="<?php echo asset('js/popper.min.js'); ?>"></script>
    <script src="<?php echo asset('js/dayjs.min.js'); ?>"></script>
    <script src="<?php echo asset('js/customParseFormat.min.js'); ?>"></script>
    <script src="<?php echo asset('js/all.min.js'); ?>"></script>
    <script src="<?php echo asset('js/timepicker-bs4.js'); ?>"></script>
    <script>
    var action = "<?php echo e($action); ?>";
    $(document).ready(function () {
        $(".alert-success, .alert-danger").delay(5000).fadeOut();
        $('.request_menus').removeClass('collapsed');
        $('.request_menus').parent().find('.collapse').addClass('show');
        $(`.${action}Active`).addClass('active');
        fill_datatable();
        $('#stationForm').validate({
                rules: {
                    name: {
                        required: true
                    },
                    company: {
                        required: true
                    },
                    latitude: {
                        required: true
                    },
                    longitude: {
                        required: true
                    },
                    address: {
                        required: true
                    },
                    startSunday: {
                        required: true
                    },
                    endSunday: {
                        required: true
                    },
                    startMonday: {
                        required: true
                    },
                    endMonday: {
                        required: true
                    },
                    startTuesday: {
                        required: true
                    },
                    endTuesday: {
                        required: true
                    },
                    startWednesday: {
                        required: true
                    },
                    endWednesday: {
                        required: true
                    },
                    startThursday: {
                        required: true
                    },
                    endThursday: {
                        required: true
                    },
                    startFriday: {
                        required: true
                    },
                    endFriday: {
                        required: true
                    },
                    startSaturday: {
                        required: true
                    },
                    endSaturday: {
                        required: true
                    }
                },
                messages: {
                    name: {
                        required: "Please enter name"
                    },
                    company: {
                        required: "Please enter company name"
                    },
                    latitude: {
                        required: "Please enter latitude"
                    },
                    longitude: {
                        required: "Please enter longitude"
                    },
                    address: {
                        required: "Please enter address"
                    },
                    startSunday: {
                        required: "Please enter start date"
                    },
                    endSunday: {
                        required: "Please enter end date"
                    },
                    startMonday: {
                        required: "Please enter start date"
                    },
                    endMonday: {
                        required: "Please enter end date"
                    },
                    startTuesday: {
                        required: "Please enter start date"
                    },
                    endTuesday: {
                        required: "Please enter end date"
                    },
                    startWednesday: {
                        required: "Please enter start date"
                    },
                    endWednesday: {
                        required: "Please enter end date"
                    },
                    startThursday: {
                        required: "Please enter start date"
                    },
                    endThursday: {
                        required: "Please enter end date"
                    },
                    startFriday: {
                        required: "Please enter start date"
                    },
                    endFriday: {
                        required: "Please enter end date"
                    },
                    startSaturday: {
                        required: "Please enter start date"
                    },
                    endSaturday: {
                        required: "Please enter end date"
                    }
                    
                },
                submitHandler: function(form) {
                    $('body').prepend('<div class="loader"></div>');
                    saveStation();
                    return false;
                }
            });
    });
    function fill_datatable(){
      var table = $('#list').DataTable({
            scrollX: true,
            lengthMenu: [
                [10, 25, 50],
                [10, 25, 50],
            ],
            "order": [[1, "desc"]],
            "columnDefs": [
                  {
                        "targets": [],
                        "visible": false,
                        "searchable": false
                    },
                {
                    "targets": [],
                    "searchable": false
                }
            ],
            "processing": true,
            "serverSide": true,
            "ajax": {
                "url": "<?php echo e(url('admin/station/addlist')); ?>",
                "dataType": "json",
                "type": "POST",
                "data": {'_token': "<?php echo e(csrf_token()); ?>", 'action':action}
            },
            "columns": [
                {"data": "deleteRequests", "sortable": false, 'className':"text-center"},
                {"data": "name", "sortable": false, "className": "text-center"},
                {"data": "address", "sortable": false, "className": "text-center"},
                {"data": "latitude"},
                {"data": "longitude", "className": "text-center"},
                {"data": "company", "className": "text-center"},
                {"data": "action", "sortable": false, "className": "text-center"},
            ],
      });
    }

    $(document).on('click', '.show-details', function(){
        var details = JSON.parse($(this).attr('data-details'));
        var id = $(this).attr('data-id');
        $('.list_view').hide();
        $('.details_view').show();
        
        if(details.name){
            $("input[name=name]").val(details.name);
        }
        if(details.company){
            $("input[name=company]").val(details.company);
        }
        if(details.address){
            $("textarea[name=address]").val(details.address);
        }
        if(details.latitude){
            $("input[name=latitude]").val(details.latitude);
        }
        if(details.longitude){
            $("input[name=longitude]").val(details.longitude);
        }
        if(details.station_id){
            $("input[name=station_id]").val(details.station_id);
        }
        $("input[name=request_id]").val(details.id);
        
        if(details.info){
            var info = JSON.parse(details.info)
            if(info.Døgnåpent){
                $('.list-group-item .start-day-time').hide();
                $('.list-group-item label.hour_text_lable').show();
                $("input[name=dognapent]").attr("checked", false);
            }else{
                $('.list-group-item label.hour_text_lable').hide();
                $('.list-group-item .start-day-time').show();
                $("input[name=dognapent]").attr("checked", true);
            }
            if(info.Kundetoaletter){
                $("input[name=Kundetoaletter]").attr("checked", true);
            }else{
                $("input[name=Kundetoaletter]").attr("checked", false);
            }
            if(info.Handikaptoalett){
                $("input[name=Handikaptoalett]").attr("checked", true);
            }else{
                $("input[name=Handikaptoalett]").attr("checked", false);
            }
            if(info.Gass){
                $("input[name=Gass]").attr("checked", true);
            }else{
                $("input[name=Gass]").attr("checked", false);
            }
            if(info.Tilhengerleie){
                $("input[name=Tilhengerleie]").attr("checked", true);
            }else{
                $("input[name=Tilhengerleie]").attr("checked", false);
            }
            if (info["Bilvask (maskin)"] === true) {
                $("input[name=Bilvask_Maskin]").attr("checked", true);
            }else{
                $("input[name=Bilvask_Maskin]").attr("checked", false);
            }
            
            if (info["Bilvask (selvvask)"] === true) {
                $("input[name=Bilvask_Selvvask]").attr("checked", true);
            }else{
                $("input[name=Bilvask_Selvvask]").attr("checked", false);
            }
            if (info.Hours) {
                // Loop over each day of the week and set the corresponding start and end times
                for (let day in info.Hours) {
                    if (info.Hours.hasOwnProperty(day)) {
                        let timeRange = info.Hours[day];
                        let times = timeRange.split('-');
                        let startTime = times[0];
                        let endTime = times[1];
                        switch (day) {
                            case "Mandag":
                                $('#start-monday').val(startTime);
                                $('#end-monday').val(endTime);
                                break;
                            case "Tirsdag":
                                $('#start-tuesday').val(startTime);
                                $('#end-tuesday').val(endTime);
                                break;
                            case "Onsdag":
                                $('#start-wednesday').val(startTime);
                                $('#end-wednesday').val(endTime);
                                break;
                            case "Torsdag":
                                $('#start-thursday').val(startTime);
                                $('#end-thursday').val(endTime);
                                break;
                            case "Fredag":
                                $('#start-friday').val(startTime);
                                $('#end-friday').val(endTime);
                                break;
                            case "Lørdag":
                                $('#start-saturday').val(startTime);
                                $('#end-saturday').val(endTime);
                                break;
                            case "Søndag":
                                $('#start-sunday').val(startTime);
                                $('#end-sunday').val(endTime);
                                break;
                            default:
                                break;
                        }
                    }
                }
            }
            
        }
    });
    $(document).ready(function () {
       
        $('.timepicker').each(function () {
            $(this).timepicker({
                format: 'HH:mm'
            });
        });

        // Handle changes in time inputs
        $('.timepicker').on('change', function () {
            const inputValue = this.value.trim();
            const resetBtnId = `${this.id}-reset-btn`;
            const resetBtn = document.getElementById(resetBtnId);

            if (resetBtn) {
                resetBtn.disabled = inputValue.length === 0;
            }

            const [type, day] = this.id.split('-');
            if (type === 'start' || type === 'end') {
                const startInput = document.getElementById(`start-${day}`);
                const endInput = document.getElementById(`end-${day}`);

                if (startInput && endInput) {
                    let startTime = startInput.value.trim();
                    let endTime = endInput.value.trim();

                    // Parse the time inputs to hours and minutes
                    let startTemp = startTime.split(":");
                    let endTemp = endTime.split(":");

                    // Create Date objects to compare times
                    let start = new Date();
                    let end = new Date();

                    // Set the hours and minutes from the parsed time strings
                    start.setHours((parseInt(startTemp[0]) - 1 + 24) % 24);  // Adjust for timezone or other logic
                    start.setMinutes(parseInt(startTemp[1]));

                    end.setHours((parseInt(endTemp[0]) - 1 + 24) % 24);
                    end.setMinutes(parseInt(endTemp[1]));

                    // Check if end time is before or equal to start time
                    if (end < start || end.getTime() === start.getTime()) {
                        endInput.value = '';
                        endInput.setCustomValidity('End time must be after start time.');
                    } else {
                        endInput.setCustomValidity('');
                    }
                }
            }
        });


        // Reset button functionality
        $('.reset-btn').on('click', function () {
            const inputId = this.id.replace('-reset-btn', '');
            const input = document.getElementById(inputId);

            if (input) {
                input.value = '';
                $(input).trigger('input');
                this.disabled = true;
            }
        });

        // Function to update all timepicker options dynamically (if needed in future extensions)
        const updateAllTimePickers = () => {
            const options = {};
            $('.options-control').each(function () {
                const value = this.value.trim();
                if (value) {
                    options[this.id] = value;
                }
            });
            console.log(options);
            $('.timepicker').each(function () {
                $(this).timepicker('option', options);
            });
        };

        // Attach dynamic update logic (if needed for advanced use cases)
        $('.options-control').on('change', updateAllTimePickers);

        // Initial setup for all timepickers
        updateAllTimePickers();
    });
    $(document).on('click', '.backBtn', function(){
        $("#stationForm")[0].reset();
        $('.details_view').hide();
        $('.list_view').show();
    });
    $("input[name='dognapent']").change(function() {
        if ($(this).prop("checked")) {
            $('.list-group-item label.hour_text_lable').hide();
            $('.list-group-item .start-day-time').show();
        } else {
            $('.list-group-item .start-day-time').hide();
            $('.list-group-item label.hour_text_lable').show();
        }
    });
    function saveStation(){
        var data = $('#stationForm').serialize();
        $.ajax({
            url: "<?php echo e(url('admin/station/save')); ?>",
            type: 'POST',
            data: data,
            success: function(response) {
                $('.loader').remove();
                $("button[type=submit]").removeAttr('disabled');
                window.location.href = `<?php echo e(url('admin/station/${action}')); ?>`;
            },
            error: function(error) {
                $("button[type=submit]").removeAttr('disabled');
                $('.errormsg').text('Failed to delete station request. Please try again.');
                $("#errormsg").show().delay(3000).fadeOut();
                $('.loader').remove();
            },
        });
    }
    $(document).on('click', '.cancelbtn', function(){
        $('.commanpopup').hide();
    });
    $(document).on('click', '#select_all', function(event) {
        if(this.checked){
            $('.checkbox').each(function(){
                this.checked = true;
            });
        }else{
             $('.checkbox').each(function(){
                this.checked = false;
            });
        }
    });
    $(document).on('click', '.checkbox', function(event) {
        if($('.checkbox:checked').length == $('.checkbox').length){
            $('#select_all').prop('checked',true);
        }else{
            $('#select_all').prop('checked',false);
        }
    });
    var requestIds=[];
    $(document).on('click', '.deletemultiplerequests', function(event) {
        event.preventDefault();
        var checkedLength = $('.checkbox:checked').length;
        if(checkedLength > 0){
            $("input:checkbox[name=requestId]:checked").each(function(){
                requestIds.push($(this).val());
            });
            $(".rejectbtn").text("Delete");
            $(".titlemsg").html("Are you sure you want to <br> delete this requests ?");
            $(".rejectbtn").attr('data-ids', requestIds);
            $('.rejectbtn').addClass('deleteRequests');
            $('.commanpopup').show();
        }else{
            $("#errormsg").show().delay(3000).fadeOut();
        }
    });
    $(document).on('click', '.deleteRequests', function(event) {
        event.preventDefault();
        var requestIds = $(this).attr('data-ids');
        $('.commanpopup').hide();
        $('body').prepend('<div class="loader"></div>');
        
        $.ajax({
            url: "<?php echo e(url('admin/station/request/delete')); ?>",
            method: "post",
            data: {requestIds,'_token': "<?php echo e(csrf_token()); ?>"},
            success: function (data) {
                $('#select_all').prop('checked',false);
                $('.commanpopup').hide();
                $("#list").DataTable().ajax.reload(null, false )
                $('.successMsg').text(data.message);
                $("#successMsg").show().delay(3000).fadeOut();
                $('.loader').remove();
            },
            error: function (xhr, status, error) {
                $('.errormsg').text('Failed to delete station request. Please try again.');
                $("#errormsg").show().delay(3000).fadeOut();
                $('.loader').remove();
            }
        });
    });
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /Applications/XAMPP/xamppfiles/htdocs/bensin_admin/resources/views/station/add.blade.php ENDPATH**/ ?>