<div class="modal-header flex items-center justify-between border-b border-border px-4 py-3 pt-0">
    <h4 class="text-sm font-semibold text-foreground"><?= lang('advance_salary_details') ?></h4>
</div>
<div class="modal-body p-4">
    <?php
    $curency = $this->db->where('code', config_item('default_currency'))->get('tbl_currencies')->row();
    ?>
    <div class="grid grid-cols-1 md:grid-cols-2 gap-4 text-sm">
        <div>
            <p class="text-xs font-semibold uppercase tracking-wide text-muted-foreground"><?= lang('name') ?></p>
            <p class="mt-1 font-medium text-foreground"><?php echo $advance_salary_info->fullname ?></p>
        </div>
        <div>
            <p class="text-xs font-semibold uppercase tracking-wide text-muted-foreground"><?= lang('advance_amount') ?></p>
            <p class="mt-1 font-medium text-foreground"><?php echo display_money($advance_salary_info->advance_amount, $curency->symbol) ?></p>
        </div>
        <div>
            <p class="text-xs font-semibold uppercase tracking-wide text-muted-foreground"><?= lang('deduct_month') ?></p>
            <p class="mt-1 font-medium text-foreground"><?php echo date('Y M', safe_strtotime($advance_salary_info->deduct_month)); ?></p>
        </div>
        <div>
            <p class="text-xs font-semibold uppercase tracking-wide text-muted-foreground"><?= lang('apply_on') ?></p>
            <p class="mt-1 font-medium text-foreground"><?= display_date($advance_salary_info->request_date) ?></p>
        </div>
        <?php if (!empty($advance_salary_info->approve_by) || $advance_salary_info->approve_by != 0) { ?>
            <div>
                <p class="text-xs font-semibold uppercase tracking-wide text-muted-foreground"><?= lang('action_by') ?></p>
                <p class="mt-1 font-medium text-foreground"><?= $this->db->where('user_id', $advance_salary_info->approve_by)->get('tbl_account_details')->row()->fullname ?></p>
            </div>
        <?php } ?>
        <div>
            <p class="text-xs font-semibold uppercase tracking-wide text-muted-foreground"><?= lang('current_status') ?></p>
            <p class="mt-1">
                <?php
                if ($advance_salary_info->status == '0') {
                    echo '<span class="inline-flex items-center rounded-full bg-amber-50 px-2 py-1 text-xs font-semibold text-amber-600">' . lang('pending') . '</span>';
                } elseif ($advance_salary_info->status == '1') {
                    echo '<span class="inline-flex items-center rounded-full bg-emerald-50 px-2 py-1 text-xs font-semibold text-emerald-600">' . lang('accepted') . '</span>';
                } elseif ($advance_salary_info->status == '2') {
                    echo '<span class="inline-flex items-center rounded-full bg-red-50 px-2 py-1 text-xs font-semibold text-red-600">' . lang('rejected') . '</span>';
                } else {
                    echo '<span class="inline-flex items-center rounded-full bg-sky-50 px-2 py-1 text-xs font-semibold text-sky-600">' . lang('paid') . '</span>';
                }
                ?>
            </p>
        </div>
    </div>

    <div class="mt-4">
        <p class="text-xs font-semibold uppercase tracking-wide text-muted-foreground"><?= lang('reason') ?></p>
        <div class="mt-2 rounded-lg border border-border bg-muted/40 p-3 text-sm text-foreground"><?= nl2br($advance_salary_info->reason) ?></div>
    </div>
    <?php if (!empty($advance_salary_info->comments)) { ?>
        <div class="mt-4">
            <p class="text-xs font-semibold uppercase tracking-wide text-muted-foreground"><?= lang('comments') ?></p>
            <div class="mt-2 rounded-lg border border-border bg-muted/40 p-3 text-sm text-foreground"><?= nl2br($advance_salary_info->comments) ?></div>
        </div>
    <?php } ?>

    <?php if ($advance_salary_info->status == '0' || $advance_salary_info->status == '2') { ?>
        <?php $status_click = "event.preventDefault();var link=this;fetch(link.href,{headers:{'X-Requested-With':'XMLHttpRequest'}}).then(function(){var closeBtn=document.querySelector('#tw-modal-overlay [data-modal-close]');if(closeBtn){closeBtn.click();}else if(window.jQuery){jQuery('#myModal').modal('hide');}setTimeout(function(){window.location.reload();},250);}).catch(function(){window.location.href=link.href;});return false;"; ?>
        <div class="mt-4">
            <p class="text-xs font-semibold uppercase tracking-wide text-muted-foreground"><?= lang('change') . ' ' . lang('status') ?></p>
            <div class="mt-2 flex flex-wrap gap-2">
                <?php if ($advance_salary_info->status == '0') { ?>
                    <a href="<?= base_url() ?>admin/payroll/set_salary_status/1/<?= $advance_salary_info->advance_salary_id; ?>" class="inline-flex items-center gap-2 rounded-lg border border-emerald-200 bg-emerald-50 px-3 py-2 text-xs font-semibold text-emerald-600 hover:bg-emerald-100" data-toggle="tooltip" title="<?= lang('approved_alert') ?>" onclick="<?= $status_click ?>">
                        <i data-lucide="thumbs-up" class="h-4 w-4"></i> <?= lang('approved') ?>
                    </a>
                    <a href="<?= base_url() ?>admin/payroll/set_salary_status/2/<?= $advance_salary_info->advance_salary_id; ?>" class="inline-flex items-center gap-2 rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-xs font-semibold text-red-600 hover:bg-red-100" onclick="<?= $status_click ?>">
                        <i data-lucide="x" class="h-4 w-4"></i> <?= lang('reject') ?>
                    </a>
                    <a href="<?= base_url() ?>admin/payroll/set_salary_status/3/<?= $advance_salary_info->advance_salary_id; ?>" class="inline-flex items-center gap-2 rounded-lg border border-sky-200 bg-sky-50 px-3 py-2 text-xs font-semibold text-sky-600 hover:bg-sky-100" data-toggle="tooltip" title="<?= lang('paid_alert') ?>" onclick="<?= $status_click ?>">
                        <i data-lucide="check" class="h-4 w-4"></i> <?= lang('paid') ?>
                    </a>
                <?php } elseif ($advance_salary_info->status == '2') { ?>
                    <a href="<?= base_url() ?>admin/payroll/set_salary_status/1/<?= $advance_salary_info->advance_salary_id; ?>" class="inline-flex items-center gap-2 rounded-lg border border-emerald-200 bg-emerald-50 px-3 py-2 text-xs font-semibold text-emerald-600 hover:bg-emerald-100" data-toggle="tooltip" title="<?= lang('approved_alert') ?>" onclick="<?= $status_click ?>">
                        <i data-lucide="thumbs-up" class="h-4 w-4"></i> <?= lang('approved') ?>
                    </a>
                    <a href="<?= base_url() ?>admin/payroll/set_salary_status/0/<?= $advance_salary_info->advance_salary_id; ?>" class="inline-flex items-center gap-2 rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs font-semibold text-amber-600 hover:bg-amber-100" onclick="<?= $status_click ?>">
                        <i data-lucide="rotate-ccw" class="h-4 w-4"></i> <?= lang('pending') ?>
                    </a>
                    <a href="<?= base_url() ?>admin/payroll/set_salary_status/3/<?= $advance_salary_info->advance_salary_id; ?>" class="inline-flex items-center gap-2 rounded-lg border border-sky-200 bg-sky-50 px-3 py-2 text-xs font-semibold text-sky-600 hover:bg-sky-100" data-toggle="tooltip" title="<?= lang('paid_alert') ?>" onclick="<?= $status_click ?>">
                        <i data-lucide="check" class="h-4 w-4"></i> <?= lang('paid') ?>
                    </a>
                <?php } ?>
            </div>
        </div>
    <?php } ?>
</div>
<div class="modal-footer flex items-center justify-end border-t border-border px-4 py-3">
    <button type="button" class="inline-flex items-center gap-2 rounded-lg border border-border bg-card px-3 py-2 text-xs font-semibold text-foreground hover:bg-muted" data-dismiss="modal">
        <i data-lucide="x" class="h-4 w-4"></i>
        <?= lang('close') ?>
    </button>
</div>
