<div class="row">
    <div class="col-12">
        <div class="card glass-card">
            <div class="card-header">
                <div class="card-header-left">
                    <i class="fas fa-building card-icon"></i>
                    <h5 class="card-title">Branches</h5>
                </div>
                <div class="card-header-actions">
                    <?php if (can('branches_create')): ?>
                        <a href="<?= url('branches/create') ?>" class="btn btn-gold btn-sm">
                            <i class="fas fa-plus me-1"></i>Add Branch
                        </a>
                    <?php endif; ?>
                </div>
            </div>
            <div class="card-body p-0">
                <div class="table-responsive">
                    <table class="table table-hover align-middle mb-0">
                        <thead>
                            <tr>
                                <th>Name</th>
                                <th>Contact</th>
                                <th>City / State</th>
                                <th class="text-center">Users</th>
                                <th>Status</th>
                                <th class="text-end">Actions</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php if (empty($branches)): ?>
                            <tr>
                                <td colspan="6" class="text-center py-4 text-muted">No branches found.</td>
                            </tr>
                            <?php else: ?>
                                <?php foreach ($branches as $branch): ?>
                                <tr>
                                    <td>
                                        <strong><?= e($branch->name) ?></strong>
                                        <div class="text-muted small"><?= e($branch->slug) ?></div>
                                    </td>
                                    <td>
                                        <div><?= e($branch->phone ?? '-') ?></div>
                                        <div class="text-muted small"><?= e($branch->email ?? '-') ?></div>
                                    </td>
                                    <td><?= e(implode(', ', array_filter([$branch->city ?? '', $branch->state ?? '']))) ?: '-' ?></td>
                                    <td class="text-center"><span class="badge bg-gold"><?= $branch->user_count ?></span></td>
                                    <td>
                                        <?php if ($branch->status === 'active'): ?>
                                            <span class="badge bg-success">Active</span>
                                        <?php else: ?>
                                            <span class="badge bg-secondary">Inactive</span>
                                        <?php endif; ?>
                                    </td>
                                    <td class="text-end">
                                        <?php if (can('branches_edit')): ?>
                                            <a href="<?= url('branches/edit/' . $branch->id) ?>" class="btn btn-sm btn-ghost" title="Edit">
                                                <i class="fas fa-edit"></i>
                                            </a>
                                        <?php endif; ?>
                                        <?php if (can('branches_delete')): ?>
                                            <button type="button" class="btn btn-sm btn-ghost text-danger" 
                                                    onclick="confirmDelete('<?= url('branches/delete/' . $branch->id) ?>')" title="Delete">
                                                <i class="fas fa-trash-alt"></i>
                                            </button>
                                        <?php endif; ?>
                                    </td>
                                </tr>
                                <?php endforeach; ?>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
