<?php

namespace App\Filament\Resources\InvoiceResource\Pages;

use App\Filament\Resources\Concerns\HasKpiHeader;
use App\Filament\Resources\Concerns\HasStatusTabs;
use App\Filament\Resources\InvoiceResource;
use App\Filament\Widgets\InvoiceTotalsOverview;
use App\Models\Lookups\Status;
use Filament\Actions\Action;
use Filament\Resources\Pages\ListRecords;

class ListInvoices extends ListRecords
{
    use HasKpiHeader;
    use HasStatusTabs;

    protected static string $resource = InvoiceResource::class;

    protected static string $tabStatusContext = Status::CTX_INVOICE_PAYMENT;

    protected static function tabStatusColumn(): string
    {
        return 'payment_status_id';
    }

    protected static string $kpiWidget = InvoiceTotalsOverview::class;

    protected function getHeaderActions(): array
    {
        return [
            // The source exposes legacy entry as its own screen
            // (invoices/legacy/create), gated by the same isms_invoices.create.
            Action::make('legacy')
                ->label('Add legacy invoice')
                ->color('gray')
                ->visible(fn (): bool => InvoiceResource::canCreate())
                ->url(fn (): string => InvoiceResource::getUrl('legacy')),
        ];
    }
}
