<?php

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

use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Table;

class PriceHistoryRelationManager extends RelationManager
{
    protected static string $relationship = 'priceHistory';

    protected static ?string $title = 'Istoric prețuri furnizori';

    public function table(Table $table): Table
    {
        return $table
            ->columns([
                Tables\Columns\TextColumn::make('observed_at')
                    ->label('Data')
                    ->dateTime('d.m.Y H:i')
                    ->sortable(),
                Tables\Columns\TextColumn::make('supplier.name')->label('Furnizor')->searchable(),
                Tables\Columns\TextColumn::make('purchase.number')->label('PO')->placeholder('—'),
                Tables\Columns\TextColumn::make('price')
                    ->money('MDL')
                    ->alignRight()
                    ->sortable(),
                Tables\Columns\TextColumn::make('currency')->label('Val.'),
            ])
            ->defaultSort('observed_at', 'desc')
            ->emptyStateHeading('Niciun preț înregistrat')
            ->emptyStateDescription('Prețurile se înregistrează automat la fiecare recepție de PO.');
    }
}
