<?php
echo message_box('success');
echo message_box('error');
$created = can_action('126', 'created');
$edited = can_action('126', 'edited');
$deleted = can_action('126', 'deleted');
$edit_id = $this->uri->segment(5);
$action_url = base_url() . 'admin/settings/contract_type/update_contract_type';
$submit_label = lang('add');
$contract_name = '';
$contract_desc = '';
if (!empty($edit_id) && !empty($contract_type_info)) {
    $action_url = base_url() . 'admin/settings/contract_type/update_contract_type/' . $contract_type_info->contract_type_id;
    $submit_label = lang('update');
    $contract_name = $contract_type_info->contract_type;
    $contract_desc = $contract_type_info->description;
}
?>

<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('contract_type', lang('contract_type'), $contract_name, 'text', true); ?>
                                <?= form_editor('description', lang('description'), $contract_desc, false); ?>
                                <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/contract_type/') ?>" 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
                        if (!empty($all_contract_type)) {
                            foreach ($all_contract_type as $contract_type) {
                                ?>
                                <div id="contract_type_<?= $contract_type->contract_type_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"><?= $contract_type->contract_type ?></h4>
                                            <p class="text-xs text-muted-foreground"><?= $contract_type->description ?></p>
                                        </div>
                                        <div class="flex items-center gap-2">
                                            <?php if (!empty($edited)) { ?>
                                                <?= btn_edit('admin/settings/contract_type/edit_contract_type/' . $contract_type->contract_type_id) ?>
                                            <?php } ?>
                                            <?php if (!empty($deleted)) { ?>
                                                <?= btn_delete('admin/settings/delete_contract_type/' . $contract_type->contract_type_id) ?>
                                            <?php } ?>
                                        </div>
                                    </div>
                                </div>
                            <?php }
                        }
                        ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
