<?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"><?= __('maids') ?></h2>
</div>

<div class="table-container">
    <div class="table-responsive">
        <table class="table align-middle">
            <thead>
                <tr>
                    <th><?= __('id') ?></th>
                    <th><?= __('full_name') ?></th>
                    <th><?= __('vendor') ?></th>
                    <th><?= __('nationality') ?></th>
                    <th><?= __('experience') ?></th>
                    <th>Verification</th>
                    <th><?= __('status') ?></th>
                    <th>Recommended</th>
                    <th>Verified</th>
                    <th class="text-end"><?= __('actions') ?></th>
                </tr>
            </thead>
            <tbody>
                <?php if (empty($maids)): ?>
                    <tr>
                        <td colspan="10" class="text-center py-5 text-muted"><?= __('no_data_found') ?></td>
                    </tr>
                <?php else: ?>
                    <?php foreach ($maids as $maid): ?>
                        <tr>
                            <td class="text-secondary fw-semibold">#<?= htmlspecialchars($maid['id']) ?></td>
                            <td>
                                <div class="d-flex align-items-center gap-3">
                                    <?php if (!empty($maid['profile_image'])): ?>
                                        <img src="<?= htmlspecialchars($maid['profile_image']) ?>" class="rounded-circle shadow-sm" width="40" height="40" style="object-fit: cover;">
                                    <?php else: ?>
                                        <div style="width: 40px; height: 40px; border-radius: 50%; background: var(--bg-main); display: flex; align-items: center; justify-content: center; font-weight: bold; color: var(--text-secondary);">
                                            <i class="fas fa-user text-secondary"></i>
                                        </div>
                                    <?php endif; ?>
                                    <a href="?page=maids&action=show&id=<?= $maid['id'] ?>" class="fw-bold text-dark text-decoration-none hover-underline"><?= htmlspecialchars($maid['full_name'] ?? '') ?></a>
                                </div>
                            </td>
                            <td>
                                <span class="badge badge-secondary fw-normal">
                                    <i class="fas fa-building" style="<?= isRTL() ? 'margin-left: 4px;' : 'margin-right: 4px;' ?>"></i> <?= htmlspecialchars($maid['agency_name'] ?? '') ?>
                                </span>
                            </td>
                            <td><?= htmlspecialchars(isRTL() ? ($maid['nationality_ar'] ?? $maid['nationality_en'] ?? '') : ($maid['nationality_en'] ?? '')) ?></td>
                            <td><?= htmlspecialchars($maid['years_experience'] ?? '0') ?> <?= __('years') ?></td>
                            <td>
                                <?php if ($maid['verification_status'] === 'approved'): ?>
                                    <span class="badge badge-success">Approved</span>
                                <?php elseif ($maid['verification_status'] === 'rejected'): ?>
                                    <span class="badge badge-danger">Rejected</span>
                                <?php else: ?>
                                    <span class="badge badge-warning">Pending</span>
                                <?php endif; ?>
                            </td>
                            <td>
                                <?php if ($maid['status'] === 'published'): ?>
                                    <span class="badge badge-success"><?= __('active') ?></span>
                                <?php elseif ($maid['status'] === 'suspended'): ?>
                                    <span class="badge badge-danger"><?= __('suspended') ?></span>
                                <?php else: ?>
                                    <span class="badge badge-warning"><?= htmlspecialchars(ucfirst($maid['status'])) ?></span>
                                <?php endif; ?>
                            </td>
                            <td>
                                <a href="?page=maids&action=toggle_recommended&id=<?= $maid['id'] ?>" class="text-decoration-none" title="Toggle Recommended">
                                    <?php if ($maid['is_recommended']): ?>
                                        <i class="fas fa-star text-warning" style="font-size: 1.25rem;"></i>
                                    <?php else: ?>
                                        <i class="far fa-star text-muted" style="font-size: 1.25rem;"></i>
                                    <?php endif; ?>
                                </a>
                            </td>
                            <td>
                                <a href="?page=maids&action=toggle_verified&id=<?= $maid['id'] ?>" class="text-decoration-none" title="Toggle Verified / Reference Checked">
                                    <?php if ($maid['emirates_id_verified']): ?>
                                        <i class="fas fa-check-circle text-success" style="font-size: 1.25rem;"></i>
                                    <?php else: ?>
                                        <i class="far fa-check-circle text-muted" style="font-size: 1.25rem;"></i>
                                    <?php endif; ?>
                                </a>
                            </td>
                            <td class="text-end">
                                <a href="?page=maids&action=show&id=<?= $maid['id'] ?>" class="btn btn-light btn-sm text-primary me-2" title="View Details"><i class="fas fa-eye"></i></a>
                                <?php if ($maid['verification_status'] !== 'approved'): ?>
                                    <a href="?page=maids&action=approve&id=<?= $maid['id'] ?>" class="btn btn-light btn-sm text-success me-2" title="Approve"><i class="fas fa-check"></i></a>
                                <?php endif; ?>
                                <?php if ($maid['verification_status'] !== 'rejected'): ?>
                                    <a href="?page=maids&action=reject&id=<?= $maid['id'] ?>" class="btn btn-light btn-sm text-danger me-2" title="Reject"><i class="fas fa-times"></i></a>
                                <?php endif; ?>
                            </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=maids&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=maids&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=maids&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'; ?>
