<?php

namespace App\Filament\Resources\TimelineEntries;

use App\Filament\Resources\TimelineEntries\Pages\ManageTimelineEntries;
use App\Models\TimelineEntry;
use BackedEnum;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteAction;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;

class TimelineEntryResource extends Resource
{
    protected static ?string $model = TimelineEntry::class;

    protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedClock;

    protected static ?string $navigationLabel = 'Taryh';

    protected static string|\UnitEnum|null $navigationGroup = 'Sahypa mazmunu';

    protected static ?int $navigationSort = 3;

    public static function form(Schema $schema): Schema
    {
        return $schema
            ->components([
                TextInput::make('year')
                    ->label('Ýyly')
                    ->required()
                    ->numeric()
                    ->minValue(1900)
                    ->maxValue(2100),
                TextInput::make('title')
                    ->label('Başlyk')
                    ->required(),
                Select::make('icon')
                    ->label('Ikony (Material Symbol)')
                    ->required()
                    ->default('history')
                    ->options([
                        'storefront' => 'storefront — Dükançasy',
                        'outdoor_grill' => 'outdoor_grill — Tüsse otagy',
                        'local_shipping' => 'local_shipping — Eltip bermek',
                        'menu_book' => 'menu_book — Resept kitaby',
                        'history' => 'history — Taryh',
                        'star' => 'star — Ýyldyz',
                        'emoji_events' => 'emoji_events — Baýrak',
                        'workspace_premium' => 'workspace_premium — Premium',
                        'factory' => 'factory — Zawod',
                        'engineering' => 'engineering — Inžinerlik',
                        'handyman' => 'handyman — Usta',
                        'lightbulb' => 'lightbulb — Täze pikir',
                    ]),
                TextInput::make('sort_order')
                    ->label('Tertip')
                    ->required()
                    ->numeric()
                    ->default(0),
                Textarea::make('body')
                    ->label('Tekst')
                    ->required()
                    ->rows(3)
                    ->columnSpanFull(),
            ]);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('year')
                    ->label('Ýyly')
                    ->sortable(),
                TextColumn::make('title')
                    ->label('Başlyk')
                    ->searchable(),
                TextColumn::make('icon')
                    ->label('Ikony'),
                TextColumn::make('sort_order')
                    ->label('Tertip')
                    ->numeric()
                    ->sortable(),
                TextColumn::make('created_at')
                    ->dateTime()
                    ->sortable()
                    ->toggleable(isToggledHiddenByDefault: true),
            ])
            ->defaultSort('sort_order')
            ->filters([])
            ->recordActions([
                EditAction::make(),
                DeleteAction::make(),
            ])
            ->toolbarActions([
                BulkActionGroup::make([
                    DeleteBulkAction::make(),
                ]),
            ]);
    }

    public static function getPages(): array
    {
        return [
            'index' => ManageTimelineEntries::route('/'),
        ];
    }
}
