<?= $this->extend('layouts/enterprise') ?>

<?= $this->section('content') ?>

<?php
$currencyMeta = $currencies[$company['currency_code']] ?? null;
$currencyLabel = $currencyMeta
    ? $currencyMeta['label'] . ' (' . $company['currency_code'] . ' - ' . $currencyMeta['symbol'] . ')'
    : $company['currency_code'];
?>

<section class="enterprise-workspace-hero">
    <div class="enterprise-workspace-crumb">
        <span class="enterprise-crumb-pill">Administration</span>
        <span class="enterprise-crumb-sep">/</span>
        <span class="enterprise-crumb-current">System Settings</span>
    </div>
    <h1 class="enterprise-workspace-title">Administrative Configuration Workspace</h1>
    <p class="enterprise-workspace-desc">
        Authorized central administrative panel for PULSE assets, company profile,
        security policies, and operational defaults.
    </p>
</section>

<div class="enterprise-settings-grid">
    <div class="enterprise-settings-main">
        <article class="enterprise-settings-card">
            <div class="enterprise-settings-card__head">
                <i class="fa-solid fa-gear"></i>
                <h2 class="enterprise-settings-card__title">General System Configurations</h2>
            </div>

            <div class="enterprise-settings-fields">
                <div class="enterprise-field">
                    <label class="enterprise-field-label">Default Currency Paradigm</label>
                    <div class="enterprise-field-readonly"><?= esc($currencyLabel) ?></div>
                </div>
                <div class="enterprise-field">
                    <label class="enterprise-field-label">Primary Operational Timezone</label>
                    <div class="enterprise-field-readonly"><?= esc($company['timezone']) ?></div>
                </div>
                <div class="enterprise-field">
                    <label class="enterprise-field-label">Two-Factor Security Assertion</label>
                    <div class="enterprise-field-readonly">
                        <?= $settings['security']['twoFactorEnabled'] ? 'Required for All Directors (L1)' : 'Optional — Not Enforced' ?>
                    </div>
                </div>
                <div class="enterprise-field">
                    <label class="enterprise-field-label">Session Idle Timeout Policy</label>
                    <div class="enterprise-field-readonly">
                        <?= esc($settings['security']['sessionIdleTimeout']) ?> Minutes Before Auto-Logout
                    </div>
                </div>
                <div class="enterprise-field">
                    <label class="enterprise-field-label">Application Environment</label>
                    <div class="enterprise-field-readonly"><?= esc(strtoupper($settings['application']['environment'])) ?></div>
                </div>
                <div class="enterprise-field">
                    <label class="enterprise-field-label">Default Locale Context</label>
                    <div class="enterprise-field-readonly"><?= esc($company['locale']) ?></div>
                </div>
                <div class="enterprise-field">
                    <label class="enterprise-field-label">Login Lockout Strategy</label>
                    <div class="enterprise-field-readonly">
                        <?= esc(ucfirst($settings['security']['lockoutStrategy'])) ?>
                        — <?= esc($settings['security']['maxLoginAttempts']) ?> Attempts /
                        <?= esc($settings['security']['lockoutMinutes']) ?> Min Lockout
                    </div>
                </div>
                <div class="enterprise-field">
                    <label class="enterprise-field-label">Password Policy Baseline</label>
                    <div class="enterprise-field-readonly">
                        Min <?= esc($settings['security']['passwordMinLength']) ?> Chars ·
                        History <?= esc($settings['security']['passwordHistoryLimit']) ?> Passwords
                    </div>
                </div>
            </div>

            <div class="enterprise-settings-card__footer">
                <a href="<?= base_url('settings/company') ?>" class="btn btn-primary">
                    Configure Company Settings
                </a>
            </div>
        </article>

        <article class="enterprise-settings-card">
            <div class="enterprise-settings-card__head">
                <i class="fa-solid fa-sliders"></i>
                <h2 class="enterprise-settings-card__title">Module Administration</h2>
            </div>
            <p class="enterprise-settings-card__intro">
                Enable or disable modules for your company and configure TPIN security policies.
            </p>
            <div class="enterprise-quick-links">
                <a href="<?= base_url('settings/modules') ?>" class="btn btn-sm btn-primary">
                    <i class="fa-solid fa-puzzle-piece me-1"></i>Modules & Security
                </a>
                <a href="<?= base_url('users') ?>" class="btn btn-sm btn-outline-secondary">
                    <i class="fa-solid fa-users me-1"></i>Users
                </a>
                <a href="<?= base_url('roles') ?>" class="btn btn-sm btn-outline-secondary">
                    <i class="fa-solid fa-user-shield me-1"></i>Roles
                </a>
                <a href="<?= base_url('permissions') ?>" class="btn btn-sm btn-outline-secondary">
                    <i class="fa-solid fa-key me-1"></i>Permissions
                </a>
                <a href="<?= base_url('account/sessions') ?>" class="btn btn-sm btn-outline-secondary">
                    <i class="fa-solid fa-display me-1"></i>Active Sessions
                </a>
            </div>
        </article>
    </div>

    <aside class="enterprise-settings-aside">
        <article class="enterprise-settings-card">
            <div class="enterprise-settings-card__head">
                <i class="fa-solid fa-building"></i>
                <h2 class="enterprise-settings-card__title">Company Profile</h2>
            </div>
            <p class="enterprise-settings-card__intro">
                Active company identity and branding used across invoices, reports, and the application shell.
            </p>

            <div class="enterprise-logo-panel">
                <div class="enterprise-logo-preview">
                    <?php if (! empty($company['logo_path'])): ?>
                        <img src="<?= base_url($company['logo_path']) ?>" alt="<?= esc($company['name']) ?>">
                    <?php else: ?>
                        <i class="fa-solid fa-building"></i>
                    <?php endif; ?>
                </div>
                <div class="enterprise-logo-name"><?= esc($company['name']) ?></div>
            </div>

            <div class="enterprise-settings-fields enterprise-settings-fields--single">
                <div class="enterprise-field">
                    <label class="enterprise-field-label">Registered Legal Entity</label>
                    <div class="enterprise-field-readonly"><?= esc($company['legal_name'] ?: '—') ?></div>
                </div>
                <div class="enterprise-field">
                    <label class="enterprise-field-label">Commercial Registration</label>
                    <div class="enterprise-field-readonly enterprise-field-readonly--mono">
                        <?= esc($company['commercial_registration'] ?: '—') ?>
                    </div>
                </div>
                <div class="enterprise-field">
                    <label class="enterprise-field-label">Tax / VAT Identifier</label>
                    <div class="enterprise-field-readonly enterprise-field-readonly--mono">
                        <?= esc($company['tax_id'] ?: '—') ?>
                    </div>
                </div>
            </div>

            <div class="enterprise-settings-card__footer">
                <a href="<?= base_url('settings/company') ?>" class="btn btn-sm btn-outline-secondary w-100">
                    Edit Company Profile
                </a>
            </div>
        </article>

        <article class="enterprise-settings-card">
            <div class="enterprise-settings-card__head">
                <i class="fa-solid fa-key"></i>
                <h2 class="enterprise-settings-card__title">Operational Context</h2>
            </div>
            <p class="enterprise-settings-card__intro">
                Below are operational variables injected from the secure environment runtime context.
            </p>

            <div class="enterprise-settings-fields enterprise-settings-fields--single">
                <div class="enterprise-field">
                    <label class="enterprise-field-label">Application Base Endpoint</label>
                    <div class="enterprise-field-readonly enterprise-field-readonly--mono">
                        <?= esc(rtrim($settings['application']['baseUrl'], '/')) ?>
                    </div>
                </div>
                <div class="enterprise-field">
                    <label class="enterprise-field-label">Runtime Environment Node</label>
                    <div class="enterprise-field-readonly enterprise-field-readonly--mono">
                        <?= esc(strtolower($settings['application']['environment'])) ?>_ctx_<?= esc(PHP_MAJOR_VERSION) ?><?= esc(PHP_MINOR_VERSION) ?>
                    </div>
                </div>
                <div class="enterprise-field">
                    <label class="enterprise-field-label">Email Verification Gate</label>
                    <div class="enterprise-field-readonly">
                        <?= $settings['security']['requireEmailVerification'] ? 'Enforced on Registration' : 'Not Required' ?>
                    </div>
                </div>
            </div>
        </article>
    </aside>
</div>

<?= $this->endSection() ?>
