<?php
use App\Core\Csrf;

$appName = config('app.name', 'HMH Dashboard');
$hospitals = config('hospitals', []);
$defaultHospitalCode = default_hospital();
$defaultHospital = $hospitals[$defaultHospitalCode] ?? ['name' => 'Jeddah'];
$branchLogoMap = [
    'njch' => 'assets/img/brand/njch.png',
    'jckh' => 'assets/img/brand/jckh.png',
    'mnh' => 'assets/img/brand/mnh.png',
];
$corporateLogo = 'assets/img/brand/logo-half.png';
$defaultLogo = $branchLogoMap[strtolower((string)$defaultHospitalCode)] ?? $corporateLogo;
$lang = current_lang();
$dir = current_dir();
?>
<!doctype html>
<html lang="<?= e($lang) ?>" dir="<?= e($dir) ?>">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title><?= e(t('auth.title')) ?> - <?= e($appName) ?></title>
    <link rel="stylesheet" href="assets/css/app.css?v=phase9-brand-theme">
</head>
<body class="login-body">
    <main class="login-shell executive-login">
        <section class="login-art">
            <div class="login-art-top">
                <a class="brand brand-on-dark" href="<?= e(url_to('login')) ?>">
                    <span class="brand-mark brand-mark-image"><img src="<?= e($corporateLogo) ?>" alt="HMH"></span>
                    <span class="brand-copy">
                        <strong><?= e($appName) ?></strong>
                        <small><?= e(t('app.subtitle')) ?></small>
                    </span>
                </a>
                <a class="language-pill dark" href="<?= e(lang_url(opposite_lang())) ?>">
                    <span><?= e(t('layout.language_code')) ?></span>
                    <b><?= e(t('layout.language')) ?></b>
                </a>
            </div>

            <div class="login-art-copy">
                <div class="login-corporate-logo"><img src="assets/img/brand/hmh-wide.png" alt="<?= e($appName) ?>"></div>
                <span class="overline light"><?= e(t('auth.kicker')) ?></span>
                <h1><?= e(t('auth.hero_title')) ?></h1>
                <p><?= e(t('auth.hero_text')) ?></p>
            </div>

            <div class="login-badges">
                <span><?= e(t('auth.badge1')) ?></span>
                <span><?= e(t('auth.badge2')) ?></span>
                <span><?= e(t('auth.badge3')) ?></span>
            </div>
        </section>

        <section class="login-card glass-login-card">
            <div class="login-title">
                <span class="overline"><?= e(t('auth.kicker')) ?></span>
                <h2><?= e(t('auth.welcome')) ?></h2>
                <p><?= e(t('auth.help')) ?></p>
            </div>

            <?php if (!empty($error)): ?>
                <div class="alert error"><?= e($error) ?></div>
            <?php endif; ?>

            <form method="post" action="<?= e(url_to('login')) ?>" autocomplete="off">
                <?= Csrf::field() ?>
                <input type="hidden" name="lang" value="<?= e(current_lang()) ?>">
                <input type="hidden" name="hospital" value="<?= e($defaultHospitalCode) ?>">

                <div class="login-hospital-logo"><img src="<?= e($defaultLogo) ?>" alt="<?= e($defaultHospital['name'] ?? 'Jeddah') ?>"></div>
                <div class="fixed-branch-note">
                    <span><?= e(t('auth.fixed_branch')) ?></span>
                    <strong><?= e($defaultHospital['name'] ?? 'Jeddah') ?></strong>
                    <small><?= e(t('auth.branch_after_login')) ?></small>
                </div>

                <label>
                    <span><?= e(t('auth.username')) ?></span>
                    <input type="text" name="username" required autofocus placeholder="7124">
                </label>
                <label>
                    <span><?= e(t('auth.password')) ?></span>
                    <input type="password" name="password" required placeholder="••••••••">
                </label>
                <button class="btn primary full" type="submit"><?= e(t('auth.login')) ?></button>
            </form>
            <p class="muted secure-note"><?= e(t('auth.note')) ?></p>
        </section>
    </main>
</body>
</html>
