<?php

namespace App\Filament\Resources\DeliveryCalendarOverrides\Schemas;

use App\Enums\OverrideScope;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Schemas\Components\Utilities\Get;
use Filament\Schemas\Schema;

class DeliveryCalendarOverrideForm
{
    public static function configure(Schema $schema): Schema
    {
        return $schema
            ->components([
                Select::make('supplier_id')
                    ->label('Beszállító')
                    ->relationship('supplier', 'name')
                    ->searchable()
                    ->required(),
                Select::make('override_scope')
                    ->label('Felülbírálás szintje')
                    ->options(collect(OverrideScope::cases())->mapWithKeys(
                        fn(OverrideScope $scope) => [$scope->value => $scope->label()]
                    ))
                    ->default(OverrideScope::General->value)
                    ->required()
                    ->live(),
                Select::make('delivery_schedule_id')
                    ->label('Szállítási sablon')
                    ->relationship('deliverySchedule', 'name')
                    ->searchable()
                    ->visible(fn(Get $get) => $get('override_scope') === OverrideScope::Region->value)
                    ->required(fn(Get $get) => $get('override_scope') === OverrideScope::Region->value),
                Select::make('profit_center_id')
                    ->label('Profitcenter')
                    ->relationship('profitCenter', 'name')
                    ->searchable()
                    ->visible(fn(Get $get) => $get('override_scope') === OverrideScope::ProfitCenter->value)
                    ->required(fn(Get $get) => $get('override_scope') === OverrideScope::ProfitCenter->value),
                DatePicker::make('date')
                    ->label('Dátum')
                    ->required()
                    ->native(false)
                    ->displayFormat('Y-m-d'),
                Toggle::make('is_delivery_day')
                    ->label('Szállítási nap?')
                    ->default(true),
                TextInput::make('description')
                    ->label('Indoklás / Megjegyzés')
                    ->maxLength(255),
            ]);
    }
}
