<?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\Bidders;
use Filament\Actions\EditAction;
use Filament\Actions\CreateAction;
use Filament\Actions\DeleteAction;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;

class WinningBidsRelationManager extends RelationManager
{
    protected static string $relationship = 'winningBids';

    protected static ?string $recordTitleAttribute = 'winning_bidder_num';

    public function form(Schema $schema): Schema
    {
        return $schema
            ->components([
                Forms\Components\Select::make('winning_bidder_num')
                    ->label('Winning Bidder Number')
                    ->options(Bidders::pluck('bidder_assigned_number', 'idbidders'))
                    ->searchable(),
            ]);
    }

    public function table(Table $table): Table
    {
        return $table
            ->columns([
                Tables\Columns\TextColumn::make('items.item_assigned_num')
                    ->label('Item Number')
                    ->sortable(),
                Tables\Columns\TextColumn::make('bidders.winning_bidder_num')
                    ->label('Bidder Number')
                    ->sortable(),
                Tables\Columns\TextColumn::make('winning_cost')
                    ->label('Winning Bid Amt')
                    ->money('USD')
                    ->sortable(),
                
            ])
            ->filters([
                //
            ])
             ->recordActions([
                EditAction::make(),
                DeleteAction::make(),
            ])
            ->toolbarActions([
                CreateAction::make(),
                BulkActionGroup::make([
                    DeleteBulkAction::make(),
                ]),
            ]);
    }    
}
