<?php if (isset($component)) { $__componentOriginal91fdd17964e43374ae18c674f95cdaa3 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal91fdd17964e43374ae18c674f95cdaa3 = $attributes; } ?>
<?php $component = App\View\Components\AdminLayout::resolve([] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('admin-layout'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\App\View\Components\AdminLayout::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes([]); ?>
     <?php $__env->slot('header', null, []); ?> 
        <h1 class="text-2xl font-bold">Channel Commission List</h1>
     <?php $__env->endSlot(); ?>

    <?php if (isset($component)) { $__componentOriginal2342e1caa3b5224183b4572420a79d31 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal2342e1caa3b5224183b4572420a79d31 = $attributes; } ?>
<?php $component = App\View\Components\Message::resolve(['type' => 'success','message' => 'success'] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('message'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\App\View\Components\Message::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes([]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal2342e1caa3b5224183b4572420a79d31)): ?>
<?php $attributes = $__attributesOriginal2342e1caa3b5224183b4572420a79d31; ?>
<?php unset($__attributesOriginal2342e1caa3b5224183b4572420a79d31); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal2342e1caa3b5224183b4572420a79d31)): ?>
<?php $component = $__componentOriginal2342e1caa3b5224183b4572420a79d31; ?>
<?php unset($__componentOriginal2342e1caa3b5224183b4572420a79d31); ?>
<?php endif; ?>
    <?php if (isset($component)) { $__componentOriginal2342e1caa3b5224183b4572420a79d31 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal2342e1caa3b5224183b4572420a79d31 = $attributes; } ?>
<?php $component = App\View\Components\Message::resolve(['type' => 'danger','message' => 'error'] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('message'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\App\View\Components\Message::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes([]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal2342e1caa3b5224183b4572420a79d31)): ?>
<?php $attributes = $__attributesOriginal2342e1caa3b5224183b4572420a79d31; ?>
<?php unset($__attributesOriginal2342e1caa3b5224183b4572420a79d31); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal2342e1caa3b5224183b4572420a79d31)): ?>
<?php $component = $__componentOriginal2342e1caa3b5224183b4572420a79d31; ?>
<?php unset($__componentOriginal2342e1caa3b5224183b4572420a79d31); ?>
<?php endif; ?>

    <form id="commissionForm" action="<?php echo e(route('admin.channel_commissions.store')); ?>" method="POST">
        <?php echo csrf_field(); ?>
        <input type="hidden" name="deleted_commissions" id="deleted_commissions">
        <input type="hidden" name="deleted_tour_exceptions" id="deleted_tour_exceptions">
        <div class="p-6">
            <div id="container" class="space-y-4">
                <?php if($channelCommissions->isNotEmpty()): ?>
                    <?php $__currentLoopData = $channelCommissions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $commission): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <div class="bg-gray-200 p-4 rounded-md shadow relative channel-commission" data-index="<?php echo e($index); ?>" data-id="<?php echo e($commission->id ?? ''); ?>">
                            <div class="flex items-center mt-2">
                                <span class="bg-gray-700 text-white px-3 py-2">Default</span>
                                <select name="channels[]" class="channel-select block w-full border border-gray-300 shadow-sm">
                                    <?php $__currentLoopData = $channels; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $channel): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($channel->id); ?>" <?php echo e($commission->channel_id == $channel->id ? 'selected' : ''); ?>>
                                            <?php echo e($channel->name); ?>

                                        </option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                                <input type="number" name="commissions[]" class="ml-4 px-2 py-2 border rounded-md commission-input"
                                    placeholder="Commission" value="<?php echo e($commission->commission); ?>">
                                <button type="button" class="ml-4 bg-red-500 text-white px-3 py-2 rounded-md" onclick="removeCommission(this)">-</button>
                            </div>

                            <div class="mt-3 space-y-2 tour-exceptions">
                                <?php $__currentLoopData = $commission->tourExceptions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tourException): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <div class="bg-gray-300 p-3 rounded-md mt-2 flex items-center gap-x-4 tour-exception" data-id="<?php echo e($tourException->id ?? ''); ?>">
                                    <span class="font-medium whitespace-nowrap">Tour Exception</span>
                                    <select name="tours[<?php echo e($index); ?>][]" class="tour-select ml-4 w-full border border-gray-300 shadow-sm rounded-md px-2 py-1">
                                        <?php $__currentLoopData = $tours; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tour): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <option value="<?php echo e($tour->id); ?>" <?php echo e($tourException->tour_id == $tour->id ? 'selected' : ''); ?>>
                                                <?php echo e($tour->name); ?>

                                            </option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                    <input type="number" name="tour_commissions[<?php echo e($index); ?>][]" class="ml-4 border border-gray-300 shadow-sm rounded-md px-2 py-1 w-32"
                                        placeholder="Commission" value="<?php echo e($tourException->commission); ?>">
                                    <button type="button" class="ml-4 bg-red-500 text-white px-3 py-1 rounded-md" onclick="removeTourException(this)">-</button>
                                </div>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </div>

                            <button type="button" class="bg-green-500 text-white px-3 py-1 mt-2 rounded-md" onclick="addTourException(this)">+ Add Tour Exception</button>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                <?php else: ?>
                    <!-- Default Div Jab Data Na Ho -->
                    <div class="bg-gray-200 p-4 rounded-md shadow relative channel-commission" data-index="0">
                        <div class="flex items-center mt-2">
                            <span class="bg-gray-700 text-white px-3 py-2">Default</span>
                            <select name="channels[]" class="channel-select block w-full border border-gray-300 shadow-sm">
                                <?php $__currentLoopData = $channels; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $channel): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($channel->id); ?>"><?php echo e($channel->name); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                            <input type="number" name="commissions[]" class="ml-4 px-2 py-2 border rounded-md commission-input" placeholder="Commission">
                            <button type="button" class="ml-4 bg-red-500 text-white px-3 py-2 rounded-md" onclick="this.closest('.channel-commission').remove()">-</button>
                        </div>
                        <div class="mt-3 space-y-2 tour-exceptions"></div>
                        <button type="button" class="bg-green-500 text-white px-3 py-1 mt-2 rounded-md" onclick="addTourException(this)">+ Add Tour Exception</button>
                    </div>
                <?php endif; ?>
            </div>


            <div class="mt-4">
                <button type="button" class="bg-gray-700 text-white px-3 py-1 rounded-md" onclick="addDefaultSection()">
                    <span class="text-lg">+</span>
                </button>
            </div>

            <div class="flex items-center justify-end">
                <button type="submit" class="inline-flex items-center px-4 py-2 text-xs font-semibold tracking-widest text-white uppercase bg-indigo-600 border border-transparent rounded-md shadow-sm hover:bg-indigo-700">
                    Save
                </button>
            </div>
        </div>
    </form>

    <script>
        document.addEventListener("DOMContentLoaded", function () {
            function addDefaultSection() {
                const container = document.getElementById('container');
                const totalSections = document.querySelectorAll('.channel-commission').length;

                const defaultSection = document.createElement('div');
                defaultSection.classList.add("bg-gray-200", "p-4", "rounded-md", "shadow", "relative", "channel-commission");
                defaultSection.dataset.index = totalSections;

                defaultSection.innerHTML = `
                    <div class="flex items-center mt-2">
                        <span class="bg-gray-700 text-white px-3 py-2">Default</span>
                        <select name="channels[]" class="channel-select block w-full border border-gray-300 shadow-sm">
                            <?php $__currentLoopData = $channels; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $channel): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($channel->id); ?>"><?php echo e($channel->name); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                        <input type="number" name="commissions[]" class="ml-4 px-2 py-2 border rounded-md commission-input" placeholder="Commission">
                        <button type="button" class="ml-4 bg-red-500 text-white px-3 py-2 rounded-md" onclick="removeCommission(this, '<?php echo e($commission->id ?? ''); ?>">-</button>
                    </div>
                    <div class="mt-3 space-y-2 tour-exceptions"></div>
                    <button type="button" class="bg-green-500 text-white px-3 py-1 mt-2 rounded-md" onclick="addTourException(this)">+ Add Tour Exception</button>
                `;

                container.appendChild(defaultSection);
            }

            function addTourException(button) {
                const tourContainer = button.previousElementSibling;
                const parentSection = button.closest('.channel-commission');

                if (!parentSection.dataset.index) {
                    const allSections = document.querySelectorAll('.channel-commission');
                    parentSection.dataset.index = Array.from(allSections).indexOf(parentSection);
                }

                let parentIndex = parentSection.dataset.index;
                const tourException = document.createElement('div');
                tourException.classList.add("bg-gray-300", "p-3", "rounded-md", "mt-2", "flex", "items-center", "gap-x-4");

                tourException.innerHTML = `
                    <span class="font-medium whitespace-nowrap">Tour Exception</span>
                    <select name="tours[${parentIndex}][]" class="tour-select ml-4 w-full border border-gray-300 shadow-sm rounded-md px-2 py-1">
                        <?php $__currentLoopData = $tours; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tour): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($tour->id); ?>"><?php echo e($tour->name); ?></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                    <input type="number" name="tour_commissions[${parentIndex}][]" class="ml-4 border border-gray-300 shadow-sm rounded-md px-2 py-1 w-32" placeholder="Commission">
                    <button type="button" class="ml-4 bg-red-500 text-white px-3 py-1 rounded-md" onclick="this.parentElement.remove()">-</button>
                `;

                tourContainer.appendChild(tourException);
            }

            function removeCommission(button) {
                const commissionElement = button.closest('.channel-commission');
                const commissionId = commissionElement.dataset.id;
                if (commissionId) {
                    let deletedCommissions = document.getElementById('deleted_commissions').value;
                    deletedCommissions += deletedCommissions ? `,${commissionId}` : commissionId;
                    document.getElementById('deleted_commissions').value = deletedCommissions;
                }
                commissionElement.remove();
            }

            function removeTourException(button) {
                const tourExceptionElement = button.closest('.tour-exception');
                const tourExceptionId = tourExceptionElement.dataset.id;
                if (tourExceptionId) {
                    let deletedTourExceptions = document.getElementById('deleted_tour_exceptions').value;
                    deletedTourExceptions += deletedTourExceptions ? `,${tourExceptionId}` : tourExceptionId;
                    document.getElementById('deleted_tour_exceptions').value = deletedTourExceptions;
                }
                tourExceptionElement.remove();
            }


            window.addDefaultSection = addDefaultSection;
            window.addTourException = addTourException;
            window.removeCommission = removeCommission;
            window.removeTourException = removeTourException;
        });
    </script>

 <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal91fdd17964e43374ae18c674f95cdaa3)): ?>
<?php $attributes = $__attributesOriginal91fdd17964e43374ae18c674f95cdaa3; ?>
<?php unset($__attributesOriginal91fdd17964e43374ae18c674f95cdaa3); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal91fdd17964e43374ae18c674f95cdaa3)): ?>
<?php $component = $__componentOriginal91fdd17964e43374ae18c674f95cdaa3; ?>
<?php unset($__componentOriginal91fdd17964e43374ae18c674f95cdaa3); ?>
<?php endif; ?>
<?php /**PATH C:\xampp8.2\htdocs\Portal\resources\views/admin/channel_commission/index.blade.php ENDPATH**/ ?>