<?= message_box('success'); ?>
<?= message_box('error'); ?>
<?php
$created = can_action('122', 'created');
$edited = can_action('122', 'edited');
$deleted = can_action('122', 'deleted');
$edit_id = $this->uri->segment(5);
$action_url = base_url() . 'admin/settings/leave_category/update_leave_category';
$submit_label = lang('add');
$leave_name = '';
$leave_quota = '';
if (!empty($edit_id) && !empty($leave_category_info)) {
    $action_url = base_url() . 'admin/settings/leave_category/update_leave_category/' . $leave_category_info->leave_category_id;
    $submit_label = lang('update');
    $leave_name = $leave_category_info->leave_category;
    $leave_quota = $leave_category_info->leave_quota;
}
?>

<div class="space-y-6">
    <div class="rounded-2xl border border-border bg-card shadow-sm">
        <div class="p-6">
            <div class="grid grid-cols-1 lg:grid-cols-12 gap-6">
                <?php if (!empty($created) || !empty($edited)) { ?>
                    <div class="lg:col-span-4">
                        <div class="rounded-2xl border border-dashed border-border bg-card p-4 space-y-4">
                            <form method="post" action="<?= $action_url ?>" class="space-y-4">
                                <?= form_input_group('leave_category', lang('leave_category'), $leave_name, 'text', true); ?>
                                <?= form_input_group('leave_quota', lang('leave_quota'), $leave_quota, 'text', true, array('placeholder' => lang('days') . ' / ' . lang('years'))); ?>
                                <div class="flex items-center gap-2">
                                    <button type="submit" class="btn btn-sm btn-primary inline-flex items-center gap-2">
                                        <i data-lucide="check" class="h-4 w-4"></i>
                                        <?= $submit_label ?>
                                    </button>
                                    <?php if (!empty($edit_id)) { ?>
                                        <a href="<?= base_url('admin/settings/leave_category/') ?>" class="btn btn-danger btn-sm"><?= lang('cancel') ?></a>
                                    <?php } ?>
                                </div>
                            </form>
                        </div>
                    </div>
                <?php } ?>

                <div class="lg:col-span-8">
                    <div class="grid grid-cols-1 xl:grid-cols-2 2xl:grid-cols-3 gap-4">
                        <?php
                        $all_leave_category = $this->db->get('tbl_leave_category')->result();
                        if (!empty($all_leave_category)) {
                            foreach ($all_leave_category as $leave_category) {
                                ?>
                                <div id="leave_category_<?= $leave_category->leave_category_id ?>" class="rounded-xl border border-border bg-muted/30 p-4">
                                    <div class="flex items-start justify-between gap-2">
                                        <div>
                                            <h4 class="text-sm font-semibold text-foreground"><?= $leave_category->leave_category ?></h4>
                                            <p class="text-xs text-muted-foreground"><?= lang('quota') ?>: <?= $leave_category->leave_quota ?></p>
                                        </div>
                                        <div class="flex items-center gap-2">
                                            <?php if (!empty($edited)) { ?>
                                                <?= btn_edit('admin/settings/leave_category/edit_leave_category/' . $leave_category->leave_category_id) ?>
                                            <?php } ?>
                                            <?php if (!empty($deleted)) { ?>
                                                <?php echo ajax_anchor(base_url("admin/settings/delete_leave_category/" . $leave_category->leave_category_id), lang('delete'), array("class" => "", "title" => lang('delete'), "data-fade-out-on-success" => "#leave_category_" . $leave_category->leave_category_id)); ?>
                                            <?php } ?>
                                        </div>
                                    </div>
                                </div>
                            <?php }
                        }
                        ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
