<?php

require_once BASE_PATH . '/app/helpers/Status.php';

$pageTitle = $pageTitle ?? APP_NAME;

$pageDescription =
    $pageDescription
    ?? 'Cửa hàng sản phẩm dành cho thú cưng.';

$layoutRoute = trim($_GET['url'] ?? '', '/');
$isAdminArea = str_starts_with($layoutRoute, 'admin');

$styleVersion = static function (string $file): string {
    $path = BASE_PATH . '/public/assets/css/' . ltrim($file, '/');
    $mtime = @filemtime($path);
    return $mtime ? (string) $mtime : '1';
};

?>

<!DOCTYPE html>

<html lang="vi">

<head>

    <meta charset="UTF-8">

    <meta
        name="viewport"
        content="width=device-width, initial-scale=1.0"
    >

    <meta
        name="description"
        content="<?= htmlspecialchars($pageDescription) ?>"
    >

    <title>
        <?= htmlspecialchars($pageTitle) ?>
    </title>

    <!-- Google Fonts -->
    <link rel="preconnect" href="https://fonts.googleapis.com">

    <link
        rel="preconnect"
        href="https://fonts.gstatic.com"
        crossorigin
    >

    <link
        href="https://fonts.googleapis.com/css2?family=Be+Vietnam+Pro:wght@400;500;600;700;800&display=swap"
        rel="stylesheet"
    >

    <!-- Bootstrap 5 -->
    <link
        href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"
        rel="stylesheet"
    >

    <!-- Bootstrap Icons -->
    <link
        rel="stylesheet"
        href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css"
    >

    <!-- CSS chính -->
    <link
        rel="stylesheet"
        href="<?= BASE_URL ?>/assets/css/style.css?v=<?= urlencode($styleVersion('style.css')) ?>"
    >

    <!-- Responsive -->
    <link
        rel="stylesheet"
        href="<?= BASE_URL ?>/assets/css/responsive.css?v=<?= urlencode($styleVersion('responsive.css')) ?>"
    >
    <?php if ($isAdminArea): ?>
    <link
        rel="stylesheet"
        href="<?= BASE_URL ?>/assets/css/admin.css?v=<?= urlencode($styleVersion('admin.css')) ?>"
    >
    <?php endif; ?>
    <?php if (!empty($pageStyles)): ?>

    <?php foreach ($pageStyles as $style): ?>

        <link
            rel="stylesheet"
            href="<?= BASE_URL ?>/assets/css/<?= htmlspecialchars($style) ?>?v=<?= urlencode($styleVersion($style)) ?>"
        >

    <?php endforeach; ?>

<?php endif; ?>
</head>

<body>
