<?php

declare(strict_types=1);

namespace TechnoArtisan\FilamentCms\Filament\Admin\Resources\WebsiteSettings\Schemas;

use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\ToggleButtons;
use Filament\Schemas\Schema;
use TechnoArtisan\FilamentCms\Enums\PhpType;
use TechnoArtisan\FilamentCms\Models\WebsiteSettingGroup;

class WebsiteSettingForm
{
    public static function configure(Schema $schema): Schema
    {
        return $schema
            ->components([
                Select::make('group_id')
                    ->label('Group')
                    ->options(WebsiteSettingGroup::query()->pluck('name', 'id'))
                ,
                TextInput::make('identifier')
                    ->required()
                    ->hint('(only lowercase alphanum & underscores)')
                    ->regex('/^[a-z0-9_]+$/i')
                    ->live(onBlur:true)
                    ->validationMessages([
                        'regex' => 'The :attribute does not match Regex pattern ([a-z0-9_]+).',
                    ])
                ,
                ToggleButtons::make('value_type')
                    ->options(PhpType::class)
                    ->default('string')
                    ->hint('(native PHP types; will be automatically cast to selected value type)')
                    ->inline()
                    ->columnSpanFull(),
                Textarea::make('value')
                    ->default(null)
                    ->columnSpanFull(),
            ]);
    }
}
