<?php $__env->startSection('workspace'); ?>

    <!-- Breadcrumb -->
    <section class="breadcrumb lg:flex items-start">
        <div>
            <h1>Sub-Dealers</h1>
            <ul>
                <li><a href="#no-link">Pages</a></li>
                <li class="divider la la-arrow-right"></li>
                <li><a href="#no-link">Sub-Dealer</a></li>
                <li class="divider la la-arrow-right"></li>
                <li>List</li>
            </ul>
        </div>

        <div class="flex flex-wrap gap-2 items-center ltr:ml-auto rtl:mr-auto mt-5 lg:mt-0">

            <!-- Search -->
            <form class="flex flex-auto">
                <label class="form-control-addon-within rounded-full">
                    <input class="form-control border-none" placeholder="Search">
                    <button
                        class="text-gray-300 dark:text-gray-700 text-xl leading-none la la-search ltr:mr-4 rtl:ml-4"></button>
                </label>
            </form>

            <div class="flex gap-x-2">

                <!-- Sort By -->
                <div class="dropdown">
                    <button class="btn btn_outlined btn_secondary uppercase" data-toggle="dropdown-menu">
                        Sort By
                        <span class="ltr:ml-3 rtl:mr-3 la la-caret-down text-xl leading-none"></span>
                    </button>
                    <div class="dropdown-menu">
                        <a href="#no-link">Ascending</a>
                        <a href="#no-link">Descending</a>
                    </div>
                </div>


                <!-- Add New -->
                <a href="<?php echo e(route('master-dealer.dealers.add-view')); ?>" class="btn btn_primary uppercase">Add New</a>


            </div>
        </div>
    </section>

    <!-- List -->
    <div class="card p-5">
        <div class="overflow-x-auto">
            <table class="table table-auto table_hoverable w-full">
                <thead>
                <tr>
                    <th class="ltr:text-left rtl:text-right uppercase">Company Name</th>
                    <th class="text-center uppercase">Contact Number</th>
                    <th class="text-center uppercase">State</th>
                    <th class="text-center uppercase">License(Activated/Total)</th>
                    <th class="text-center uppercase">Status</th>
                    <th class="uppercase">Action</th>
                </tr>
                </thead>
                <tbody>

                <?php if(count($dealers) == 0): ?>
                    <tr>
                        <td colspan="6" class="text-center">No Sub-Dealer Found</td>
                    </tr>
                <?php else: ?>

                    <?php $__currentLoopData = $dealers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $dealer): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <tr>
                            <td><?php echo e($dealer->company_name); ?></td>
                            
                            <td class="text-center"><?php echo e($dealer->contact_number); ?></td>
                            <td class="text-center"><?php echo e(ucwords($dealer->state)); ?></td>
                            <td class="text-center"><?php echo e($dealer->used_license); ?>/<?php echo e($dealer->total_license); ?></td>
                            <td class="text-center">
                                <div class="badge badge_outlined badge_success uppercase"><?php echo e($dealer->status); ?></div>
                            </td>
                            <td class="ltr:text-right rtl:text-left whitespace-nowrap">
                                <div class="inline-flex ltr:ml-auto rtl:mr-auto">
                                    <button class="btn btn-icon btn_outlined btn_primary" data-toggle="modal"
                                            data-target="#exampleModalCentered" onclick="openModal('<?php echo e($dealer->sub_dealer_id); ?>')"><span
                                            class="la la-file-contract"></span></button>







                                </div>
                            </td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                <?php endif; ?>



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

    <div id="exampleModalCentered" class="modal" data-animations="fadeInDown, fadeOutUp" data-static-backdrop>
        <div class="modal-dialog modal-dialog_centered max-w-2xl">
            <div class="modal-content">
                <div class="modal-header">
                    <h2 class="modal-title">Assign License</h2>
                    <button class="close la la-times" data-dismiss="modal" onclick="closeModal()"></button>
                </div>
                <div class="modal-body">
                    <div class="relative">

                        <label class="label block mb-2" for="license_qty">License Quantity</label>
                        <input id="license_qty" class="form-control" type="number" placeholder="Enter quantity here"
                               min="1">
                        <p class="block mt-2 ">Max License(s) can assign: <?php echo e($maxLicense); ?> </p>

                    </div>
                </div>
                <div class="modal-footer">
                    <div class="flex ltr:ml-auto rtl:mr-auto">
                        <button class="btn btn_secondary uppercase" data-dismiss="modal" onclick="closeModal()">Close
                        </button>
                        <button class="btn btn_primary ltr:ml-2 rtl:mr-2 uppercase" onclick="submitFunction()">Submit
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>







<?php $__env->stopSection(); ?>


<?php $__env->startSection('scripts'); ?>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <script>

        let selectedDealerId = '';

        function closeModal() {
            selectedDealerId = '';
        }

        function openModal(dealerId) {
            selectedDealerId = dealerId;
        }


        function submitFunction() {
            let license_qty = document.getElementById('license_qty').value;
            if (license_qty === '') {
                alert('Please enter license quantity');
                return;
            } else if (license_qty < 1) {
                alert('Please enter valid license quantity');
                return;
            }

            axios.post('<?php echo e(route('master-dealer.dealers.assign-license')); ?>', {
                _token: '<?php echo e(csrf_token()); ?>',
                sub_dealer_id: selectedDealerId,
                license_qty: license_qty
            })
                .then(function (response) {
                    console.log(response);
                    if (response.status === 200) {
                        alert(response.data.message);
                        window.location.reload();
                    } else {
                        alert(response.data.message);
                    }
                })
                .catch(function (error) {
                    console.log(error);
                });
            console.log(license_qty);
        }

    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.master', ['title' => 'List - Dealer - Pages'], \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/ezyorder/public_html/ezypos.ezyorder.com.my/ezypos-backend/resources/views/pages/master-dealer/dealer-list.blade.php ENDPATH**/ ?>