<?php 
require_once 'includes/db.php';
require_once 'includes/header.php'; 

$cell_type = 'STATE';
$page_title = 'Board Members';
$breadcrumb_active = 'Board Members';

// If this file is included by others, they might set these variables
if (isset($override_cell)) $cell_type = $override_cell;
if (isset($override_title)) $page_title = $override_title;
?>

<!-- Page Hero Banner -->
<div class="position-relative" style="background: linear-gradient(135deg, #A20E37 0%, #7b0a28 60%, #FBBC09 100%); padding: 60px 0;">
    <div class="container text-white text-center">
        <h1 class="fw-bold mb-2" style="font-size:2.5rem; letter-spacing:1px;"><?php echo h($page_title); ?></h1>
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb justify-content-center mb-0">
                <li class="breadcrumb-item"><a href="index.php" class="text-warning">Home</a></li>
                <li class="breadcrumb-item"><a href="about.php" class="text-warning">About Us</a></li>
                <li class="breadcrumb-item active text-white"><?php echo h($page_title); ?></li>
            </ol>
        </nav>
    </div>
</div>

<section class="py-5" style="background:#f8fafc;">
<div class="container">

    <div class="text-center mb-5">
        <span class="badge px-3 py-2 mb-2" style="background:#fff3f6; color:#A20E37; font-size:0.9rem; border-radius:20px;">Organization Structure</span>
        <h2 class="fw-bold" style="color:#1e293b;">Our <span style="color:#A20E37;"><?php echo h($page_title); ?></span></h2>
        <p class="text-muted">The dedicated team members of Bhartiya Seva Educational Sangthan Trust.</p>
    </div>

    <!-- Members Table -->
    <div class="card border-0 shadow-sm rounded-4 overflow-hidden mb-5">
        <div class="card-header py-3" style="background: linear-gradient(135deg, #A20E37, #7b0a28);">
            <h5 class="text-white mb-0 fw-bold"><i class="fas fa-users me-2"></i><?php echo h($page_title); ?> — BSES Trust</h5>
        </div>
        <div class="table-responsive">
            <table class="table table-hover mb-0 align-middle">
                <thead style="background:#fff3f6;">
                    <tr>
                        <th class="py-3 ps-4" style="color:#A20E37; font-weight:700; width:80px;">Image</th>
                        <th class="py-3" style="color:#A20E37; font-weight:700;">Name</th>
                        <th class="py-3" style="color:#A20E37; font-weight:700;">Designation</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    $res = $conn->query("SELECT * FROM board_members WHERE cell = '$cell_type' ORDER BY sort_order ASC, id DESC");
                    if ($res->num_rows > 0):
                        while($row = $res->fetch_assoc()):
                            $img_src = (strpos($row['image'], 'http') === 0) ? $row['image'] : 'uploads/members/'.$row['image'];
                            if (empty($row['image'])) $img_src = 'https://ui-avatars.com/api/?name='.urlencode($row['name']).'&background=random';
                    ?>
                    <tr style="border-bottom:1px solid #f0e0e5;">
                        <td class="py-3 ps-4">
                            <img src="<?php echo $img_src; ?>" class="rounded-circle border" width="50" height="50" style="object-fit: cover;" onerror="this.src='https://ui-avatars.com/api/?name=<?php echo urlencode($row['name']); ?>&background=random'">
                        </td>
                        <td class="py-3 fw-semibold text-dark"><?php echo h($row['name']); ?></td>
                        <td class="py-3">
                            <span class="badge px-3 py-2" style="background:#fff3f6; color:#A20E37; border:1px solid #A20E37; border-radius:15px; font-size:0.85rem;"><?php echo h($row['designation']); ?></span>
                        </td>
                    </tr>
                    <?php endwhile; else: ?>
                    <tr>
                        <td colspan="3" class="text-center py-5 text-muted">No members found in this section.</td>
                    </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>

</div>
</section>

<?php require_once 'includes/footer.php'; ?>
