<?php

namespace App\Filament\Tenant\Resources\PartResource\RelationManagers;

use Filament\Actions;
use Filament\Forms;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Schemas\Schema;
use Filament\Tables;
use Filament\Tables\Table;

class CrossRefsRelationManager extends RelationManager
{
    protected static string $relationship = 'crossRefs';

    protected static ?string $title = 'Coduri cross (OEM/echivalente)';

    public function form(Schema $schema): Schema
    {
        return $schema->components([
            Forms\Components\TextInput::make('cross_article')->label('Cod echivalent')->required()->maxLength(64),
            Forms\Components\TextInput::make('brand')->label('Brand')->maxLength(64),
        ]);
    }

    public function table(Table $table): Table
    {
        return $table
            ->recordTitleAttribute('cross_article')
            ->columns([
                Tables\Columns\TextColumn::make('cross_article')->label('Cod')->searchable(),
                Tables\Columns\TextColumn::make('brand')->placeholder('—'),
            ])
            ->headerActions([Actions\CreateAction::make()])
            ->actions([Actions\EditAction::make(), Actions\DeleteAction::make()])
            ->emptyStateHeading('Niciun cod cross')
            ->emptyStateDescription('Adaugă coduri echivalente OEM/aftermarket ca să fie găsite în căutarea din magazin.');
    }
}
