<?php

declare(strict_types=1);

namespace App\Filament\Support;

use Filament\Support\Icons\Heroicon;

/**
 * Filament 按钮 / 行操作图标（实心 Heroicon）。
 *
 * 约定：Resource、Page 中不要手写 ->icon()；在下方 EXACT 或模式规则中维护动作名即可。
 * 全局注入见 {@see DberpFilamentActionConfigurator}。
 */
final class DberpFilamentActionIconResolver
{
    /**
     * @var array<string, Heroicon>
     */
    private const EXACT = [
        'apply' => Heroicon::CheckBadge,
        'close' => Heroicon::LockClosed,
        'close_exception' => Heroicon::LockClosed,
        'cancel' => Heroicon::XMark,
        'confirm' => Heroicon::CheckCircle,
        'createAnother' => Heroicon::SquaresPlus,
        'confirmDifference' => Heroicon::Scale,
        'convert' => Heroicon::ArrowsRightLeft,
        'convert_remaining_to_purchase_order' => Heroicon::ArrowsRightLeft,
        'copy' => Heroicon::DocumentDuplicate,
        'copy_role' => Heroicon::DocumentDuplicate,
        'create' => Heroicon::Plus,
        'create_outbound' => Heroicon::ArrowUpTray,
        'customerReceivables' => Heroicon::CurrencyDollar,
        'delete' => Heroicon::Trash,
        'disable' => Heroicon::NoSymbol,
        'disableSpecCombo' => Heroicon::NoSymbol,
        'disable_selected' => Heroicon::NoSymbol,
        'edit' => Heroicon::PencilSquare,
        'enable_selected' => Heroicon::CheckCircle,
        'export' => Heroicon::ArrowDownTray,
        'generate' => Heroicon::Sparkles,
        'generate_purchase_request' => Heroicon::ClipboardDocumentList,
        'generateSpecCombinations' => Heroicon::Sparkles,
        'ignored' => Heroicon::EyeSlash,
        'import_china_regions' => Heroicon::ArrowUpTray,
        'inventoryTransactions' => Heroicon::QueueList,
        'invalidate_mapping' => Heroicon::XMark,
        'open' => Heroicon::ArrowTopRightOnSquare,
        'open_exception_list' => Heroicon::ExclamationTriangle,
        'print' => Heroicon::Printer,
        'paymentOrders' => Heroicon::DocumentArrowUp,
        'processed' => Heroicon::CheckBadge,
        'purchaseOrders' => Heroicon::ClipboardDocumentList,
        'receiptOrders' => Heroicon::DocumentArrowDown,
        'receiptPaymentQuery' => Heroicon::MagnifyingGlass,
        'register_arrival' => Heroicon::Truck,
        'remap_customer' => Heroicon::ArrowsRightLeft,
        'rebind_customer' => Heroicon::UserGroup,
        'rebind_product' => Heroicon::Cube,
        'reopen' => Heroicon::ArrowUturnLeft,
        'reset_password' => Heroicon::Key,
        'resolve' => Heroicon::CheckCircle,
        'retry' => Heroicon::ArrowPath,
        'retry_customer_sync' => Heroicon::ArrowPath,
        'retry_mapping_sync' => Heroicon::ArrowPath,
        'retry_selected' => Heroicon::ArrowPath,
        'reviewed' => Heroicon::ClipboardDocumentCheck,
        'refreshAnalysis' => Heroicon::ArrowPath,
        'refreshData' => Heroicon::ArrowPath,
        'salesOrders' => Heroicon::ShoppingCart,
        'save' => Heroicon::Check,
        'settlementStatements' => Heroicon::DocumentText,
        'settlementWriteOffs' => Heroicon::DocumentMinus,
        'submit' => Heroicon::PaperAirplane,
        'submit_resolution' => Heroicon::PaperAirplane,
        'supplierPayables' => Heroicon::CurrencyDollar,
        'sync_dbshop_customers' => Heroicon::ArrowPath,
        'sync_dbshop_inventory' => Heroicon::ArrowPath,
        'sync_inventory_single' => Heroicon::ArrowPath,
        'toggle_enabled' => Heroicon::Power,
        'toggle_status' => Heroicon::Power,
        'view' => Heroicon::Eye,
        'view_customer' => Heroicon::UserGroup,
        'view_inventory' => Heroicon::ArchiveBox,
        'view_inventory_balance' => Heroicon::ArchiveBox,
        'view_inventory_transactions' => Heroicon::QueueList,
        'view_product' => Heroicon::Cube,
        'view_purchase_order' => Heroicon::ClipboardDocumentList,
        'view_purchase_orders' => Heroicon::ClipboardDocumentList,
        'view_sales_orders' => Heroicon::ShoppingCart,
        'view_source' => Heroicon::ArrowTopRightOnSquare,
        'view_source_document' => Heroicon::ArrowTopRightOnSquare,
        'view_supplier' => Heroicon::BuildingStorefront,
        'view_supplier_payables' => Heroicon::CurrencyDollar,
        'void' => Heroicon::XCircle,
        'adjustSafetyStock' => Heroicon::AdjustmentsHorizontal,
        'complete' => Heroicon::Flag,
        'link_purchase_exceptions' => Heroicon::ExclamationTriangle,
        'link_purchase_order' => Heroicon::ClipboardDocumentList,
        'link_purchase_orders' => Heroicon::ClipboardDocumentList,
        'link_purchase_price_references' => Heroicon::Tag,
        'link_purchase_returns' => Heroicon::ArrowUturnLeft,
        'link_product' => Heroicon::Cube,
        'link_supplier' => Heroicon::BuildingStorefront,
    ];

    public static function forActionName(?string $name): Heroicon|string|null
    {
        if ($name === null || $name === '') {
            return null;
        }

        if (isset(self::EXACT[$name])) {
            return self::EXACT[$name];
        }

        if (str_starts_with($name, 'view_')) {
            return Heroicon::Eye;
        }

        if (str_starts_with($name, 'link_')) {
            return Heroicon::Link;
        }

        if (str_contains($name, 'refresh')) {
            return Heroicon::ArrowPath;
        }

        if (str_contains($name, 'retry')) {
            return Heroicon::ArrowPath;
        }

        if (str_contains($name, 'sync')) {
            return Heroicon::ArrowPath;
        }

        if (str_contains($name, 'import')) {
            return Heroicon::ArrowUpTray;
        }

        if (str_contains($name, 'export')) {
            return Heroicon::ArrowDownTray;
        }

        if (str_contains($name, 'disable') || str_contains($name, 'void')) {
            return str_contains($name, 'void') ? Heroicon::XCircle : Heroicon::NoSymbol;
        }

        if (str_contains($name, 'enable')) {
            return Heroicon::CheckCircle;
        }

        if (str_contains($name, 'confirm')) {
            return Heroicon::CheckCircle;
        }

        if (str_contains($name, 'generate')) {
            return Heroicon::Sparkles;
        }

        if (str_contains($name, 'inventory_transaction') || str_contains($name, 'inventoryTransaction')) {
            return Heroicon::QueueList;
        }

        if (str_contains($name, 'copy')) {
            return Heroicon::DocumentDuplicate;
        }

        return null;
    }
}
