<?php $__env->startSection('page-title', __('Bonus Setup')); ?>

<?php $__env->startSection('action-button'); ?>
    <a href="#" data-url="<?php echo e(route('bonus-setups.create')); ?>" data-size="lg" data-ajax-popup="true"
        data-title="<?php echo e(__('Create Bonus Plan')); ?>" class="btn btn-sm btn-primary">
        <i class="ti ti-plus"></i> <?php echo e(__('Add Bonus Plan')); ?>

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

<?php $__env->startSection('content'); ?>
    <div class="row">
        <div class="col-12">
            <?php echo $__env->make('layouts.hrm_setup', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
        </div>

        <div class="col-md-12">
            <div class="card">
                <div class="card-body table-border-style">
                    <div class="table-responsive">
                        <table class="table datatable">
                            <thead>
                                <tr>
                                    <th><?php echo e(__('Name')); ?></th>
                                    <th><?php echo e(__('Bonus Type')); ?></th>
                                    <th><?php echo e(__('Calculation Type')); ?></th>
                                    <th><?php echo e(__('Flat Amount')); ?></th>
                                    <th><?php echo e(__('Target %')); ?></th>
                                    <th><?php echo e(__('Max %')); ?></th>
                                    <th><?php echo e(__('Formula')); ?></th>
                                    <th><?php echo e(__('Notes')); ?></th>
                                    <th><?php echo e(__('Effective Period')); ?></th>
                                    <th><?php echo e(__('Status')); ?></th>
                                    <th class="text-end"><?php echo e(__('Actions')); ?></th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $__empty_1 = true; $__currentLoopData = $bonusSetups; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $setup): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                    <tr>
                                        <td><?php echo e($setup->name); ?></td>
                                        <td><?php echo e(ucfirst(str_replace('_', ' ', $setup->bonus_type))); ?></td>
                                        <td><?php echo e(ucfirst($setup->calculation_type)); ?></td>
                                        <td>
                                            <?php if($setup->calculation_type === 'flat'): ?>
                                                <?php echo e(number_format($setup->flat_amount ?? 0, 2)); ?>

                                            <?php else: ?>
                                                -
                                            <?php endif; ?>
                                        </td>
                                        <td>
                                            <?php if($setup->calculation_type === 'percentage'): ?>
                                                <?php echo e($setup->target_percent ?? '-'); ?>%
                                            <?php else: ?>
                                                -
                                            <?php endif; ?>
                                        </td>
                                        <td>
                                            <?php if($setup->calculation_type === 'percentage'): ?>
                                                <?php echo e($setup->max_percent ?? '-'); ?>%
                                            <?php else: ?>
                                                -
                                            <?php endif; ?>
                                        </td>
                                        <td>
                                            <?php if($setup->calculation_type === 'formula'): ?>
                                                <?php echo e($setup->formula ?? '-'); ?>

                                            <?php else: ?>
                                                -
                                            <?php endif; ?>
                                        </td>
                                        <td><?php echo e($setup->notes ?? '-'); ?></td>
                                        <td>
                                            <?php echo e($setup->effective_start ? $setup->effective_start->format('Y-m-d') : '-'); ?>

                                            -
                                            <?php echo e($setup->effective_end ? $setup->effective_end->format('Y-m-d') : '-'); ?>

                                        </td>
                                        <td>
                                            <?php if($setup->active): ?>
                                                <span class="badge bg-success"><?php echo e(__('Active')); ?></span>
                                            <?php else: ?>
                                                <span class="badge bg-danger"><?php echo e(__('Inactive')); ?></span>
                                            <?php endif; ?>
                                        </td>
                                        <td class="text-end">
                                            <div class="action-btn bg-warning ms-2">
                                                <a href="#" data-url="<?php echo e(route('bonus-setups.edit', $setup->id)); ?>"
                                                    data-size="lg" data-ajax-popup="true"
                                                    data-title="<?php echo e(__('Edit Bonus Plan')); ?>"
                                                    class="mx-3 btn btn-sm align-items-center">
                                                    <i class="ti ti-pencil text-white"></i>
                                                </a>
                                            </div>
                                            <div class="action-btn bg-danger ms-2">
                                                <?php echo Form::open(['method' => 'DELETE', 'route' => ['bonus-setups.destroy', $setup->id], 'id' => 'delete-form-' . $setup->id]); ?>

                                                <a href="#" class="mx-3 btn btn-sm align-items-center bs-pass-para"
                                                    data-confirm="<?php echo e(__('Are You Sure?')); ?>"
                                                    data-confirm-yes="document.getElementById('delete-form-<?php echo e($setup->id); ?>').submit();">
                                                    <i class="ti ti-trash text-white"></i>
                                                </a>
                                                <?php echo Form::close(); ?>

                                            </div>
                                        </td>
                                    </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                    <tr>
                                        <td colspan="11" class="text-center"><?php echo e(__('No bonus plans found')); ?></td>
                                    </tr>
                                <?php endif; ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
    <script>
        document.addEventListener('DOMContentLoaded', () => {
            function initBonusFormFields(formContainer = document) {
                const calculationSelect = formContainer.querySelector('#calculation_type');
                if (!calculationSelect) return;

                const formulaSection = formContainer.querySelector('.formula-section');
                const flatSection = formContainer.querySelector('.flat-section');
                const percentSection = formContainer.querySelector('.percent-section');

                const toggleFields = () => {
                    const type = calculationSelect.value;
                    formulaSection?.classList.toggle('d-none', type !== 'formula');
                    flatSection?.classList.toggle('d-none', type !== 'flat');
                    percentSection?.classList.toggle('d-none', type !== 'percentage');
                };

                calculationSelect.removeEventListener('change', toggleFields);
                calculationSelect.addEventListener('change', toggleFields);
                toggleFields();
            }

            document.querySelectorAll('form').forEach(form => initBonusFormFields(form));

            document.addEventListener('shown.bs.modal', event => {
                initBonusFormFields(event.target);
            });
        });
    </script>
<?php $__env->stopPush(); ?>
<?php echo $__env->make('layouts.admin', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /var/www/payraty/hris/resources/views/bonus_setups/index.blade.php ENDPATH**/ ?>