<?php

namespace App\Filament\Resources\Employees\Schemas;

use App\Enums\EmploymentStatus;
use App\Enums\Gender;
use Filament\Forms\Components\TextInput;
use Filament\Support\RawJs;
use App\Filament\Support\HrForm;
use App\Support\Countries;use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Schemas\Components\Tabs;
use Filament\Schemas\Components\Tabs\Tab;
use Filament\Schemas\Schema;

class EmployeeForm
{
    public static function configure(Schema $schema): Schema
    {
        return $schema
            ->components([
                Tabs::make(__('hr.tabs.employee'))
                    ->tabs([
                        Tab::make(__('hr.tabs.personal'))
                            ->schema([
                                HrForm::fileUpload('profile_photo_path')
                                    ->label(__('hr.fields.photo'))
                                    ->image()
                                    ->avatar()
                                    ->imageEditor(),
                                TextInput::make('employee_number')
                                    ->label(__('hr.fields.employee_number'))
                                    ->disabled()
                                    ->dehydrated(false)
                                    ->visibleOn('edit'),
                                TextInput::make('full_name')
                                    ->label(__('hr.fields.full_name'))
                                    ->required()
                                    ->maxLength(255),
                                Select::make('national_id')
                                    ->label(__('hr.fields.national_id'))
                                    ->options(fn (): array => Countries::options())
                                    ->searchable()
                                    ->native(false)
                                    ->default(Countries::default())
                                    ->required(),

                                Select::make('gender')
                                    ->label(__('hr.fields.gender'))
                                    ->options(Gender::class)
                                    ->required()
                                    ->native(false),
                                    
                                DatePicker::make('birth_date')
                                    ->label(__('hr.fields.birth_date'))
                                    ->required()
                                    ->native(false),

                                TextInput::make('phone')
                                    ->label(__('hr.fields.phone'))
                                    ->prefix('+993')
                                    ->mask(RawJs::make(<<<'JS'
                                        '99 99-99-99'
                                    JS))
                                    ->required(),

                                Textarea::make('address')
                                    ->label(__('hr.fields.address'))
                                    ->rows(3)
                                    ->columnSpanFull(),
                            ])
                            ->columns(2),
                        Tab::make(__('hr.tabs.employment'))
                            ->schema([
                                Select::make('department_id')
                                    ->label(__('hr.fields.department'))
                                    ->relationship('department', 'name')
                                    ->searchable()
                                    ->preload()
                                    ->required(),
                                Select::make('position_id')
                                    ->label(__('hr.fields.position'))
                                    ->relationship('position', 'name')
                                    ->searchable()
                                    ->preload()
                                    ->required(),
                                Select::make('shift_id')
                                    ->label(__('hr.fields.shift'))
                                    ->relationship('shift', 'name')
                                    ->searchable()
                                    ->preload()
                                    ->required(),
                                Select::make('employment_status')
                                    ->label(__('hr.fields.employment_status'))
                                    ->options(EmploymentStatus::class)
                                    ->default(EmploymentStatus::Active)
                                    ->required()
                                    ->native(false),
                                DatePicker::make('hire_date')
                                    ->label(__('hr.fields.hire_date'))
                                    ->required()
                                    ->native(false),

                                DatePicker::make('termination_date')
                                    ->label(__('hr.fields.termination_date'))
                                    ->native(false),

                                Textarea::make('notes')
                                    ->label(__('hr.fields.notes'))
                                    ->rows(4)
                                    ->columnSpanFull(),
                            ])
                            ->columns(2),
                    ])
                    ->columnSpanFull(),
            ]);
    }
}
