<?php

declare(strict_types=1);

namespace App\Filament\Resources\Users\Schemas;

use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Schema;

class UserForm
{
    public static function configure(Schema $schema): Schema
    {
        return $schema
            ->components([
                TextInput::make('name')
                    ->label(__('admin.fields.display_name'))
                    ->required()
                    ->maxLength(120),
                TextInput::make('username')
                    ->label(__('admin.fields.username'))
                    ->required()
                    ->maxLength(40)
                    ->unique(ignoreRecord: true),
                TextInput::make('email')
                    ->label(__('admin.fields.email'))
                    ->email()
                    ->maxLength(120)
                    ->unique(ignoreRecord: true),
                TextInput::make('url')
                    ->label(__('admin.fields.website'))
                    ->url()
                    ->maxLength(255),
                TextInput::make('password')
                    ->label(__('admin.fields.password'))
                    ->password()
                    ->revealable()
                    ->dehydrated(fn (?string $state): bool => filled($state))
                    ->required(fn (string $operation): bool => $operation === 'create'),
                Select::make('roles')
                    ->label(__('admin.fields.roles'))
                    ->multiple()
                    ->relationship('roles', 'name')
                    ->preload(),
            ]);
    }
}
