<?php 
include 'config.php'; 
include 'header.php'; 

// جلب كل الفروع من قاعدة البيانات
$stmt = $pdo->query("SELECT * FROM branches");
$branches = $stmt->fetchAll();
?>

<style>
    :root { --odoo-purple: #714B67; --odoo-bg: #F0F2F5; }
    body { background-color: var(--odoo-bg); }
    
    /* ستايل كروت الفروع شبه أودو */
    .o_kanban_view { display: flex; flex-wrap: wrap; gap: 15px; padding: 20px; }
    .o_kanban_record { 
        background: white; border: 1px solid #dee2e6; border-radius: 3px;
        width: 300px; padding: 15px; position: relative; transition: 0.3s;
        cursor: pointer;
    }
    .o_kanban_record:hover { box-shadow: 0 4px 10px rgba(0,0,0,0.1); border-color: var(--odoo-purple); }
    .o_primary { color: var(--odoo-purple); font-weight: bold; font-size: 1.1rem; }
    .o_branch_icon { font-size: 2rem; color: #ccc; margin-left: 15px; }
</style>

<div class="container-fluid" dir="rtl">
    <div class="d-flex justify-content-between align-items-center p-3 bg-white border-bottom shadow-sm">
        <h4 class="mb-0 fw-bold text-muted">الفروع</h4>
        <button class="btn btn-primary btn-sm" style="background: var(--odoo-purple); border: none;">
            <i class="fa fa-plus"></i> إنشاء فرع جديد
        </button>
    </div>

    <div class="o_kanban_view">
        <?php foreach($branches as $b): ?>
        <div class="o_kanban_record d-flex align-items-start" onclick="location.href='branch_details.php?id=<?= $b['id'] ?>'">
            <div class="o_branch_icon">
                <i class="fa fa-building text-opacity-25"></i>
            </div>
            <div class="flex-grow-1">
                <div class="o_primary"><?= $b['branch_name'] ?></div>
                <div class="text-muted small mb-2"><i class="fa fa-map-marker me-1"></i> <?= $b['location'] ?></div>
                <div class="d-flex justify-content-between mt-3 border-top pt-2">
                    <span class="badge bg-soft-info text-primary border border-primary border-opacity-10">إدارة الفرع</span>
                    <i class="fa fa-arrow-left text-muted mt-1"></i>
                </div>
            </div>
        </div>
        <?php endforeach; ?>
    </div>
</div>

<?php include 'footer.php'; ?>