<?php

namespace App\Filament\Resources\DesignerResource\RelationManagers;

use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Table;

class RidesRelationManager extends RelationManager
{
    protected static string $relationship = 'rides';
    protected static ?string $title = 'Rides';

    public function form(Form $form): Form
    {
        return $form
            ->schema([
                Forms\Components\TextInput::make('name')
                    ->required()
                    ->maxLength(255),
                Forms\Components\TextInput::make('manufacturer_name')
                    ->maxLength(255),
                Forms\Components\TextInput::make('model_name')
                    ->maxLength(255),
                Forms\Components\DatePicker::make('opened_date')
                    ->label('Opening Date'),
                Forms\Components\DatePicker::make('closed_date')
                    ->label('Closing Date')
                    ->after('opened_date'),
                Forms\Components\Textarea::make('description')
                    ->columnSpanFull(),
                Forms\Components\Toggle::make('is_active')
                    ->label('Active')
                    ->default(true),
            ]);
    }

    public function table(Table $table): Table
    {
        return $table
            ->columns([
                Tables\Columns\TextColumn::make('name')
                    ->sortable()
                    ->searchable(),
                Tables\Columns\TextColumn::make('manufacturer_name')
                    ->sortable()
                    ->searchable(),
                Tables\Columns\TextColumn::make('opened_date')
                    ->date()
                    ->sortable(),
                Tables\Columns\TextColumn::make('closed_date')
                    ->date()
                    ->sortable(),
                Tables\Columns\IconColumn::make('is_active')
                    ->boolean()
                    ->sortable(),
            ])
            ->filters([
                Tables\Filters\TrashedFilter::make(),
            ])
            ->headerActions([
                Tables\Actions\CreateAction::make(),
            ])
            ->actions([
                Tables\Actions\EditAction::make(),
                Tables\Actions\DeleteAction::make(),
            ])
            ->bulkActions([
                Tables\Actions\BulkActionGroup::make([
                    Tables\Actions\DeleteBulkAction::make(),
                ]),
            ]);
    }
}