<?php

declare(strict_types=1);

namespace PpPhp\Core\Designer\Templates;

use PpPhp\Core\Designer\DesignerComponent as C;
use PpPhp\Core\Designer\DesignerTemplate;

/**
 * Forgot-password page templates. Reached from the login page's
 * "Forgot password?" link, so it reuses the same visual shells as
 * login / register / reset-password — the recovery journey stays on-brand.
 */
final class ForgotPasswordPageTemplate extends DesignerTemplate
{
    private const VARIANTS = ['liquid', 'flat', 'aurora', 'halo', 'executive', 'verdant'];

    public function toArray(): array
    {
        $variant = strtolower((string) ($this->options['variant'] ?? 'liquid'));
        if (!in_array($variant, self::VARIANTS, true)) {
            $variant = 'liquid';
        }

        $props = $this->applyBrand(array_replace($this->baseProps(), $this->variantProps($variant)));
        $page = $this->basePage($props['title'], [
            C::make('forgot_password_auth_form', 'auth_form', 'Forgot Password Experience', $props, [], [], [
                'onLoad' => 'forgot_password:load',
                'server' => 'forgot_password:request',
                'context' => 'global',
            ], [], [
                'designerRuntime' => 'auth',
                'template' => $variant,
            ]),
        ]);

        $page['pageType'] = 'forgot_password';
        $page['table'] = '';
        $page['layout'] = ['device' => 'desktop', 'width' => 'fluid', 'theme' => 'simple', 'align' => 'center'];
        $page['settings']['forgotPasswordTemplate'] = $variant;

        return $page;
    }

    private function baseProps(): array
    {
        return [
            'pageType' => 'forgot_password',
            'template' => 'aurora',
            'brandName' => 'PPPHP',
            'brandMark' => 'P',
            'brandTagline' => 'Applications, beautifully built.',
            'title' => 'Forgot your password?',
            'subtitle' => 'No worries — it happens. We will email you a reset link.',
            'emailLabel' => 'Account email',
            'emailPlaceholder' => 'you@example.com',
            'helpText' => 'Enter the email you signed up with. The reset link stays valid for one hour.',
            'submitLabel' => 'Send reset link',
            'signupText' => 'Remembered it?',
            'signupLabel' => 'Back to sign in',
            'socialProviders' => [],
            'showSignup' => true,
            'showSecurityNote' => true,
            'securityNote' => 'For your safety we never reveal whether an email is registered',
            'showcaseEyebrow' => 'ACCOUNT RECOVERY',
            'showcaseTitle' => 'Locked out? Back in a minute.',
            'showcaseText' => 'A quick email is all it takes to get back to your workspace.',
            'testimonial' => '',
            'quoteAuthor' => '',
            'accentColor' => '#6d5dfc',
            'backgroundColor' => '#f4f7fb',
            'fields' => [
                ['name' => 'email', 'type' => 'email', 'label' => 'Account email', 'required' => true],
            ],
            'actions' => [
                ['id' => 'request', 'label' => 'Send reset link', 'variant' => 'primary'],
            ],
            'links' => [
                ['label' => 'Back to sign in', 'target' => 'login'],
            ],
            'security' => ['csrf' => true, 'rateLimit' => true, 'guestOnly' => true, 'authRequired' => false],
        ];
    }

    private function variantProps(string $variant): array
    {
        return match ($variant) {
            'halo' => [
                'template' => 'halo',
                'brandName' => 'PPPHP',
                'brandMark' => 'P',
                'brandTagline' => 'Ideas become outcomes.',
                'title' => 'Reset your access',
                'securityNote' => 'Private by design · SOC 2 ready',
                'showcaseEyebrow' => 'WELCOME BACK',
                'showcaseTitle' => 'Focus on the work that matters.',
                'showcaseText' => 'A thoughtfully designed workspace for ambitious teams.',
                'accentColor' => '#7c3aed',
                'backgroundColor' => '#100b2d',
            ],
            'executive' => [
                'template' => 'executive',
                'brandName' => 'PPPHP',
                'brandMark' => 'P',
                'brandTagline' => 'Operations, made clear.',
                'title' => 'Recover your account',
                'subtitle' => 'We will send a secure reset link to your work email.',
                'securityNote' => 'Secure SSO · SAML · Audit logging',
                'showcaseEyebrow' => 'TRUSTED OPERATIONS',
                'showcaseTitle' => 'Decisions move faster when the picture is clear.',
                'showcaseText' => 'A secure command center for teams that run critical operations.',
                'accentColor' => '#0f766e',
                'backgroundColor' => '#eef3f1',
            ],
            'verdant' => [
                'template' => 'verdant',
                'brandName' => 'PPPHP',
                'brandMark' => 'P',
                'brandTagline' => 'A clearer path forward.',
                'title' => 'Recover your account',
                'subtitle' => 'Enter your email and we will send a secure reset link.',
                'submitLabel' => 'Send reset link',
                'securityNote' => 'Private and protected',
                'showcaseEyebrow' => '',
                'showcaseTitle' => '',
                'showcaseText' => '',
                'accentColor' => '#38c96b',
                'backgroundColor' => '#6d9078',
            ],
            'liquid' => [
                'template' => 'liquid',
                'accentColor' => '#6366f1',
                'backgroundColor' => '#eceef6',
            ],
            'flat' => [
                'template' => 'flat',
                'accentColor' => '#2563eb',
                'backgroundColor' => '#fafafa',
            ],
            default => [],
        };
    }
}
