"use client";

import { useTranslation } from "@enode/core/translations/hooks";
import { Button } from "@enode/ui/button";
import { CloudSlashFillIcon, ExclamationTriangleFillIcon } from "@enode/ui/icons";

// What a questionnaire sheet shows when its questions did not arrive: what
// happened, in the caller's words, with a way to try again and a way out.
// Shared by the check-in and the session rating so the two fail alike.
export function QuestionnaireUnavailable({
  reason,
  title,
  body,
  onRetry,
  onLater,
}: {
  /** Picks the icon; the words are the caller's, who knows what was asked. */
  reason: "offline" | "failed";
  title: string;
  body: string;
  onRetry: () => void;
  onLater: () => void;
}) {
  const { t } = useTranslation();
  const Icon =
    reason === "offline" ? CloudSlashFillIcon : ExclamationTriangleFillIcon;
  return (
    <div
      role="alert"
      className="flex min-h-0 flex-1 flex-col items-center justify-center px-6 pb-[env(safe-area-inset-bottom)]"
    >
      <div className="flex w-full max-w-sm flex-col items-center gap-3 text-center">
        <span className="flex size-14 items-center justify-center rounded-full bg-surface-base text-foreground-muted ring-1 ring-surface-stroke">
          <Icon className="size-6" />
        </span>
        <h2 className="heading-large text-foreground-default">{title}</h2>
        <p className="body-normal text-foreground-muted">{body}</p>
        <div className="mt-3 flex w-full flex-col gap-2">
          <Button variant="primary" size="large" onClick={onRetry}>
            {t("Try again")}
          </Button>
          <Button variant="tertiary" size="large" onClick={onLater}>
            {t("Later")}
          </Button>
        </div>
      </div>
    </div>
  );
}
