import { Pencil, Plus, Trash2 } from 'lucide-react';
import StatusBadge from '@/components/member/status-badge';

/**
 * Pieces shared by the admin lists a business configures for itself
 * (loan categories, financing types, savings plan types).
 */

export function CatalogNameCell({
    name,
    description,
    isActive,
}: {
    name: string;
    description: string | null;
    isActive: boolean;
}) {
    return (
        <div className="min-w-0">
            <span className="flex flex-wrap items-center gap-1.5 font-semibold text-ink">
                {name}
                {!isActive && <StatusBadge tone="neutral">Hidden</StatusBadge>}
            </span>
            {description && (
                <span className="line-clamp-2 text-xs text-ink-400">
                    {description}
                </span>
            )}
        </div>
    );
}

export function CatalogActions({
    name,
    onEdit,
    onDelete,
}: {
    name: string;
    onEdit: () => void;
    /** Left out when the item is in use and cannot be deleted. */
    onDelete?: () => void;
}) {
    return (
        <span className="inline-flex items-center gap-0.5">
            <button
                type="button"
                onClick={onEdit}
                className="rounded-full p-1.5 text-ink-400 hover:bg-surface-100 hover:text-ink"
                aria-label={`Edit ${name}`}
            >
                <Pencil className="size-4" />
            </button>
            {onDelete ? (
                <button
                    type="button"
                    onClick={onDelete}
                    className="rounded-full p-1.5 text-ink-400 hover:bg-red-50 hover:text-red-600"
                    aria-label={`Delete ${name}`}
                >
                    <Trash2 className="size-4" />
                </button>
            ) : (
                <span className="size-7" aria-hidden />
            )}
        </span>
    );
}

export function CatalogNewButton({
    label,
    onClick,
}: {
    label: string;
    onClick: () => void;
}) {
    return (
        <button
            type="button"
            onClick={onClick}
            className="inline-flex items-center gap-1.5 rounded-full bg-brand px-3.5 py-1.5 text-sm font-semibold text-white hover:bg-brand-hover"
        >
            <Plus className="size-4" />
            {label}
        </button>
    );
}
