export type BookingStatus = "new" | "contacted" | "confirmed" | "declined";
export type BookingFilter = "all" | BookingStatus;

export interface BaseBooking {
  id: number;
  name: string;
  phone?: string;
  instagram?: string;
  telegram?: string;
  status: BookingStatus;
  notes?: string;
  createdAt: string;
}

export const SHORT_DAYS: Record<string, string> = {
  "Понедельник": "ПН", "Вторник": "ВТ", "Среда": "СР", "Четверг": "ЧТ",
  "Пятница": "ПТ", "Суббота": "СБ", "Воскресенье": "ВС",
};

export const BOOKING_STATUSES: { key: BookingStatus; label: string; color: string; bg: string; border: string }[] = [
  { key: "new", label: "Новая", color: "text-gold", bg: "bg-gold/10", border: "border-gold/30" },
  { key: "contacted", label: "Связались", color: "text-blue-400", bg: "bg-blue-500/10", border: "border-blue-500/30" },
  { key: "confirmed", label: "Подтверждено", color: "text-emerald-400", bg: "bg-emerald-500/10", border: "border-emerald-500/30" },
  { key: "declined", label: "Отказ", color: "text-red-400", bg: "bg-red-500/10", border: "border-red-500/30" },
];

export function fmtDate(iso: string): string {
  return new Date(iso).toLocaleDateString("ru-RU");
}

export function countStatuses(items: { status: string }[]): Record<string, number> {
  const c: Record<string, number> = { new: 0, contacted: 0, confirmed: 0, declined: 0 };
  for (const i of items) c[i.status] = (c[i.status] || 0) + 1;
  return c;
}

export function sortByStatus<T extends { status: string }>(items: T[]): T[] {
  const order: Record<string, number> = { new: 0, contacted: 1, confirmed: 2, declined: 3 };
  return [...items].sort((a, b) => (order[a.status] ?? 0) - (order[b.status] ?? 0));
}

export interface BookingGroup<T extends BaseBooking> {
  key: string;
  label: string;
  sublabel?: string;
  dateBadge?: string;
  items: T[];
  isArchived: boolean;
}

export interface SearchResult extends BaseBooking {
  type: "class" | "mc" | "open-day";
  groupLabel?: string;
}
