{{--
    Protera register override (`auth::auth.register` — ThemeManager prepends this
    theme's Resources/views/auth/ into the `auth` namespace, so this file wins over
    the package's own screen wherever Protera is the active web theme).

    SystemFindings/task-18 — finding #22. Until this task every user-visible string
    below was a Lithuanian literal in the markup: fifteen of them, on the public
    registration page, with `__()` never called once. `/en/register` and
    `/pl/register` returned 200 with a Lithuanian form — the quietest shape a
    multilingual defect can take, because the URL, the locale switcher and the
    status code are all correct.

    🔑 AND task-3'S SCANNER COULD NOT SEE IT. `TranslationKeysAreSemanticTest`
    inspects `__()` ARGUMENTS for LT text used as a key; here there was no `__()`
    to inspect. Finding #5's third shape needed a text-node scanner, which is what
    `RegisterScreenIsSelfContainedTest::hardcodedText()` is.

    Two LT strings CHANGED rather than moved, deliberately (task-18 §Constraint 1,
    option (a) — this screen and the base `auth::auth.register` must say the same
    thing, and two keys that differ only because two people typed them separately
    are two keys nobody keeps in sync):
      - the <title> was "Registracija", now `register_title` = "Sukurti paskyrą",
        matching the <h1> it sits above;
      - "Pakartokite slaptažodį" is now `confirm_password` = "Patvirtinkite
        slaptažodį", the label the reset-password screen has always used.

    Field names are NOT touched. `RegisterScreenIsSelfContainedTest` derives them
    from `RegisterController::validator()` by reflection and asserts this file
    carries every one — drop `terms` and registration becomes impossible while the
    GET stays a clean 200.
--}}
@extends('theme::layouts.auth')

@section('title', __('auth::messages.register_title'))

@section('content')
@php
    /*
     | The two legal documents the terms checkbox points at.
     |
     | LegalPageLinks resolves the CURRENT locale's URL from the default-locale
     | slug and returns null when the page is missing, unpublished or untranslated
     | — the hardcoded `/privatumo-politika` these replace was a Lithuanian path
     | served to every locale, and a 404 waiting for any install that never seeded
     | the row. `public-page-recipe` §7: guard the link, never emit a dead one.
     |
     | Null degrades to plain text, so the sentence still reads correctly and the
     | checkbox still works; only the link is lost.
     */
    $privacyUrl = \ViartasThemes\Protera\Support\LegalPageLinks::url('privatumo-politika');
    $termsUrl = \ViartasThemes\Protera\Support\LegalPageLinks::url('pirkimo-salygos');

    $legalLink = static function (?string $url, string $label): string {
        $label = e($label);

        return $url === null
            ? $label
            : '<a href="'.e($url).'" target="_blank" rel="noopener" class="terms-link">'.$label.'</a>';
    };
@endphp
<h1>{{ __('auth::messages.register_title') }}</h1>
<p class="subtitle">{{ __('auth::messages.register_subtitle') }}</p>

<form method="POST" action="{{ route(cms_route_name_for_current_locale(cms_current_environment() . '.auth.register.store')) }}" id="registerForm" novalidate>
    @csrf

    <div class="mb-3">
        <label for="name" class="form-label">{{ __('auth::messages.name') }}</label>
        <input type="text" id="name" name="name" value="{{ old('name') }}"
               class="form-control @error('name') is-invalid @enderror"
               required autocomplete="name" autofocus>
        @error('name')
            <div class="invalid-feedback d-block">{{ $message }}</div>
        @enderror
    </div>

    <div class="mb-3">
        <label for="email" class="form-label">{{ __('auth::messages.email') }}</label>
        <input type="email" id="email" name="email" value="{{ old('email') }}"
               class="form-control @error('email') is-invalid @enderror"
               required autocomplete="email">
        @error('email')
            <div class="invalid-feedback d-block">{{ $message }}</div>
        @enderror
    </div>

    <div class="mb-3">
        <label for="password" class="form-label">{{ __('auth::messages.password') }}</label>
        <input type="password" id="password" name="password"
               class="form-control @error('password') is-invalid @enderror"
               required autocomplete="new-password" minlength="8">
        {{-- task-18: the inline style moved to this theme's auth.css
             (.auth-card .form-text), which already loads on `web.*auth.*`. --}}
        <div class="form-text">
            {{ __('auth::messages.password_hint') }}
        </div>
        @error('password')
            <div class="invalid-feedback d-block">{{ $message }}</div>
        @enderror
    </div>

    <div class="mb-3">
        <label for="password_confirmation" class="form-label">{{ __('auth::messages.confirm_password') }}</label>
        <input type="password" id="password_confirmation" name="password_confirmation"
               class="form-control"
               required autocomplete="new-password">
    </div>

    {{-- Agreement to terms — required by RegisterController::validator().

         ONE key with :privacy / :terms placeholders, not three strings glued
         together: LT declines both nouns after "su", EN needs an article and PL a
         different conjunction, and a sentence assembled from fragments in the
         blade cannot express word order at all. --}}
    <div class="form-check mb-3">
        <input type="checkbox" id="terms" name="terms" class="form-check-input @error('terms') is-invalid @enderror" required>
        <label for="terms" class="form-check-label">
            {!! __('auth::messages.terms_accept_linked', [
                'privacy' => $legalLink($privacyUrl, __('auth::messages.terms_privacy')),
                'terms' => $legalLink($termsUrl, __('auth::messages.terms_conditions')),
            ]) !!}
        </label>
        @error('terms')
            <div class="invalid-feedback d-block">{{ $message }}</div>
        @enderror
    </div>

    <button type="submit" class="btn-brand">{{ __('auth::messages.register') }}</button>
</form>

<div class="divider"></div>

<div class="meta-link">
    {{ __('auth::messages.have_account') }}
    <a href="{{ route(cms_route_name_for_current_locale(cms_current_environment() . '.auth.login')) }}">
        {{ __('auth::messages.sign_in') }}
    </a>
</div>
@endsection
