<?php

declare(strict_types=1);
// Variables: $baseUrl, $assetsUrl, $project, $user, $navItems, $pageTitle
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
    <title><?= htmlspecialchars($project['name'] ?? 'Project') ?> - Security</title>
    <?php include constant('BASE_PATH') . '/core/views/project-head.php'; ?>

    <?= \PpPhp\Core\ModuleAssets::style('Security', 'Views/styles.css') ?>
</head>

<body class="security-module">
    <?php include __DIR__ . '/partials/shell.php'; ?>

    <div id="mainArea" class="main-area">
        <!-- Sidebar with accordion categories -->
        <aside class="left-panel security-sidebar" id="securitySidebar" aria-label="Security configuration navigation">
            <div class="panel-header security-sidebar-header">
                <div class="security-sidebar-title">
                    <span class="security-sidebar-icon"><i class="bi bi-shield-check"></i></span>
                    <span>
                        <small>Project protection</small>
                        <strong>Security</strong>
                    </span>
                </div>
                <span class="security-module-count" title="Available security areas">12</span>
            </div>
            <div class="security-nav-tools">
                <div class="security-nav-search">
                    <i class="bi bi-search" aria-hidden="true"></i>
                    <input type="search" id="securityNavSearch" placeholder="Find a security setting" aria-label="Find a security setting">
                    <button type="button" id="clearSecurityNavSearch" aria-label="Clear security search" title="Clear search"><i class="bi bi-x-lg"></i></button>
                </div>
                <div class="security-nav-summary">
                    <span><i class="bi bi-layers"></i> 7 categories</span>
                    <span id="securityNavResultCount">12 settings</span>
                </div>
            </div>
            <div class="accordion" id="securityAccordion">
                <!-- Settings (always expanded) -->
                <div class="accordion-item">
                    <h2 class="accordion-header">
                        <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#settingsCollapse">
                            <span class="security-category-icon" aria-hidden="true"><i class="bi bi-sliders2-vertical"></i></span>
                            <span class="security-category-label">Settings</span>
                        </button>
                    </h2>
                    <div id="settingsCollapse" class="accordion-collapse collapse show" data-bs-parent="#securityAccordion">
                        <div class="accordion-body p-0">
                            <ul class="nav flex-column">
                                <li class="nav-item"><a href="#" data-page="settings-database" class="nav-link"><span class="security-setting-icon" aria-hidden="true"><i class="bi bi-database"></i></span><span class="security-setting-label">Database</span></a></li>
                                <li class="nav-item"><a href="#" data-page="settings-login" class="nav-link"><span class="security-setting-icon" aria-hidden="true"><i class="bi bi-box-arrow-in-right"></i></span><span class="security-setting-label">Login Security</span></a></li>
                                <li class="nav-item"><a href="#" data-page="settings-registration" class="nav-link"><span class="security-setting-icon" aria-hidden="true"><i class="bi bi-pencil-square"></i></span><span class="security-setting-label">Registration & Passwords</span></a></li>
                                <li class="nav-item"><a href="#" data-page="settings-emails" class="nav-link"><span class="security-setting-icon" aria-hidden="true"><i class="bi bi-envelope-paper"></i></span><span class="security-setting-label">Email Templates</span></a></li>
                                <li class="nav-item"><a href="#" data-page="settings-social" class="nav-link"><span class="security-setting-icon" aria-hidden="true"><i class="bi bi-person-badge"></i></span><span class="security-setting-label">Social Login Providers</span></a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <!-- Users & Groups -->
                <div class="accordion-item">
                    <h2 class="accordion-header">
                        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#usersCollapse">
                            <span class="security-category-icon" aria-hidden="true"><i class="bi bi-people"></i></span>
                            <span class="security-category-label">Users & Groups</span>
                        </button>
                    </h2>
                    <div id="usersCollapse" class="accordion-collapse collapse" data-bs-parent="#securityAccordion">
                        <div class="accordion-body p-0">
                            <ul class="nav flex-column">
                                <li class="nav-item"><a href="#" data-page="users" class="nav-link"><span class="security-setting-icon" aria-hidden="true"><i class="bi bi-person"></i></span><span class="security-setting-label">Users</span></a></li>
                                <li class="nav-item"><a href="#" data-page="groups" class="nav-link"><span class="security-setting-icon" aria-hidden="true"><i class="bi bi-shield-lock"></i></span><span class="security-setting-label">Groups</span></a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <!-- Permissions -->
                <div class="accordion-item">
                    <h2 class="accordion-header">
                        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#permsCollapse">
                            <span class="security-category-icon" aria-hidden="true"><i class="bi bi-key"></i></span>
                            <span class="security-category-label">Permissions</span>
                        </button>
                    </h2>
                    <div id="permsCollapse" class="accordion-collapse collapse" data-bs-parent="#securityAccordion">
                        <div class="accordion-body p-0">
                            <ul class="nav flex-column">
                                <li class="nav-item"><a href="#" data-page="permissions" class="nav-link"><span class="security-setting-icon" aria-hidden="true"><i class="bi bi-grid-3x3-gap"></i></span><span class="security-setting-label">Table & Page Permissions</span></a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <!-- Two-Factor Authentication -->
                <div class="accordion-item">
                    <h2 class="accordion-header">
                        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#twofaCollapse">
                            <span class="security-category-icon" aria-hidden="true"><i class="bi bi-shield-lock"></i></span>
                            <span class="security-category-label">Two‑Factor Authentication</span>
                        </button>
                    </h2>
                    <div id="twofaCollapse" class="accordion-collapse collapse" data-bs-parent="#securityAccordion">
                        <div class="accordion-body p-0">
                            <ul class="nav flex-column">
                                <li class="nav-item"><a href="#" data-page="twofactor" class="nav-link"><span class="security-setting-icon" aria-hidden="true"><i class="bi bi-qr-code"></i></span><span class="security-setting-label">2FA Setup</span></a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <!-- Advanced Security -->
                <div class="accordion-item">
                    <h2 class="accordion-header">
                        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#advancedCollapse">
                            <span class="security-category-icon" aria-hidden="true"><i class="bi bi-shield-plus"></i></span>
                            <span class="security-category-label">Advanced Security</span>
                        </button>
                    </h2>
                    <div id="advancedCollapse" class="accordion-collapse collapse" data-bs-parent="#securityAccordion">
                        <div class="accordion-body p-0">
                            <ul class="nav flex-column">
                                <li class="nav-item"><a href="#" data-page="advanced" class="nav-link"><span class="security-setting-icon" aria-hidden="true"><i class="bi bi-diagram-3"></i></span><span class="security-setting-label">Row‑Level Security</span></a></li>
                                <li class="nav-item"><a href="#" data-page="encryption" class="nav-link"><span class="security-setting-icon" aria-hidden="true"><i class="bi bi-lock"></i></span><span class="security-setting-label">Field Encryption</span></a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <!-- Audit & Locking -->
                <div class="accordion-item">
                    <h2 class="accordion-header">
                        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#auditCollapse">
                            <span class="security-category-icon" aria-hidden="true"><i class="bi bi-journal-check"></i></span>
                            <span class="security-category-label">Audit & Locking</span>
                        </button>
                    </h2>
                    <div id="auditCollapse" class="accordion-collapse collapse" data-bs-parent="#securityAccordion">
                        <div class="accordion-body p-0">
                            <ul class="nav flex-column">
                                <li class="nav-item"><a href="#" data-page="audit" class="nav-link"><span class="security-setting-icon" aria-hidden="true"><i class="bi bi-journal-text"></i></span><span class="security-setting-label">Audit Log</span></a></li>
                                <li class="nav-item"><a href="#" data-page="locks" class="nav-link"><span class="security-setting-icon" aria-hidden="true"><i class="bi bi-lock-fill"></i></span><span class="security-setting-label">Record Locks</span></a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <!-- Session Control -->
                <div class="accordion-item">
                    <h2 class="accordion-header">
                        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#sessionCollapse">
                            <span class="security-category-icon" aria-hidden="true"><i class="bi bi-clock-history"></i></span>
                            <span class="security-category-label">Session Control</span>
                        </button>
                    </h2>
                    <div id="sessionCollapse" class="accordion-collapse collapse" data-bs-parent="#securityAccordion">
                        <div class="accordion-body p-0">
                            <ul class="nav flex-column">
                                <li class="nav-item"><a href="#" data-page="session" class="nav-link"><span class="security-setting-icon" aria-hidden="true"><i class="bi bi-hourglass-split"></i></span><span class="security-setting-label">Session Settings</span></a></li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
            <div class="security-sidebar-footer">
                <i class="bi bi-info-circle"></i>
                <span>Changes are stored with this project.</span>
            </div>
        </aside>

        <!-- Right workspace -->
        <div class="right-workspace">
            <div class="toolbar security-toolbar" id="securityToolbar">
                <button type="button" class="security-nav-toggle" id="btnToggleSecurityNav" aria-controls="securitySidebar" aria-expanded="false" title="Open security navigation">
                    <i class="bi bi-list"></i>
                </button>
                <span class="security-page-icon" id="selectedPageIcon"><i class="bi bi-database-check"></i></span>
                <div class="security-page-context">
                    <div class="security-page-kicker" id="selectedPageLabel">Settings / Database</div>
                    <strong id="selectedPageTitle">Authentication database</strong>
                    <span id="selectedPageDescription">Connect user accounts and identity fields to your project data.</span>
                </div>
                <div class="security-toolbar-actions">
                    <span class="security-status-pill" id="securityAuthState"><i class="bi bi-circle-fill"></i> Checking authentication</span>
                    <button type="button" class="btn btn-sm btn-outline-secondary" id="btnSecurityGuide" data-bs-toggle="modal" data-bs-target="#securityGuideModal" title="Open the Security module guide"><i class="bi bi-question-circle me-1"></i><span>Guide</span></button>
                    <button class="btn btn-sm btn-success" id="btnSaveSecurity" title="Save settings on the current Security page"><i class="bi bi-check-lg me-1"></i> Save</button>
                </div>
            </div>
            <div class="workspace-content" id="securityWorkspace">
                <div id="securityPageContainer">
                    <!-- dynamic content -->
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="securityGuideModal" tabindex="-1" aria-labelledby="securityGuideTitle" aria-hidden="true">
        <div class="modal-dialog modal-xl modal-dialog-centered modal-dialog-scrollable">
            <div class="modal-content security-guide-modal">
                <div class="modal-header">
                    <div class="d-flex align-items-center gap-3">
                        <span class="security-guide-icon"><i class="bi bi-shield-check"></i></span>
                        <div><span class="security-page-kicker">Basic to advanced · Security guide</span><h5 class="modal-title" id="securityGuideTitle">Protect every layer of your application</h5></div>
                    </div>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <?php include __DIR__ . '/partials/security-guide.php'; ?>
                </div>
                <div class="modal-footer"><span class="me-auto text-muted"><i class="bi bi-info-circle me-1"></i>Recommended order: identity → access → protection → verification.</span><button type="button" class="btn btn-primary" data-bs-dismiss="modal">Close guide</button></div>
            </div>
        </div>
    </div>

    <?php include constant('BASE_PATH') . '/core/views/project-scripts.php'; ?>

    <script>
        const projectSlug = <?= json_encode($project['slug'] ?? '') ?>;
        const baseUrl = <?= json_encode($baseUrl) ?>;
    </script>

    <!-- Modular scripts -->
    <?= \PpPhp\Core\ModuleAssets::script('Security', 'Views/scripts/core.js') ?>
    <?= \PpPhp\Core\ModuleAssets::script('Security', 'Views/scripts/database.js') ?>
    <?= \PpPhp\Core\ModuleAssets::script('Security', 'Views/scripts/login-appearance.js') ?>
    <?= \PpPhp\Core\ModuleAssets::script('Security', 'Views/scripts/social-auth.js') ?>
    <?= \PpPhp\Core\ModuleAssets::script('Security', 'Views/scripts/registration.js') ?>
        <?= \PpPhp\Core\ModuleAssets::script('Security', 'Views/scripts/auth-emails.js') ?>
    <?= \PpPhp\Core\ModuleAssets::script('Security', 'Views/scripts/users.js') ?>
    <?= \PpPhp\Core\ModuleAssets::script('Security', 'Views/scripts/groups.js') ?>
    <?= \PpPhp\Core\ModuleAssets::script('Security', 'Views/scripts/permissions.js') ?>
    <?= \PpPhp\Core\ModuleAssets::script('Security', 'Views/scripts/twofactor.js') ?>
    <?= \PpPhp\Core\ModuleAssets::script('Security', 'Views/scripts/advanced.js') ?>
    <?= \PpPhp\Core\ModuleAssets::script('Security', 'Views/scripts/audit.js') ?>
    <?= \PpPhp\Core\ModuleAssets::script('Security', 'Views/scripts/encryption.js') ?>
    <?= \PpPhp\Core\ModuleAssets::script('Security', 'Views/scripts/session.js') ?>
    <?= \PpPhp\Core\ModuleAssets::script('Security', 'Views/scripts/save.js') ?>
    <?= \PpPhp\Core\ModuleAssets::script('Security', 'Views/scripts/init.js') ?>
</body>

</html>
