<?php
require_once 'config/database.php';
require_once 'app/helpers/auth.php';
requireLogin();
$page_js = 'departments.js';
include 'views/layouts/header.php';
include 'views/layouts/sidebar.php';
?>
<main class="main-content">
<?php include 'views/layouts/topbar.php'; ?>
<div class="container-fluid p-4">
    <div id="alertBox" class="alert d-none"></div>
    <div class="card shadow-sm border-0 mb-4">
        <div class="card-body p-4 p-lg-5">
            <div class="row g-4 align-items-center">
                <div class="col-lg-8">
                    <span class="badge bg-primary bg-opacity-10 text-primary mb-3 px-3 py-2">Organization</span>
                    <h2 class="mb-2">Departments</h2>
                    <p class="mb-0 text-muted">Manage departments for organisational structure and reporting.</p>
                </div>
                <div class="col-lg-4 text-lg-end">
                    <button type="button" class="btn btn-primary" id="btnAdd"><i class="bi bi-plus-lg"></i> Add Department</button>
                </div>
            </div>
        </div>
    </div>
    <div class="row g-4 mb-4">
        <div class="col-12 col-md-6"><div class="card kpi-card shadow-sm border-0 rounded-4 h-100"><div class="card-body py-3 px-3"><div class="d-flex justify-content-between align-items-center"><div><div class="kpi-label">Total</div><div class="kpi-value" id="kpiTotal">0</div></div><div class="kpi-icon text-primary fs-3"><i class="bi bi-building"></i></div></div></div></div></div>
        <div class="col-12 col-md-6"><div class="card kpi-card shadow-sm border-0 rounded-4 h-100"><div class="card-body py-3 px-3"><div class="d-flex justify-content-between align-items-center"><div><div class="kpi-label">Active</div><div class="kpi-value" id="kpiActive">0</div></div><div class="kpi-icon text-success fs-3"><i class="bi bi-check-circle"></i></div></div></div></div></div>
    </div>
    <div class="card shadow-sm border-0">
        <div class="card-body">
            <div class="row mb-3">
                <div class="col-md-4"><input type="text" id="searchBox" class="form-control" placeholder="Search departments..."></div>
            </div>
            <div class="table-responsive">
                <table class="table align-middle mb-0">
                    <thead class="table-light"><tr><th>Name</th><th>Status</th><th class="text-end">Actions</th></tr></thead>
                    <tbody id="tableBody"><tr><td colspan="3" class="text-center text-muted py-4">Loading...</td></tr></tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="itemModal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="modalTitle">Add Department</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>
            <div class="modal-body">
                <input type="hidden" id="itemId" value="0">
                <div class="mb-3">
                    <label class="form-label">Department Name <span class="text-danger">*</span></label>
                    <input type="text" id="itemName" class="form-control">
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
                <button type="button" class="btn btn-primary" id="btnSave">Save</button>
            </div>
        </div>
    </div>
</div>
</main>
<?php include 'views/layouts/footer.php'; ?>
