<?php
use App\Models\Settings;

// System branding
$appConfig = new Settings();
$appName   = $appConfig->get('company_name', 'Finance Manager');
$logo      = $appConfig->get('logo');
$logoUrl   = $logo ? $this->baseUrl('/' . ltrim($logo, '/')) : null;

// Client info
$clientName = $_SESSION['client_name'] ?? 'Client';
$clientCode = $_SESSION['client_code'] ?? '';
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= htmlspecialchars($clientName) ?> - <?= htmlspecialchars($appName) ?></title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.0/font/bootstrap-icons.css">
    <link rel="stylesheet" href="<?= $this->baseUrl('/css/style.css') ?>">
    <style>
        .client-navbar {
            background: #fff;
            border-bottom: 2px solid var(--gold);
            box-shadow: 0 2px 8px rgba(0,0,0,0.04);
        }
        .client-navbar .navbar-brand {
            font-weight: 700;
            color: #0f172a;
        }
        .client-navbar .nav-link {
            color: #475569;
            font-weight: 500;
            margin: 0 0.25rem;
            border-radius: 6px;
        }
        .client-navbar .nav-link:hover,
        .client-navbar .nav-link.active {
            background: rgba(212,175,55,0.1);
            color: #0f172a;
        }
        .client-navbar .dropdown-menu {
            border: 1px solid rgba(0,0,0,0.08);
            border-radius: 0.5rem;
            box-shadow: 0 8px 20px rgba(0,0,0,0.08);
        }
    </style>
</head>
<body class="bg-light">

<nav class="navbar navbar-expand-lg client-navbar py-2">
    <div class="container">
        <a class="navbar-brand d-flex align-items-center gap-2" href="<?= $this->baseUrl('/client/dashboard') ?>">
            <?php if ($logoUrl): ?>
                <img src="<?= $logoUrl ?>" alt="Logo" style="height:30px; max-width:90px;">
            <?php else: ?>
                <span style="font-size:1.4rem;">💰</span>
            <?php endif; ?>
            <?= htmlspecialchars($appName) ?>
        </a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#clientNav">
            <span class="navbar-toggler-icon"></span>
        </button>

        <div class="collapse navbar-collapse" id="clientNav">
            <ul class="navbar-nav ms-auto mb-2 mb-lg-0">
                <li class="nav-item">
                    <a class="nav-link <?= strpos($_SERVER['REQUEST_URI'], '/client/dashboard') !== false ? 'active' : '' ?>" 
                       href="<?= $this->baseUrl('/client/dashboard') ?>">
                        <i class="bi bi-speedometer2 me-1"></i> Dashboard
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link <?= strpos($_SERVER['REQUEST_URI'], '/client/transactions') !== false ? 'active' : '' ?>" 
                       href="<?= $this->baseUrl('/client/transactions') ?>">
                        <i class="bi bi-list-ul me-1"></i> Transactions
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="<?= $this->baseUrl('/client/statement/pdf') ?>">
                        <i class="bi bi-download me-1"></i> Statement
                    </a>
                </li>
                <li class="nav-item dropdown ms-2">
                    <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown">
                        <i class="bi bi-person-circle me-1"></i> <?= htmlspecialchars($clientName) ?>
                    </a>
                    <ul class="dropdown-menu dropdown-menu-end">
                        <li>
                            <a class="dropdown-item" href="<?= $this->baseUrl('/client/dashboard') ?>">
                                <i class="bi bi-speedometer2 me-2"></i> Dashboard
                            </a>
                        </li>
                        <li><hr class="dropdown-divider"></li>
                        <li>
                            <a class="dropdown-item text-danger" href="<?= $this->baseUrl('/client/logout') ?>">
                                <i class="bi bi-box-arrow-right me-2"></i> Logout
                            </a>
                        </li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
</nav>

<div class="container mt-4">