<?php

namespace App\Filament\Resources;

use App\Filament\Resources\RideResource\Pages;
use App\Filament\Resources\RideResource\RelationManagers;
use App\Models\Ride;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;

class RideResource extends Resource
{
    protected static ?string $model = Ride::class;

    protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Forms\Components\TextInput::make('name')
                    ->required()
                    ->maxLength(255),
                Forms\Components\TextInput::make('slug')
                    ->required()
                    ->maxLength(255),
                Forms\Components\Textarea::make('description')
                    ->required()
                    ->columnSpanFull(),
                Forms\Components\Select::make('park_id')
                    ->relationship('park', 'name')
                    ->required(),
                Forms\Components\Select::make('park_area_id')
                    ->relationship('parkArea', 'name'),
                Forms\Components\Select::make('manufacturer_id')
                    ->relationship('manufacturer', 'name'),
                Forms\Components\Select::make('designer_id')
                    ->relationship('designer', 'name'),
                Forms\Components\Select::make('ride_model_id')
                    ->relationship('rideModel', 'name'),
                Forms\Components\TextInput::make('category')
                    ->required()
                    ->maxLength(2)
                    ->default(''),
                Forms\Components\TextInput::make('status')
                    ->required()
                    ->maxLength(20)
                    ->default('OPERATING'),
                Forms\Components\TextInput::make('post_closing_status')
                    ->maxLength(20),
                Forms\Components\DatePicker::make('opening_date'),
                Forms\Components\DatePicker::make('closing_date'),
                Forms\Components\DatePicker::make('status_since'),
                Forms\Components\TextInput::make('min_height_in')
                    ->numeric(),
                Forms\Components\TextInput::make('max_height_in')
                    ->numeric(),
                Forms\Components\TextInput::make('capacity_per_hour')
                    ->numeric(),
                Forms\Components\TextInput::make('ride_duration_seconds')
                    ->numeric(),
                Forms\Components\TextInput::make('average_rating')
                    ->numeric(),
            ]);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                Tables\Columns\TextColumn::make('name')
                    ->searchable(),
                Tables\Columns\TextColumn::make('slug')
                    ->searchable(),
                Tables\Columns\TextColumn::make('park.name')
                    ->numeric()
                    ->sortable(),
                Tables\Columns\TextColumn::make('parkArea.name')
                    ->numeric()
                    ->sortable(),
                Tables\Columns\TextColumn::make('manufacturer.name')
                    ->numeric()
                    ->sortable(),
                Tables\Columns\TextColumn::make('designer.name')
                    ->numeric()
                    ->sortable(),
                Tables\Columns\TextColumn::make('rideModel.name')
                    ->numeric()
                    ->sortable(),
                Tables\Columns\TextColumn::make('category')
                    ->searchable(),
                Tables\Columns\TextColumn::make('status')
                    ->searchable(),
                Tables\Columns\TextColumn::make('post_closing_status')
                    ->searchable(),
                Tables\Columns\TextColumn::make('opening_date')
                    ->date()
                    ->sortable(),
                Tables\Columns\TextColumn::make('closing_date')
                    ->date()
                    ->sortable(),
                Tables\Columns\TextColumn::make('status_since')
                    ->date()
                    ->sortable(),
                Tables\Columns\TextColumn::make('min_height_in')
                    ->numeric()
                    ->sortable(),
                Tables\Columns\TextColumn::make('max_height_in')
                    ->numeric()
                    ->sortable(),
                Tables\Columns\TextColumn::make('capacity_per_hour')
                    ->numeric()
                    ->sortable(),
                Tables\Columns\TextColumn::make('ride_duration_seconds')
                    ->numeric()
                    ->sortable(),
                Tables\Columns\TextColumn::make('average_rating')
                    ->numeric()
                    ->sortable(),
                Tables\Columns\TextColumn::make('created_at')
                    ->dateTime()
                    ->sortable()
                    ->toggleable(isToggledHiddenByDefault: true),
                Tables\Columns\TextColumn::make('updated_at')
                    ->dateTime()
                    ->sortable()
                    ->toggleable(isToggledHiddenByDefault: true),
            ])
            ->filters([
                //
            ])
            ->actions([
                Tables\Actions\EditAction::make(),
            ])
            ->bulkActions([
                Tables\Actions\BulkActionGroup::make([
                    Tables\Actions\DeleteBulkAction::make(),
                ]),
            ]);
    }

    public static function getRelations(): array
    {
        return [
            //
        ];
    }

    public static function getPages(): array
    {
        return [
            'index' => Pages\ListRides::route('/'),
            'create' => Pages\CreateRide::route('/create'),
            'edit' => Pages\EditRide::route('/{record}/edit'),
        ];
    }
}
