export type VehicleSizeCategoryOption = {
    id: number;
    slug: string;
    name: string;
    description: string | null;
    image_url: string | null;
    emoji_fallback: string | null;
    display_order: number;
    is_active: boolean;
};

export function formatPriceRangeCents(prices: number[]): string {
    if (prices.length === 0) {
        return '$0.00';
    }

    const min = Math.min(...prices);
    const max = Math.max(...prices);
    const format = (cents: number) => `$${(cents / 100).toFixed(2)}`;

    if (min === max) {
        return format(min);
    }

    return `${format(min)} – ${format(max)}`;
}

export function buildDefaultPrices(
    categories: VehicleSizeCategoryOption[],
): Record<string, number> {
    return Object.fromEntries(
        categories.map((category) => [category.slug, 0]),
    );
}

export function vehicleSizeLabel(
    categories: VehicleSizeCategoryOption[],
    slug: string,
): string {
    return categories.find((category) => category.slug === slug)?.name ?? slug;
}
