<?php

namespace App\Filament\Resources\BiddersResource\RelationManagers;

use Filament\Forms;
use Filament\Schemas\Schema;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables\Table;
use Filament\Tables;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use App\Models\CarShowCategory;
use Filament\Actions\CreateAction;
use Filament\Actions\EditAction;
use Filament\Actions\DeleteAction;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
use Filament\Tables\Columns\IconColumn;
class VehiclesRelationManager extends RelationManager
{
    protected static string $relationship = 'vehicles';

    protected static ?string $recordTitleAttribute = 'owner';

    public function form(Schema $schema): Schema
    {
        return $schema
            ->components([
                Forms\Components\TextInput::make('year')
                    ->label('Year'),
                Forms\Components\TextInput::make('make')
                    ->label('Make'),
                Forms\Components\TextInput::make('model')
                    ->label('Model'),
                Forms\Components\Select::make('type')
                    ->label('Type')
                    ->options(CarShowCategory::vehtype()->pluck('category_name', 'id'))
                    ->searchable(),
            ]);
    }

    public function table(Table $table): Table
    {
        return $table
            ->columns([
                Tables\Columns\TextColumn::make('vehicleOwner.bidder_assigned_number')
                    ->label('Number')
                    ->sortable(),
                Tables\Columns\TextColumn::make('year')
                    ->label('Year')
                    ->sortable(),
                Tables\Columns\TextColumn::make('make')
                    ->label('Make')
                    ->sortable(),
                Tables\Columns\TextColumn::make('model')
                    ->label('Model')
                    ->sortable(),
                Tables\Columns\TextColumn::make('vehicleType.category_name')
                    ->label('Type')
                    ->sortable(),
                IconColumn::make('doNotJudge')
                    ->boolean()
                    ->label('Judged?')
                    ->sortable()
                    ->falseIcon('heroicon-o-check-badge')
                    ->trueIcon('heroicon-o-x-circle')
                    ->trueColor('danger')
                    ->falseColor('success'),
            ])
            ->filters([
                //
            ])
            ->recordActions([
                EditAction::make(),
                DeleteAction::make(),
            ])
            ->toolbarActions([
                CreateAction::make(),
                BulkActionGroup::make([
                    DeleteBulkAction::make(),
                ]),
            ]);
    }    
}
