<?php
    $rows = $myPayslipRows ?? collect();
    $years = $myPayslipYears ?? collect();
    $selectedYear = (int) ($myPayslipSelectedYear ?? 0);
    $selected = $myPayslipSelected ?? null;
    $preview = $myPayslipPreview ?? null;
?>

<div class="grid grid-cols-1 gap-4 xl:grid-cols-[300px_minmax(0,1fr)]">
    <div class="overflow-hidden rounded-xl border border-slate-200 bg-white">
        <div class="border-b border-slate-200 px-4 py-3">
            <div class="flex items-center justify-between gap-2">
                <h3 class="text-sm font-semibold text-slate-800">Pay Slips</h3>
                <span class="text-xs text-slate-500"><?php echo e($rows->count()); ?> records</span>
            </div>
            <p class="mt-1 text-xs text-slate-500">Select a month to preview your payslip.</p>
        </div>
        <div class="border-b border-slate-200 p-3">
            <form method="GET" action="<?php echo e(route('payroll.index')); ?>" class="flex items-center gap-2">
                <input type="hidden" name="tab" value="my">
                <input type="hidden" name="my_sub" value="payslips">
                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($selected): ?>
                    <input type="hidden" name="source" value="<?php echo e($selected['source'] ?? ''); ?>">
                    <input type="hidden" name="payslip_id" value="<?php echo e((int) ($selected['id'] ?? 0)); ?>">
                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                <label for="my-payslip-year" class="text-xs font-medium text-slate-600">Year</label>
                <select id="my-payslip-year" name="year" class="h-9 w-full rounded-lg border border-slate-300 px-2 text-sm text-slate-700 js-select2" onchange="this.form.submit()">
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__empty_1 = true; $__currentLoopData = $years; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $year): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <option value="<?php echo e((int) $year); ?>" <?php if((int) $year === $selectedYear): echo 'selected'; endif; ?>><?php echo e((int) $year); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <option value="<?php echo e(date('Y')); ?>"><?php echo e(date('Y')); ?></option>
                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                </select>
            </form>
        </div>
        <div class="max-h-[68vh] overflow-y-auto p-2">
            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__empty_1 = true; $__currentLoopData = $rows; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <?php
                    $isActive = $selected
                        && (int) ($selected['id'] ?? 0) === (int) ($row['id'] ?? 0)
                        && (string) ($selected['source'] ?? '') === (string) ($row['source'] ?? '');
                ?>
                <a
                    href="<?php echo e(route('payroll.index', ['tab' => 'my', 'my_sub' => 'payslips', 'year' => $selectedYear, 'source' => $row['source'] ?? '', 'payslip_id' => (int) ($row['id'] ?? 0)])); ?>"
                    class="mb-2 block rounded-lg border px-3 py-2 transition <?php echo e($isActive ? 'border-primary bg-primary/10' : 'border-slate-200 bg-white hover:bg-slate-50'); ?>"
                >
                    <div class="flex items-center justify-between gap-3">
                        <div>
                            <div class="text-sm font-medium text-slate-800"><?php echo e($row['period'] ?? '—'); ?></div>
                            <div class="text-xs text-slate-500"><?php echo e(strtoupper((string) ($row['source'] ?? ''))); ?></div>
                        </div>
                        <div class="text-right">
                            <div class="text-xs text-slate-500">Net</div>
                            <div class="text-sm font-semibold text-slate-900">₹<?php echo e(number_format((float) ($row['net'] ?? 0), 2)); ?></div>
                        </div>
                    </div>
                </a>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <div class="rounded-lg border border-dashed border-slate-300 px-3 py-8 text-center">
                    <p class="text-sm font-medium text-slate-700">No payslips found</p>
                    <p class="mt-1 text-xs text-slate-500">Payslips for the selected year will appear here.</p>
                </div>
            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
        </div>
    </div>

    <div>
        <?php echo $__env->make('payroll.my.partials.payslip-preview', ['preview' => $preview, 'showActions' => true], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
    </div>
</div>
<?php /**PATH /var/www/html/kiyohr/v2_version/resources/views/payroll/tabs/my/payslips.blade.php ENDPATH**/ ?>