"use client";

import { useTranslation } from "react-i18next";
import Button from "@/components/ui/Button";
import { getReadErrorMessage } from "@/lib/api/errors";
import { useLanguageStore } from "@/store/languageStore";

/**
 * The development detail when its read failed: the server's own message (a
 * 404 already arrives localized, «لم يتم العثور على الفرصة»), else «not
 * found» only for a 404 and «could not load» for anything else, with a retry. Replaces the empty page that used to render
 * «تاريخ غير صحيح» and an active «تسجيل» button for a course that did not load.
 */
export default function LearnServeDetailsUnavailable({ error, onRetry }: { error: unknown; onRetry: () => void }) {
  const { t } = useTranslation();
  const language = useLanguageStore((s) => s.language);
  return (
    <div role="alert" className="mx-auto max-w-3xl px-4 py-24 text-center">
      <p className="mb-6 text-lg text-red-600">
        {getReadErrorMessage(error, language, { notFound: t("COMMON.LEARN_SERVE_OPPORTUNITY_NOT_FOUND"), failed: t("COMMON.DETAILS_LOAD_FAILED") })}
      </p>
      <Button size="medium" onClick={onRetry}>{t("COMMON.RETRY")}</Button>
    </div>
  );
}
