<?php
// ═══════════════════════════════════════════════════════════
// TWO FILES — split into separate files as shown below
// ═══════════════════════════════════════════════════════════

// ── FILE 1 ────────────────────────────────────────────────
// app/Filament/Resources/Invoices/Schemas/InvoiceInfolist.php

namespace App\Filament\Resources\Invoices\Schemas;

use Filament\Infolists\Components\TextEntry;
use Filament\Schemas\Components\Grid;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;

class InvoiceInfolist
{
    public static function configure(Schema $schema): Schema
    {
        return $schema->components([

            Section::make('Invoice')->schema([
                Grid::make(3)->schema([
                    TextEntry::make('invoice_number')
                        ->label('Invoice No.')
                        ->weight('bold')
                        ->copyable(),

                    TextEntry::make('payment_status')
                        ->label('Status')
                        ->badge()
                        ->color(fn (string $state): string => match ($state) {
                            'paid'    => 'success',
                            'partial' => 'warning',
                            'unpaid'  => 'danger',
                            default   => 'gray',
                        })
                        ->formatStateUsing(fn (string $state): string =>
                            ucfirst($state)
                        ),

                    TextEntry::make('due_date')
                        ->label('Due Date')
                        ->date('M d, Y')
                        ->placeholder('—'),
                ]),
            ]),

            Section::make('Amounts')->schema([
                Grid::make(3)->schema([
                    TextEntry::make('amount_kes')
                        ->label('Total (KES)')
                        ->formatStateUsing(fn ($state) =>
                            'KES ' . number_format($state, 2)
                        )
                        ->weight('bold')
                        ->size('lg'),

                    TextEntry::make('amount_usd')
                        ->label('USD Amount')
                        ->formatStateUsing(fn ($state) =>
                            $state > 0 ? '$ ' . number_format($state, 2) : '—'
                        ),

                    TextEntry::make('extra_charge_usd')
                        ->label('Extra Charge ($)')
                        ->formatStateUsing(fn ($state) =>
                            $state > 0 ? '$ ' . number_format($state, 2) : '—'
                        ),

                    TextEntry::make('amount_paid_kes')
                        ->label('Paid (KES)')
                        ->formatStateUsing(fn ($state) =>
                            'KES ' . number_format($state, 2)
                        )
                        ->color('success'),

                    TextEntry::make('outstanding_kes')
                        ->label('Outstanding (KES)')
                        ->formatStateUsing(fn ($state) =>
                            'KES ' . number_format($state, 2)
                        )
                        ->color(fn ($state) =>
                            $state > 0 ? 'danger' : 'success'
                        ),
                ]),
            ]),

            Section::make('Consignee')->schema([
                Grid::make(2)->schema([
                    TextEntry::make('consignment.customer_name')
                        ->label('Client Name'),
                    TextEntry::make('consignment.phone')
                        ->label('Phone'),
                    TextEntry::make('consignment.destination')
                        ->label('Destination'),
                    TextEntry::make('consignment.house_waybill_no')
                        ->label('Waybill / Container')
                        ->formatStateUsing(fn ($state, $record) =>
                            $state ?? $record->consignment?->container_no ?? '—'
                        ),
                ]),
            ]),
        ]);
    }
}
