<?php

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

use App\Models\Tenant\TireStorage;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Table;

class StorageRelationManager extends RelationManager
{
    protected static string $relationship = 'storage';

    protected static ?string $title = null;

    public static function getTitle(\Illuminate\Database\Eloquent\Model $ownerRecord, string $pageClass): string
    {
        return __('Istoric depozitare');
    }

    public function table(Table $table): Table
    {
        return $table
            ->columns([
                Tables\Columns\TextColumn::make('season_label')->label(__('Perioadă'))->placeholder('—'),
                Tables\Columns\TextColumn::make('location')->label(__('Locație'))->placeholder('—'),
                Tables\Columns\TextColumn::make('checked_in_at')->label(__('Primit'))->dateTime('d.m.Y'),
                Tables\Columns\TextColumn::make('checked_out_at')->label(__('Ridicat'))->dateTime('d.m.Y')->placeholder('—'),
                Tables\Columns\TextColumn::make('status')
                    ->formatStateUsing(fn ($s) => __(TireStorage::STATUSES[$s] ?? $s))
                    ->badge()
                    ->colors(['success' => ['stored'], 'gray' => ['retrieved']]),
                Tables\Columns\TextColumn::make('fee')->money('MDL')->alignRight(),
                Tables\Columns\IconColumn::make('paid')->label(__('Plătit'))->boolean(),
            ])
            ->defaultSort('checked_in_at', 'desc')
            ->emptyStateHeading(__('Niciun istoric'))
            ->emptyStateDescription(__('Folosește „Check-in depozit" pe set pentru a înregistra prima depozitare.'));
    }
}
