<?php

namespace App\Filament\Resources\Payments\Pages;

use App\Filament\Resources\Payments\PaymentResource;
use App\Support\Format;
use Filament\Actions\EditAction;
use Filament\Resources\Pages\ViewRecord;

class ViewPayment extends ViewRecord
{
    protected static string $resource = PaymentResource::class;

    public function getHeading(): string
    {
        $status = $this->record->voided ? 'ANULADO' : 'ACTIVO';

        return "Pago #{$this->record->id} — {$status}";
    }

    public function getSubheading(): ?string
    {
        $client = $this->record->credit?->client?->name ?? 'Sin cliente';
        $amount = Format::money($this->record->amount);

        if ($this->record->voided) {
            return "{$client} · {$amount} (anulado)";
        }

        return "{$client} · {$amount}";
    }

    protected function getHeaderActions(): array
    {
        return [
            EditAction::make()
                ->visible(fn () => ! $this->record->voided),
        ];
    }
}
