<?php

namespace App\Filament\Support;

use Filament\Infolists\Components\ViewEntry;

/**
 * The merged, date-descending activity rail (see ViewCustomer::timelineFor()
 * for the data shape) rendered as one ViewEntry. Replaces the RepeatableEntry
 * table the port collapsed the Inertia timeline into: each event gets a
 * coloured circular icon node punched over a vertical border, a bold label, a
 * muted date · detail sub-line, and a right-aligned amount — readable from a
 * metre away, unlike five grey columns of text.
 *
 * Event types carry their own icon + colour:
 *   invoice     → receipt-text, blue
 *   payment     → banknotes, success
 *   return      → arrow-uturn, warning
 *   credit_note → document, purple
 *
 * @see resources/views/filament/infolists/timeline.blade.php
 */
class Timeline
{
    public const TYPES = [
        'invoice' => ['heroicon-m-receipt-percent', 'blue'],
        'payment' => ['heroicon-m-banknotes', 'success'],
        'return' => ['heroicon-m-arrow-uturn-left', 'warning'],
        'credit_note' => ['heroicon-m-document-text', 'purple'],
        'info' => ['heroicon-m-information-circle', 'gray'],
    ];

    public static function make(string $name = 'timeline'): ViewEntry
    {
        return ViewEntry::make($name)
            ->view('filament.infolists.timeline')
            ->columnSpanFull();
    }

    /**
     * The rendered classes for a timeline row of the given type — the tailwind
     * colour utilities the blade uses to paint the node. Explicit per colour
     * rather than a runtime string-build so every utility is visible to
     * Tailwind's JIT compiler.
     *
     * @return array{icon: string, node: string, ring: string}
     */
    public static function classesFor(string $type): array
    {
        return match ($type) {
            'invoice' => ['heroicon-m-receipt-percent', 'bg-blue-500', 'ring-blue-100'],
            'payment' => ['heroicon-m-banknotes', 'bg-emerald-500', 'ring-emerald-100'],
            'return' => ['heroicon-m-arrow-uturn-left', 'bg-amber-500', 'ring-amber-100'],
            'credit_note' => ['heroicon-m-document-text', 'bg-purple-500', 'ring-purple-100'],
            default => ['heroicon-m-information-circle', 'bg-gray-400', 'ring-gray-100'],
        };
    }
}