/**
 * Centralized demand-colour logic for the Yield Manager.
 *
 * A night's price is coloured relative to the property's base price. The
 * buckets below are the single source of truth shared by the calendar preview,
 * the table cells (Phase 1+), and any future yield view — extracted verbatim
 * from the original local copy in PriceCalendarPreview so they never drift.
 */

/**
 * Tailwind classes (with dark: variants) for a night priced at `price`
 * relative to the property `base` price.
 *
 * Ratio buckets:
 *   <= 0.80  red    (deep discount / low demand)
 *   <= 0.95  orange (discount)
 *   <= 1.05  green  (around base / normal)
 *   <= 1.20  blue   (premium)
 *   >  1.20  purple (high demand)
 */
export function getPriceColor(price: number, base: number): string {
    const ratio = base > 0 ? price / base : 1;
    if (ratio <= 0.8) return 'bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-300';
    if (ratio <= 0.95) return 'bg-orange-100 text-orange-800 dark:bg-orange-900/30 dark:text-orange-300';
    if (ratio <= 1.05) return 'bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-300';
    if (ratio <= 1.2) return 'bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-300';
    return 'bg-purple-100 text-purple-800 dark:bg-purple-900/30 dark:text-purple-300';
}

/** A single swatch entry for a reusable demand legend. */
export interface DemandLegendItem {
    label: string;
    className: string;
}

/**
 * Reusable legend matching {@link getPriceColor} buckets, plus the "Réservé"
 * swatch for booked nights. `className` is the swatch background only (callers
 * add their own border/size).
 */
export const DEMAND_LEGEND: DemandLegendItem[] = [
    { label: '≤80%', className: 'bg-red-100' },
    { label: '80-95%', className: 'bg-orange-100' },
    { label: '95-105%', className: 'bg-green-100' },
    { label: '105-120%', className: 'bg-blue-100' },
    { label: '>120%', className: 'bg-purple-100' },
    { label: 'Réservé', className: 'bg-muted' },
];
