<?php

namespace App\Filament\Resources\Galleries\Schemas;

use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Components\View;
use Filament\Schemas\Schema;
use Illuminate\Support\Facades\URL;

class GalleryForm
{
    public static function configure(Schema $schema): Schema
    {
        return $schema
            ->components([
                Section::make('Details')
                    ->columns(2)
                    ->schema([
                        TextInput::make('name')
                            ->label('Name')
                            ->required(),
                        TextInput::make('slug')
                            ->label('Slug')
                            ->disabled()
                            ->dehydrated(true)
                            ->helperText('Wird automatisch erzeugt'),
                        TextInput::make('title')
                            ->label('Titel')
                            ->required(),
                        TextInput::make('images_path')
                            ->label('Bilder-Pfad')
                            ->helperText('Relativer Pfad unter public/storage')
                            ->required(),
                        Toggle::make('is_public')
                            ->label('Öffentlich')
                            ->default(true),
                        Toggle::make('allow_ai_styles')
                            ->label('AI-Stile erlauben')
                            ->default(true),
                        Toggle::make('allow_print')
                            ->label('Drucken erlauben')
                            ->default(true),
                        Toggle::make('require_password')
                            ->label('Passwortschutz aktiv')
                            ->default(false),
                        TextInput::make('password')
                            ->label('Neues Passwort')
                            ->password()
                            ->revealable()
                            ->dehydrated(false)
                            ->helperText('Leer lassen, um das bestehende Passwort zu behalten.'),
                        DateTimePicker::make('expires_at')
                            ->label('Ablaufdatum')
                            ->native(false)
                            ->seconds(false),
                        TextInput::make('access_duration_minutes')
                            ->label('Zugriffsdauer (Minuten)')
                            ->numeric()
                            ->minValue(1)
                            ->nullable()
                            ->helperText('Optional: Zeitfenster nach dem ersten Unlock.'),
                    ]),
                View::make('filament.components.gallery-link')
                    ->columnSpanFull()
                    ->visible(fn (?object $record) => (bool) $record?->id)
                    ->viewData(fn (?object $record) => [
                        'url' => $record ? URL::route('gallery.show', $record) : null,
                    ]),
            ]);
    }
}
