<?php

namespace App\Filament\Resources;

use App\Filament\Resources\PeoplesChoiceResource\Pages;
use App\Filament\Resources\PeoplesChoiceResource\RelationManagers;
use App\Models\PeoplesChoice;
use UnitEnum;
use BackedEnum;
use Filament\Schemas\Schema;
use Filament\Resources\Resource;
use Filament\Tables\Table;
use Filament\Tables;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Tables\Columns\TextColumn;
use Filament\Forms\Components\TextInput;
use App\Models\Vehicles;
use Filament\Forms\Components\Select;
use Filament\Actions\EditAction;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;

class PeoplesChoiceResource extends Resource
{
    protected static ?string $model = PeoplesChoice::class;

    protected static ?string $pluralModelLabel = 'Peoples Choice';

    protected static string | BackedEnum | null $navigationIcon = 'heroicon-o-rectangle-stack';

    protected static string | UnitEnum | null $navigationGroup = 'Car Show';

    public static function form(Schema $schema): Schema
    {
        return $schema
            ->components([
                Select::make('vehicle')
                ->label('Vehicle')
                ->options(Vehicles::all()->pluck('owner', 'id'))
                ->searchable(),
                TextInput::make('pc_count'),
            ]);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('pc_count')->label('PC Vote Count')->sortable(),
                TextColumn::make('vehicles.owner')->label('Vehicle Number')->sortable(),
                TextColumn::make('vehicles.year')->label('Year')->sortable(),
                TextColumn::make('vehicles.make')->label('Make')->sortable(),
                TextColumn::make('vehicles.model')->label('Model')->sortable(),
            ])
            ->filters([
                //
            ])
            ->recordActions([
                EditAction::make(),
            ])
            ->toolbarActions([
                BulkActionGroup::make([
                    DeleteBulkAction::make(),
                ]),
            ]);
    }
    
    public static function getRelations(): array
    {
        return [
            //
        ];
    }
    
    public static function getPages(): array
    {
        return [
            'index' => Pages\ListPeoplesChoices::route('/'),
            'create' => Pages\CreatePeoplesChoice::route('/create'),
            'edit' => Pages\EditPeoplesChoice::route('/{record}/edit'),
        ];
    }    
}
