import type { ReactNode } from "react";
import DismissibleAlert from "../DismissibleAlert";
import LoadingFrame from "../LoadingFrame";
import PageTitle from "../PageTitle";
import { usePlatformLanguage } from "../../i18n/LanguageContext";

type Props = {
  title: string;
  description: string;
  loading?: boolean;
  loadingLabel?: string;
  error?: string;
  success?: string;
  actions?: ReactNode;
  children: ReactNode;
  className?: string;
};

export default function AdminPageLayout({
  title,
  description,
  loading = false,
  loadingLabel = "i18n:govoplan-core.loading_administration_data.643bd894",
  error = "",
  success = "",
  actions,
  children,
  className = ""
}: Props) {
  const { translateText } = usePlatformLanguage();
  return (
    <div className={`admin-section-page ${className}`.trim()}>
      <div className="page-heading split workspace-heading admin-page-heading">
        <div>
          <PageTitle loading={loading}>{title}</PageTitle>
          <p>{translateText(description)}</p>
        </div>
        {actions && <div className="button-row compact-actions admin-page-actions">{actions}</div>}
      </div>
      {error && <DismissibleAlert tone="danger" resetKey={error} floating>{error}</DismissibleAlert>}
      {success && <DismissibleAlert tone="success" resetKey={success} floating>{success}</DismissibleAlert>}
      <LoadingFrame loading={loading} label={translateText(loadingLabel)}>
        {children}
      </LoadingFrame>
    </div>);

}