import type { AgendaCalendar } from "@/lib/agenda/agenda-types"
import type { AgendaVideoProvider } from "@/lib/agenda/agenda-settings-types"
import { videoProviderLabel } from "@/lib/agenda/agenda-settings-labels"

export type AgendaVideoIcon =
  | { kind: "image"; src: string; alt: string }
  | { kind: "iconify"; icon: string }

export const AGENDA_VIDEO_PROVIDER_ICONS: Record<
  Exclude<AgendaVideoProvider, "none">,
  AgendaVideoIcon
> = {
  ultimeet: { kind: "image", src: "/ultimeet-mark.svg", alt: "UltiMeet" },
  google_meet: { kind: "iconify", icon: "logos:google-meet" },
  zoom: { kind: "iconify", icon: "logos:zoom-icon" },
  teams: { kind: "iconify", icon: "logos:microsoft-teams" },
  jitsi: { kind: "iconify", icon: "simple-icons:jitsi" },
}

export function newAgendaEventUid(): string {
  return `${crypto.randomUUID()}@ulti`
}

export function agendaEventPath(calendar: AgendaCalendar, uid: string): string {
  const base = calendar.path.endsWith("/") ? calendar.path : `${calendar.path}/`
  return `${base}${uid}.ics`
}

export function videoToggleLabel(
  provider: AgendaVideoProvider,
  enabled: boolean,
): string {
  if (provider === "none") return "Aucune visio"
  const name = videoProviderLabel(provider)
  return enabled ? `${name} activée` : `Ajouter ${name}`
}

export function videoJoinLabel(provider: AgendaVideoProvider): string {
  return `Rejoindre ${videoProviderLabel(provider)}`
}

export function canAutoGenerateVideoLink(provider: AgendaVideoProvider): boolean {
  return provider === "ultimeet"
}
