<?php

declare(strict_types=1);

namespace App\Application\LiveComponents\UserRegistration;

use App\Framework\LiveComponents\FormBuilder\FieldCondition;
use App\Framework\LiveComponents\FormBuilder\FormFieldDefinition;
use App\Framework\LiveComponents\FormBuilder\FormStepDefinition;
use App\Framework\LiveComponents\FormBuilder\MultiStepFormDefinition;

/**
 * User Registration Form Definition
 *
 * Einfaches Beispiel ohne Validators (erst mal)
 */
final readonly class UserRegistrationFormDefinition
{
    public static function create(): MultiStepFormDefinition
    {
        return new MultiStepFormDefinition(
            steps: [
                // Step 1: Personal Information
                new FormStepDefinition(
                    title: 'Persönliche Informationen',
                    description: 'Bitte geben Sie Ihre persönlichen Daten ein',
                    fields: [
                        FormFieldDefinition::text(
                            name: 'first_name',
                            label: 'Vorname',
                            required: true,
                            placeholder: 'Max'
                        ),
                        FormFieldDefinition::text(
                            name: 'last_name',
                            label: 'Nachname',
                            required: true,
                            placeholder: 'Mustermann'
                        ),
                        FormFieldDefinition::email(
                            name: 'email',
                            label: 'E-Mail Adresse',
                            required: true,
                            placeholder: 'max@example.com'
                        ),
                    ]
                ),

                // Step 2: Account Type
                new FormStepDefinition(
                    title: 'Konto-Typ',
                    description: 'Wählen Sie Ihren Konto-Typ',
                    fields: [
                        FormFieldDefinition::radio(
                            name: 'account_type',
                            label: 'Account Type',
                            options: [
                                'personal' => 'Privatkonto',
                                'business' => 'Geschäftskonto',
                            ],
                            required: true,
                            defaultValue: 'personal'
                        ),
                        // Conditional Fields - nur bei Business
                        FormFieldDefinition::text(
                            name: 'company_name',
                            label: 'Firmenname',
                            required: true,
                            placeholder: 'Firma GmbH'
                        )->showWhen(
                            FieldCondition::equals('account_type', 'business')
                        ),
                        FormFieldDefinition::text(
                            name: 'vat_number',
                            label: 'USt-IdNr.',
                            placeholder: 'DE123456789'
                        )->showWhen(
                            FieldCondition::equals('account_type', 'business')
                        ),
                    ]
                ),

                // Step 3: Preferences
                new FormStepDefinition(
                    title: 'Präferenzen',
                    description: 'Passen Sie Ihre Einstellungen an',
                    fields: [
                        FormFieldDefinition::checkbox(
                            name: 'newsletter',
                            label: 'Newsletter abonnieren'
                        ),
                        FormFieldDefinition::select(
                            name: 'language',
                            label: 'Bevorzugte Sprache',
                            options: [
                                'en' => 'English',
                                'de' => 'Deutsch',
                                'fr' => 'Français',
                                'es' => 'Español',
                            ],
                            defaultValue: 'de'
                        ),
                        FormFieldDefinition::select(
                            name: 'timezone',
                            label: 'Zeitzone',
                            options: [
                                'UTC' => 'UTC',
                                'Europe/Berlin' => 'Europe/Berlin',
                                'America/New_York' => 'America/New York',
                                'Asia/Tokyo' => 'Asia/Tokyo',
                            ],
                            defaultValue: 'UTC'
                        ),
                    ]
                ),
            ]
        );
    }
}
