<?php

namespace App\Filament\Resources\Groups\Schemas;

use App\Models\Teacher;
use Carbon\Carbon;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Select;
use Filament\Schemas\Components\Utilities\Set;
use Filament\Schemas\Schema;

class GroupForm
{
    public static function configure(Schema $schema): Schema
    {
        return $schema
            ->components([
                DatePicker::make('start_date')
                    ->label('Başlanýan senesi')
                    ->required()
                    ->live()
                    ->afterStateUpdated(fn(Set $set, ?string $state) => $set('end_date', $state ? Carbon::parse($state)->addDays(14)->format('Y-m-d') : null)),

                DatePicker::make('end_date')
                    ->label('Gutarýan senesi')
                    ->required(),

                Select::make('leader_teacher_id')
                    ->label('Topar başy')
                    ->options(Teacher::query()->pluck('name', 'id'))
                    ->searchable()
                    ->required(),

                Select::make('helperTeachers')
                    ->label('Topar kömekçileri')
                    ->relationship('helperTeachers', 'name')
                    ->multiple()
                    ->searchable()
                    ->preload(),
            ]);
    }
}
