<?php
/// file: app/Components/home-hero-locale-toggle.php

declare(strict_types=1);

$cur = \App\Core\Session::get('locale') ?? 'en';
if (! is_string($cur) || ! in_array($cur, ['en', 'tr'], true)) {
    $cur = 'en';
}
$redirect = $_SERVER['REQUEST_URI'] ?? '/';
if (! is_string($redirect) || ! str_starts_with($redirect, '/')) {
    $redirect = '/';
}
?>
<form
    method="post"
    action="<?= e(url('/locale')) ?>"
    class="home-hero-locale font-hero relative z-[2] shrink-0"
    aria-label="<?= e(__('locale.group_aria')) ?>"
>
    <?= \App\Core\Csrf::field() ?>
    <input type="hidden" name="redirect" value="<?= e($redirect) ?>">
    <div class="home-hero-locale__shell flex overflow-hidden rounded-full" role="group">
        <button
            type="submit"
            name="locale"
            value="en"
            class="home-hero-locale__btn<?= $cur === 'en' ? ' home-hero-locale__btn--active' : '' ?>"
            <?= $cur === 'en' ? 'aria-current="true"' : '' ?>
            aria-label="<?= e(__('locale.use_en')) ?>"
        >EN</button>
        <span class="home-hero-locale__divider" aria-hidden="true"></span>
        <button
            type="submit"
            name="locale"
            value="tr"
            class="home-hero-locale__btn<?= $cur === 'tr' ? ' home-hero-locale__btn--active' : '' ?>"
            <?= $cur === 'tr' ? 'aria-current="true"' : '' ?>
            aria-label="<?= e(__('locale.use_tr')) ?>"
        >TR</button>
    </div>
</form>
