<?php

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

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

class OrdersRelationManager extends RelationManager
{
    protected static string $relationship = 'orders';

    protected static ?string $title = 'Comenzi';

    public function table(Table $table): Table
    {
        return $table
            ->recordTitleAttribute('number')
            ->columns([
                Tables\Columns\TextColumn::make('number')->label('Nr.'),
                Tables\Columns\TextColumn::make('created_at')->label('Data')->dateTime('d.m.Y H:i'),
                Tables\Columns\TextColumn::make('status')
                    ->formatStateUsing(fn ($s) => OnlineOrder::STATUSES[$s] ?? $s)
                    ->badge()
                    ->colors([
                        'warning' => ['new'],
                        'info' => ['confirmed', 'packed'],
                        'primary' => ['shipped'],
                        'success' => ['delivered'],
                        'danger' => ['cancelled'],
                    ]),
                Tables\Columns\TextColumn::make('total')->money('MDL')->alignRight(),
            ])
            ->defaultSort('created_at', 'desc')
            ->emptyStateHeading('Nicio comandă încă');
    }
}
