<?php
$stores = isset($stores) ? $stores : array();
$schedules = isset($schedules) ? $schedules : array();
?>

<div class="container-fluid py-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h4 class="fw-bold mb-1"><i class="fa-solid fa-store text-primary me-2"></i>Checklist Store Assignment</h4>
            <p class="text-muted mb-0">Mapping routine checklists and audits to specific physical branch stores.</p>
        </div>
    </div>

    <div class="card border-0 shadow-sm rounded-4">
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-hover align-middle mb-0">
                    <thead class="table-light">
                        <tr>
                            <th class="ps-4">Store Branch</th>
                            <th>Location</th>
                            <th>Active Routine Checklists</th>
                            <th>Status</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($stores as $sId => $s): ?>
                            <tr>
                                <td class="ps-4">
                                    <div class="fw-bold text-dark"><?php echo htmlspecialchars(isset($s['name']) ? $s['name'] : $sId); ?></div>
                                    <div class="small text-muted font-monospace">ID: <?php echo htmlspecialchars($sId); ?></div>
                                </td>
                                <td><?php echo htmlspecialchars(isset($s['city']) ? $s['city'] : 'Islamabad'); ?></td>
                                <td>
                                    <div class="d-flex flex-wrap gap-1">
                                        <?php foreach ($schedules as $sc): ?>
                                            <?php if (isset($sc['storeStatus'][$sId])): ?>
                                                <span class="badge bg-primary bg-opacity-10 text-primary border border-primary">
                                                    <?php echo htmlspecialchars(isset($sc['title']) ? $sc['title'] : 'Routine'); ?>
                                                </span>
                                            <?php endif; ?>
                                        <?php endforeach; ?>
                                    </div>
                                </td>
                                <td>
                                    <span class="badge bg-success bg-opacity-10 text-success rounded-pill px-3 py-1">Enrolled</span>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
