<?php

namespace App\Filament\Resources\OrdenProduccionResource\RelationManagers;

use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Forms;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Select;

class OjalesRelationManager extends RelationManager
{
    protected static string $relationship = 'ojales';

    protected static ?string $recordTitleAttribute = 'id';

    public function form(Forms\Form $form): Forms\Form
    {
        return $form->schema([
            Select::make('proveedor_id')->relationship('proveedor', 'nombre', fn(\Illuminate\Database\Eloquent\Builder $q) => $q->where('categoria', 'ojal'))->required(),
            TextInput::make('cantidad_enviada')->numeric()->required()->minValue(1),
            TextInput::make('cantidad_recibida')->numeric()->nullable(),
        ]);
    }

    public function table(Tables\Table $table): Tables\Table
    {
        return $table->columns([
            Tables\Columns\TextColumn::make('id')->label('#'),
            Tables\Columns\TextColumn::make('proveedor.nombre')->label('Proveedor'),
            Tables\Columns\TextColumn::make('cantidad_enviada'),
            Tables\Columns\TextColumn::make('cantidad_recibida'),
            Tables\Columns\TextColumn::make('created_at')->label('Creado')->dateTime(),
        ])->headerActions([
            Tables\Actions\CreateAction::make(),
        ])->actions([
            Tables\Actions\EditAction::make(),
            Tables\Actions\DeleteAction::make(),
        ]);
    }
}
