<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>

<div class="rounded-2xl border border-border bg-card shadow-sm dark:border-slate-700 dark:bg-slate-900">
    <div class="flex items-center justify-between border-b border-border px-5 py-4 dark:border-slate-700">
        <h4 class="text-sm font-semibold text-foreground"><i class="mr-2" data-lucide="calendar"></i><?php echo lang('provident_found') . ' ' . $year; ?></h4>
        <div class="hidden-print">
            <?php echo btn_pdf('admin/user/provident_fund_pdf/' . $year . '/' . $profile_info->user_id); ?>
        </div>
    </div>
    <div class="p-5 space-y-4">
        <form data-parsley-validate="" novalidate="" role="form" enctype="multipart/form-data" action="<?php echo base_url(); ?>admin/user/user_details/<?= $profile_info->user_id ?>/provident_found" method="post" class="rounded-xl border border-border bg-muted/30 p-4 dark:border-slate-700 dark:bg-slate-800/60">
			<div class="grid grid-cols-1 gap-2 md:grid-cols-[minmax(0,220px)_auto] md:items-end">
				<?= form_datepicker('year', lang('year'), !empty($year) ? $year : date('Y'), true,   array(
					'id' => 'date',
					'data-type' => 'month',
					'data-format' => 'Y-m',
					'data-auto-close' => 'true',
				)); ?>
				<div class="flex items-end">
					<button type="submit" id="sbtn" class="inline-flex h-9 items-center justify-center gap-2 rounded-lg bg-indigo-600 px-4 text-xs font-semibold text-white shadow-sm transition hover:bg-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-400/40">
						<i data-lucide="arrow-right" class="h-4 w-4"></i>
						<?= lang('go') ?>
					</button>
				</div>
			</div>
		</form>

        <div class="overflow-x-auto rounded-xl border border-border bg-card dark:border-slate-700 dark:bg-slate-900">
            <table class="w-full border-collapse text-sm">
                <thead class="bg-muted/50 text-xs uppercase tracking-[0.14em] text-muted-foreground dark:bg-slate-800/80 dark:text-slate-400">
                    <tr>
                        <th class="border-b border-border px-4 py-3 text-left font-semibold dark:border-slate-700"><?= lang('payment_month') ?></th>
                        <th class="border-b border-border px-4 py-3 text-left font-semibold dark:border-slate-700"><?= lang('payment_date') ?></th>
                        <th class="border-b border-border px-4 py-3 text-left font-semibold dark:border-slate-700"><?= lang('amount') ?></th>
                    </tr>
                </thead>
				<tbody>
					<?php
					$total_amount = 0;
					$curency = $this->db->where('code', config_item('default_currency'))->get('tbl_currencies')->row();
					$has_rows = false;
					?>
					<?php if (!empty($provident_fund_info)) {
						foreach ($provident_fund_info as $key => $v_provident_fund) {
							$month_name = date('F', safe_strtotime($year . '-' . $key));
							if (!empty($v_provident_fund)) {
								foreach ($v_provident_fund as $provident_fund) {
									$has_rows = true; ?>
                                    <tr class="border-t border-border dark:border-slate-700">
                                        <td class="px-4 py-3 text-foreground dark:text-slate-100"><?php echo $month_name ?></td>
                                        <td class="px-4 py-3 text-foreground dark:text-slate-100"><?= display_date($provident_fund->paid_date) ?></td>
                                        <td class="px-4 py-3 font-medium text-foreground dark:text-slate-100"><?php echo display_money($provident_fund->salary_payment_deduction_value, $curency->symbol);
                                            $total_amount += $provident_fund->salary_payment_deduction_value;
                                            ?></td>
                                    </tr>
					<?php
									$key++;
								};
								$total_amount = $total_amount;
							};
						}
					}; ?>
					<?php if (!$has_rows) { ?>
						<tr>
                            <td colspan="3" class="px-4 py-8 text-center text-sm text-muted-foreground dark:text-slate-400"><?= lang('no_data_found') ?></td>
                        </tr>
                    <?php } ?>
                    <tr class="border-t border-border bg-indigo-50 dark:border-slate-700 dark:bg-indigo-950/30">
                        <td colspan="2" class="px-4 py-3 text-right font-semibold text-indigo-950 dark:text-indigo-200">
                            <?= lang('total') . ' ' . lang('provident_fund') ?> :
                        </td>
                        <td class="px-4 py-3 font-semibold text-indigo-950 dark:text-indigo-200"><?php echo display_money($total_amount, $curency->symbol); ?></td>
                    </tr>

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