<?php

namespace App\Filament\Resources\FormQuestionGroups\Schemas;

use App\Enums\FormType;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;

class FormQuestionGroupForm
{
    public static function configure(Schema $schema): Schema
    {
        return $schema
            ->components([
                Section::make('Group Details')
                    ->schema([
                        Select::make('form_type')
                            ->label('Form Type')
                            ->options(collect(FormType::cases())->mapWithKeys(fn ($case) => [$case->value => $case->label()]))
                            ->required()
                            ->native(false),

                        TextInput::make('name')
                            ->label('Group Name')
                            ->required()
                            ->maxLength(255),

                        Select::make('icon')
                            ->label('Icon')
                            ->options([
                                'heroicon-o-user' => 'User',
                                'heroicon-o-users' => 'Users',
                                'heroicon-o-user-group' => 'User Group',
                                'heroicon-o-home' => 'Home',
                                'heroicon-o-building-office' => 'Building Office',
                                'heroicon-o-building-office-2' => 'Building Office 2',
                                'heroicon-o-heart' => 'Heart',
                                'heroicon-o-sparkles' => 'Sparkles',
                                'heroicon-o-star' => 'Star',
                                'heroicon-o-phone' => 'Phone',
                                'heroicon-o-envelope' => 'Envelope',
                                'heroicon-o-map-pin' => 'Map Pin',
                                'heroicon-o-clock' => 'Clock',
                                'heroicon-o-calendar' => 'Calendar',
                                'heroicon-o-currency-dollar' => 'Currency Dollar',
                                'heroicon-o-hand-raised' => 'Hand Raised',
                                'heroicon-o-shield-check' => 'Shield Check',
                                'heroicon-o-key' => 'Key',
                                'heroicon-o-document-text' => 'Document Text',
                                'heroicon-o-clipboard-document-list' => 'Clipboard Document List',
                                'heroicon-o-chat-bubble-left-right' => 'Chat Bubble',
                                'heroicon-o-bell' => 'Bell',
                                'heroicon-o-cog-6-tooth' => 'Cog',
                                'heroicon-o-briefcase' => 'Briefcase',
                                'heroicon-o-academic-cap' => 'Academic Cap',
                                'heroicon-o-truck' => 'Truck',
                                'heroicon-o-shopping-cart' => 'Shopping Cart',
                                'heroicon-o-gift' => 'Gift',
                                'heroicon-o-light-bulb' => 'Light Bulb',
                                'heroicon-o-banknotes' => 'Banknotes',
                                'heroicon-o-chart-bar' => 'Chart Bar',
                                'heroicon-o-cube' => 'Cube',
                                'heroicon-o-globe-alt' => 'Globe',
                                'heroicon-o-flag' => 'Flag',
                                'heroicon-o-bookmark' => 'Bookmark',
                                'heroicon-o-identification' => 'Identification',
                            ])
                            ->searchable()
                            ->allowHtml()
                            ->getSearchResultsUsing(fn (string $search): array => collect([
                                'heroicon-o-user' => 'User',
                                'heroicon-o-users' => 'Users',
                                'heroicon-o-user-group' => 'User Group',
                                'heroicon-o-home' => 'Home',
                                'heroicon-o-building-office' => 'Building Office',
                                'heroicon-o-building-office-2' => 'Building Office 2',
                                'heroicon-o-heart' => 'Heart',
                                'heroicon-o-sparkles' => 'Sparkles',
                                'heroicon-o-star' => 'Star',
                                'heroicon-o-phone' => 'Phone',
                                'heroicon-o-envelope' => 'Envelope',
                                'heroicon-o-map-pin' => 'Map Pin',
                                'heroicon-o-clock' => 'Clock',
                                'heroicon-o-calendar' => 'Calendar',
                                'heroicon-o-currency-dollar' => 'Currency Dollar',
                                'heroicon-o-hand-raised' => 'Hand Raised',
                                'heroicon-o-shield-check' => 'Shield Check',
                                'heroicon-o-key' => 'Key',
                                'heroicon-o-document-text' => 'Document Text',
                                'heroicon-o-clipboard-document-list' => 'Clipboard Document List',
                                'heroicon-o-chat-bubble-left-right' => 'Chat Bubble',
                                'heroicon-o-bell' => 'Bell',
                                'heroicon-o-cog-6-tooth' => 'Cog',
                                'heroicon-o-briefcase' => 'Briefcase',
                                'heroicon-o-academic-cap' => 'Academic Cap',
                                'heroicon-o-truck' => 'Truck',
                                'heroicon-o-shopping-cart' => 'Shopping Cart',
                                'heroicon-o-gift' => 'Gift',
                                'heroicon-o-light-bulb' => 'Light Bulb',
                                'heroicon-o-banknotes' => 'Banknotes',
                                'heroicon-o-chart-bar' => 'Chart Bar',
                                'heroicon-o-cube' => 'Cube',
                                'heroicon-o-globe-alt' => 'Globe',
                                'heroicon-o-flag' => 'Flag',
                                'heroicon-o-bookmark' => 'Bookmark',
                                'heroicon-o-identification' => 'Identification',
                            ])
                                ->filter(fn ($label, $icon) => str_contains(strtolower($label), strtolower($search)) || str_contains(strtolower($icon), strtolower($search)))
                                ->toArray())
                            ->native(false)
                            ->placeholder('Select an icon')
                            ->helperText('Choose an icon to represent this group'),

                        Textarea::make('description')
                            ->label('Description')
                            ->maxLength(1000)
                            ->rows(3),

                        Toggle::make('is_active')
                            ->label('Active')
                            ->default(true),
                    ])
                    ->columns(2)
                    ->columnSpan('full'),
            ]);
    }
}
