<?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('uuid')
                    ->label('UUID')
                    ->required()
                    ->maxLength(36),
                Forms\Components\TextInput::make('pickup_label')
                    ->required()
                    ->maxLength(255),
                Forms\Components\TextInput::make('pickup_lat')
                    ->numeric()
                    ->default(null),
                Forms\Components\TextInput::make('pickup_lng')
                    ->numeric()
                    ->default(null),
                Forms\Components\TextInput::make('destination_label')
                    ->required()
                    ->maxLength(255),
                Forms\Components\TextInput::make('destination_lat')
                    ->numeric()
                    ->default(null),
                Forms\Components\TextInput::make('destination_lng')
                    ->numeric()
                    ->default(null),
                Forms\Components\DateTimePicker::make('scheduled_for'),
                Forms\Components\TextInput::make('status')
                    ->required(),
                Forms\Components\TextInput::make('eta_minutes')
                    ->numeric()
                    ->default(null),
                Forms\Components\TextInput::make('source_channel')
                    ->required(),
                Forms\Components\TextInput::make('context_zone')
                    ->maxLength(255)
                    ->default(null),
                Forms\Components\TextInput::make('locale')
                    ->maxLength(10)
                    ->default(null),
            ]);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                Tables\Columns\TextColumn::make('uuid')
                    ->label('UUID')
                    ->searchable(),
                Tables\Columns\TextColumn::make('pickup_label')
                    ->searchable(),
                Tables\Columns\TextColumn::make('pickup_lat')
                    ->numeric()
                    ->sortable(),
                Tables\Columns\TextColumn::make('pickup_lng')
                    ->numeric()
                    ->sortable(),
                Tables\Columns\TextColumn::make('destination_label')
                    ->searchable(),
                Tables\Columns\TextColumn::make('destination_lat')
                    ->numeric()
                    ->sortable(),
                Tables\Columns\TextColumn::make('destination_lng')
                    ->numeric()
                    ->sortable(),
                Tables\Columns\TextColumn::make('scheduled_for')
                    ->dateTime()
                    ->sortable(),
                Tables\Columns\TextColumn::make('status'),
                Tables\Columns\TextColumn::make('eta_minutes')
                    ->numeric()
                    ->sortable(),
                Tables\Columns\TextColumn::make('source_channel'),
                Tables\Columns\TextColumn::make('context_zone')
                    ->searchable(),
                Tables\Columns\TextColumn::make('locale')
                    ->searchable(),
                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'),
        ];
    }
}
