<?php

namespace App\Filament\Resources\VehiclesResource\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\Bidders;
use Filament\Actions\CreateAction;
use Filament\Actions\EditAction;
use Filament\Actions\DeleteAction;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
class VehicleOwnerRelationManager extends RelationManager
{
    protected static string $relationship = 'vehicleOwner';

    protected static ?string $recordTitleAttribute = 'owner';

    public function form(Schema $schema): Schema
    {
        return $schema
            ->components([
                Forms\Components\Select::make('owner')
                    ->label('Owner Assigned Number')
                    ->required()
                    ->searchable()
                    ->options(
                        Bidders::orderBy('bidder_assigned_number')
                        ->pluck('bidder_assigned_number', 'idbidders'
                    ))
                    ->createOptionForm([
                        Forms\Components\TextInput::make('bidder_fname')->label('First Name'),
                        Forms\Components\TextInput::make('bidder_lname')->label('Last Name'),
                        Forms\Components\TextInput::make('bidder_addr')->label('Address'),
                        Forms\Components\TextInput::make('bidder_city')->label('City'),
                        Forms\Components\TextInput::make('bidder_state')->label('State'),
                        Forms\Components\TextInput::make('bidder_zip')->label('Zip'),
                        Forms\Components\TextInput::make('bidder_phone')->label('Phone Number'),
                        Forms\Components\TextInput::make('bidder_email')->label('Email'),
                        Forms\Components\TextInput::make('bidder_assigned_number')->label('Assigned Number'),
                ]),
            ]);
    }

    public function table(Table $table): Table
    {
        return $table
            ->columns([
                Tables\Columns\TextColumn::make('bidder_fname')->label('First Name'),
                Tables\Columns\TextColumn::make('bidder_lname')->label('Last Name'),
                Tables\Columns\TextColumn::make('bidder_assigned_number')->label('Number'),
            ])
            ->filters([
                //
            ])
            ->recordActions([
                EditAction::make(),
                DeleteAction::make(),
            ])
            ->toolbarActions([
                CreateAction::make(),
                BulkActionGroup::make([
                    DeleteBulkAction::make(),
                ]),
            ]);
    }    
}
