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

<table class="w-full text-sm">
    <thead class="bg-muted/50 text-xs uppercase tracking-[0.14em] text-muted-foreground">
        <tr>
            <th class="px-4 py-3 text-left font-semibold"><?= lang('shift_name') ?></th>
            <th class="px-4 py-3 text-left font-semibold"><?= lang('start_date') ?></th>
            <th class="px-4 py-3 text-left font-semibold"><?= lang('end_date') ?></th>
            <th class="px-4 py-3 text-left font-semibold"><?= lang('signed') ?></th>
        </tr>
    </thead>

    <tbody>
        <?php
        if ($shift) {
            foreach ($shift as $v_shift) {
                $is_signed = property_exists($v_shift, 'signed') && (int) $v_shift->signed === 1;
        ?>
                <tr class="border-t border-border align-top">
                    <td class="px-4 py-3">
                        <div class="font-medium text-foreground"><?= html_escape($v_shift->shift_name) ?></div>
                        <div class="mt-1 text-xs text-muted-foreground"><?= html_escape($v_shift->start_time . ' - ' . $v_shift->end_time) ?></div>
                    </td>
                    <td class="px-4 py-3 text-foreground"><?= display_date($v_shift->start_date) ?></td>
                    <td class="px-4 py-3 text-foreground"><?= display_date($v_shift->end_date) ?></td>

                    <td class="px-4 py-3">
                        <?php
                        if ($is_signed) {
                            echo '<span class="inline-flex items-center rounded-full bg-emerald-100 px-2 py-0.5 text-xs font-semibold text-emerald-700">' . lang('yes') . '</span>';
                        ?>
                            <a href="<?= base_url('admin/shift/view_contract/' . $v_shift->shift_mapping_id) ?>" class="ml-2 inline-flex items-center rounded-md border border-emerald-200 bg-emerald-50 px-2.5 py-1 text-xs font-semibold text-emerald-700 hover:bg-emerald-100"><?= lang('view') ?></a>
                        <?php
                        } else {
                            echo '<span class="inline-flex items-center rounded-full bg-rose-100 px-2 py-0.5 text-xs font-semibold text-rose-700">' . lang('no') . '</span>';
                        ?>
                            <a href="<?= base_url('admin/shift/sign_contract/' . $v_shift->shift_mapping_id) ?>"
                               class="ml-2 inline-flex items-center rounded-md border border-border bg-background px-2.5 py-1 text-xs font-semibold text-foreground hover:bg-muted"><?= lang('sign') ?></a>
                        <?php }
                        ?>
                    </td>
                </tr>
        <?php
            }
        } else {
        ?>
            <tr>
                <td colspan="4" class="px-4 py-8 text-center text-sm text-muted-foreground"><?= lang('no_data_found') ?></td>
            </tr>
        <?php
        }
        ?>
    </tbody>
</table>
