<?php include __DIR__ . '/../../layouts/header.php'; ?>
<?php include __DIR__ . '/../../layouts/sidebar.php'; ?>

<div class="d-flex justify-content-between align-items-center mb-4">
    <h2 class="mb-0"><?= __('contracts') ?></h2>
</div>

<div class="table-container">
    <div class="table-responsive">
        <table class="table align-middle">
            <thead>
                <tr>
                    <th><?= __('id') ?></th>
                    <th><?= __('customer') ?></th>
                    <th><?= __('vendor') ?></th>
                    <th><?= __('date') ?></th>
                    <th><?= __('total_amount') ?></th>
                    <th><?= __('status') ?></th>
                    <th class="text-end"><?= __('actions') ?></th>
                </tr>
            </thead>
            <tbody>
                <?php if (empty($contracts)): ?>
                    <tr>
                        <td colspan="7" class="text-center py-5 text-muted"><?= __('no_data_found') ?></td>
                    </tr>
                <?php else: ?>
                    <?php foreach ($contracts as $contract): ?>
                        <tr>
                            <td class="text-secondary fw-semibold">#<?= htmlspecialchars($contract['id']) ?></td>
                            <td>
                                <span class="fw-bold text-dark"><i class="fas fa-user-circle text-secondary" style="<?= isRTL() ? 'margin-left: 4px;' : 'margin-right: 4px;' ?>"></i> <?= htmlspecialchars($contract['customer_name']) ?></span>
                            </td>
                            <td>
                                <span class="badge badge-secondary fw-normal">
                                    <i class="fas fa-building" style="<?= isRTL() ? 'margin-left: 4px;' : 'margin-right: 4px;' ?>"></i> <?= htmlspecialchars($contract['vendor_name']) ?>
                                </span>
                            </td>
                            <td><?= htmlspecialchars($contract['start_date']) ?></td>
                            <td><span class="fw-bold text-dark"><?= htmlspecialchars($contract['total_amount']) ?></span> <span class="text-secondary" style="font-size: 12px;"><?= htmlspecialchars($contract['currency']) ?></span></td>
                            <td>
                                <?php if ($contract['status'] === 'active' || $contract['status'] === 'approved'): ?>
                                    <span class="badge badge-success"><?= __('active') ?></span>
                                <?php elseif ($contract['status'] === 'cancelled' || $contract['status'] === 'rejected'): ?>
                                    <span class="badge badge-danger"><?= __('rejected') ?></span>
                                <?php else: ?>
                                    <span class="badge badge-warning"><?= htmlspecialchars(ucfirst($contract['status'])) ?></span>
                                <?php endif; ?>
                            </td>
                            <td class="text-end">
                                <button class="btn btn-light btn-sm text-primary me-2"><i class="fas fa-eye"></i></button>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                <?php endif; ?>
            </tbody>
        </table>
    </div>

    <?php if ($totalPages > 1): ?>
    <div class="d-flex justify-content-end mt-4">
        <ul class="pagination mb-0 gap-2">
            <li class="page-item <?= $page <= 1 ? 'disabled' : '' ?>">
                <a class="page-link rounded-circle border-0 text-secondary bg-light" href="?page=contracts&p=<?= $page - 1 ?>" style="width:40px; height:40px; display:flex; align-items:center; justify-content:center;"><i class="fas <?= isRTL() ? 'fa-chevron-right' : 'fa-chevron-left' ?>"></i></a>
            </li>
            <?php for ($i = 1; $i <= $totalPages; $i++): ?>
                <li class="page-item <?= $i == $page ? 'active' : '' ?>">
                    <a class="page-link rounded-circle border-0 <?= $i == $page ? 'bg-primary text-white' : 'text-secondary bg-light' ?>" href="?page=contracts&p=<?= $i ?>" style="width:40px; height:40px; display:flex; align-items:center; justify-content:center;"><?= $i ?></a>
                </li>
            <?php endfor; ?>
            <li class="page-item <?= $page >= $totalPages ? 'disabled' : '' ?>">
                <a class="page-link rounded-circle border-0 text-secondary bg-light" href="?page=contracts&p=<?= $page + 1 ?>" style="width:40px; height:40px; display:flex; align-items:center; justify-content:center;"><i class="fas <?= isRTL() ? 'fa-chevron-left' : 'fa-chevron-right' ?>"></i></a>
            </li>
        </ul>
    </div>
    <?php endif; ?>
</div>

<?php include __DIR__ . '/../../layouts/footer.php'; ?>
