// Video is bookable only when every gate holds: the practice switch, a telehealth location, video on a // service and a clinician schedule that offers it. The practice switch alone is not "Working". export const VIDEO_GATES = "Turn on video visits, add a telehealth location, then offer video on a service and on a clinician's schedule."; export type VideoCardFacts = { telehealthEnabled: boolean; clinicians: { loading: boolean; error: boolean; readiness: { telehealthReady: boolean }[] }; }; export type VideoCard = { detail: string; status: "working" | "needs-setup" | "needs-attention"; statusLabel: string; }; export const videoVisitsCard = ({ telehealthEnabled, clinicians }: VideoCardFacts): VideoCard => { if (!telehealthEnabled) return { detail: VIDEO_GATES, status: "needs-setup", statusLabel: "Needs setup" }; if (clinicians.error) { return { detail: `Couldn't check whether a clinician can be booked by video. ${VIDEO_GATES}`, status: "needs-attention", statusLabel: "Status unavailable" }; } if (clinicians.loading) return { detail: VIDEO_GATES, status: "needs-attention", statusLabel: "Checking" }; if (clinicians.readiness.some((r) => r.telehealthReady)) { return { detail: "Patients can book a video visit with at least one clinician.", status: "working", statusLabel: "Working" }; } return { detail: `Video is on, but no clinician can be booked by video yet. ${VIDEO_GATES}`, status: "needs-setup", statusLabel: "Needs setup" }; };