import type { ReactNode } from "react";
import { useApp } from "@/pages/app/AppContext";
import { BackHeader, Btn, cn } from "@/pages/app/components/ui";

type Tone = "warn" | "mint" | "danger";

const ICON_TONES: Record<Tone, string> = {
  warn: "bg-secondary-50 text-secondary-700",
  mint: "bg-accent-100 text-accent-600",
  danger: "bg-danger-50 text-danger-500",
};

const NOTE_TONES: Record<Tone, string> = {
  warn: "bg-secondary-50 border-secondary-200 text-secondary-900",
  mint: "bg-accent-50 border-accent-200 text-accent-800",
  danger: "bg-danger-50 border-danger-200 text-danger-700",
};

/**
 * A "sent / pending / approved / rejected" notice screen: yellow, mint or
 * danger icon + title + optional details card + note + actions, all in the
 * normal page flow (no sticky bars).
 */
export default function ReviewScreen({
  headerTitle,
  icon = "ri-time-line",
  tone = "warn",
  title,
  desc,
  children,
  note,
  primaryLabel,
  onPrimary,
  secondaryLabel,
  onSecondary,
}: {
  headerTitle: string;
  icon?: string;
  tone?: Tone;
  title: string;
  desc?: string;
  children?: ReactNode;
  note?: string;
  primaryLabel: string;
  onPrimary: () => void;
  secondaryLabel?: string;
  onSecondary?: () => void;
}) {
  const { goBack } = useApp();

  return (
    <div className="min-h-full flex flex-col bg-background-50">
      <BackHeader title={headerTitle} onBack={goBack} />

      <div className="flex-1 px-5 pt-8 pb-4 flex flex-col items-center text-center">
        <div
          className={cn(
            "w-20 h-20 rounded-full flex items-center justify-center mb-5 shrink-0",
            ICON_TONES[tone],
          )}
        >
          <i className={cn(icon, "text-[42px] leading-none")} />
        </div>

        <h1 className="text-[20px] font-bold text-foreground-950 max-w-[320px]">{title}</h1>
        {desc && (
          <p className="text-[13px] text-foreground-600 mt-2.5 max-w-[300px] leading-relaxed">
            {desc}
          </p>
        )}

        {children && <div className="w-full mt-6 text-right">{children}</div>}

        {note && (
          <div
            className={cn(
              "mt-4 w-full rounded-[14px] border px-4 py-3 text-right flex items-start gap-2",
              NOTE_TONES[tone],
            )}
          >
            <i className="ri-information-line text-[16px] leading-none mt-0.5 shrink-0" />
            <p className="text-[11.5px] leading-relaxed">{note}</p>
          </div>
        )}

        <div className="mt-auto pt-8 w-full space-y-2.5">
          <Btn full onClick={onPrimary}>
            {primaryLabel}
          </Btn>
          {secondaryLabel && onSecondary && (
            <button
              type="button"
              onClick={onSecondary}
              className="w-full h-[52px] rounded-[14px] text-[14px] font-semibold text-foreground-900 border border-background-300 hover:bg-background-200 cursor-pointer whitespace-nowrap active:scale-[0.98] transition-transform"
            >
              {secondaryLabel}
            </button>
          )}
        </div>
      </div>
    </div>
  );
}