<?php

declare(strict_types=1);

/**
 * Login view — email + password form for Karvi Partner API.
 *
 * @var string $error
 * @var string $action
 */

require_once dirname(__DIR__, 2) . '/includes/layout.php';

render_header('title_sign_in', ['layout' => 'auth', 'nav' => false]);
?>

<div class="w-full max-w-md animate-fade-in">
    <div class="mb-8">
        <h2 class="font-display font-bold text-2xl sm:text-3xl text-karvi-950 tracking-tight"><?= e(__('welcome_back')) ?></h2>
        <p class="text-karvi-500 mt-2 text-sm"><?= e(__('sign_in_subtitle')) ?></p>
    </div>

    <?php if (!empty($error)): ?>
    <div class="alert-error mb-6">
        <span class="material-symbols-rounded text-karvi-950">lock</span>
        <span><?= e($error) ?></span>
    </div>
    <?php endif; ?>

    <form method="POST" action="<?= e($action) ?>" class="space-y-5" autocomplete="on">
        <div class="form-group">
            <label class="form-label" for="email"><?= e(__('admin_id')) ?></label>
            <div class="form-input-icon-wrap">
                <span class="material-symbols-rounded input-icon">person</span>
                <input
                    type="text"
                    id="email"
                    name="email"
                    class="form-input"
                    placeholder="<?= e(__('admin_id_placeholder')) ?>"
                    required
                    autocomplete="username"
                    value="<?= e((string)($_POST['email'] ?? '')) ?>"
                >
            </div>
        </div>
        <div class="form-group">
            <label class="form-label" for="password"><?= e(__('password')) ?></label>
            <div class="form-input-icon-wrap">
                <span class="material-symbols-rounded input-icon">key</span>
                <input
                    type="password"
                    id="password"
                    name="password"
                    class="form-input"
                    placeholder="<?= e(__('password_placeholder')) ?>"
                    required
                    autocomplete="current-password"
                >
            </div>
        </div>
        <button type="submit" class="btn-primary w-full !py-3.5 mt-2">
            <span class="material-symbols-rounded">login</span>
            <?= e(__('sign_in')) ?>
        </button>
    </form>

    <p class="text-center text-xs text-karvi-400 mt-8"><?= e(__('secure_access_note')) ?></p>
</div>

<?php render_footer(['layout' => 'auth']); ?>
