<?php

declare(strict_types=1);

namespace App\Filament\Resources\Users\Schemas;

use App\Filament\Support\SelectOptionLabels;
use App\Models\User;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\Toggle;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;

class UserForm
{
    public static function configure(Schema $schema): Schema
    {
        return $schema->components([
            Section::make('اطلاعات کاربر')
                ->schema([
                    \App\Filament\Components\Form\FirstNameTextInput::create()->columnSpan(6),
                    \App\Filament\Components\Form\LastNameTextInput::create()->columnSpan(6),
                    \App\Filament\Components\Form\NameTextInput::create()->columnSpan(6),
                    \App\Filament\Components\Form\NationalCodeTextInput::create()->columnSpan(6),
                    \App\Filament\Components\Form\CellphoneTextInput::create()->columnSpan(6),
                    \App\Filament\Components\Form\EmailTextInput::create()->columnSpan(6),
                    \App\Filament\Components\Form\PhoneTextInput::create()->columnSpan(6),
                    \App\Filament\Components\Form\DobDateTimePicker::create()->columnSpan(6),
                    \App\Filament\Components\Form\GenderSelect::create()->columnSpan(6),
                    \App\Filament\Components\Form\ProvinceSelect::create()->columnSpan(6),
                    \App\Filament\Components\Form\CountySelect::create()->columnSpan(6),
                    \App\Filament\Components\Form\PostalCodeTextInput::create()->columnSpan(6),
                    \App\Filament\Components\Form\AddressTextInput::create()->columnSpan(12),
                    \App\Filament\Components\Form\PasswordTextInput::create()->columnSpan(6),
                    \App\Filament\Components\Form\DescTextarea::create()->columnSpan(12),
                    \App\Filament\Components\Form\AvatarFileUpload::create()->columnSpan(12),
                ])
                ->columns(12)
                ->columnSpan(12),
            Section::make('دسترسی و وضعیت')
                ->schema([
                    Select::make('roles')
                        ->label('نقش‌ها')
                        ->multiple()
                        ->relationship('roles', 'name')
                        ->getOptionLabelFromRecordUsing(fn ($record) => SelectOptionLabels::generic($record, 'name', 'نقش'))
                        ->preload()
                        ->columnSpan(6),
                    Select::make('account_type')
                        ->label('نوع حساب')
                        ->options(User::accountTypeOptions())
                        ->columnSpan(6),
                    Select::make('status')
                        ->label('وضعیت')
                        ->options([1 => 'فعال', 0 => 'غیرفعال'])
                        ->default(1)
                        ->columnSpan(4),
                    Toggle::make('is_blocked')->label('مسدود')->columnSpan(4),
                    \App\Filament\Components\Form\LoginTypeSelect::create()->columnSpan(4),
                    Textarea::make('blocked_reason')->label('دلیل مسدودی')->rows(2)->columnSpan(12),
                    \App\Filament\Components\Form\BaseCreditTextInput::create()->required()->columnSpan(4),
                    \App\Filament\Components\Form\EmailVerifiedAtDateTimePicker::create()->columnSpan(4),
                    \App\Filament\Components\Form\LastOnlineAtDateTimePicker::create()->columnSpan(4),
                    \App\Filament\Components\Form\AvatarVerifiedAtDateTimePicker::create()->columnSpan(6),
                ])
                ->columns(12)
                ->columnSpan(12),
        ])
            ->columns(12);
    }
}
