"use client";

import { useRouter } from "next/navigation";
import { motion } from "framer-motion";
import { ChevronLeft } from "lucide-react";
import { ReactNode } from "react";

export function AuthShell({
  title,
  subtitle,
  children,
  backHref,
}: {
  title: string;
  subtitle?: string;
  children: ReactNode;
  backHref?: string;
}) {
  const router = useRouter();

  return (
    <div className="relative flex min-h-dvh flex-1 flex-col overflow-hidden bg-ink px-6 pt-safe pb-safe">
      <div className="pointer-events-none absolute -top-16 right-[-40px] h-56 w-56 rounded-full bg-teal/15 blur-3xl" />
      <div className="pointer-events-none absolute top-40 left-[-50px] h-56 w-56 rounded-full bg-gold/15 blur-3xl" />

      <div className="flex items-center pt-2">
        <button
          type="button"
          aria-label="Go back"
          onClick={() => (backHref ? router.push(backHref) : router.back())}
          className="flex h-10 w-10 items-center justify-center rounded-full border border-white/10 bg-white/[0.06] text-paper"
        >
          <ChevronLeft size={20} strokeWidth={2.5} />
        </button>
      </div>

      <div className="flex flex-1 flex-col justify-center gap-8 py-6">
        <motion.div
          initial={{ opacity: 0, y: 12 }}
          animate={{ opacity: 1, y: 0 }}
          transition={{ duration: 0.4 }}
        >
          <div className="mb-6 flex h-12 w-12 items-center justify-center rounded-2xl bg-gradient-to-br from-gold-bright to-gold-dim shadow-glow-gold">
            <span className="font-display text-xl font-bold text-ink">S</span>
          </div>
          <h1 className="font-display text-2xl font-semibold tracking-tight text-paper">
            {title}
          </h1>
          {subtitle && <p className="mt-2 text-sm leading-relaxed text-paper/60">{subtitle}</p>}
        </motion.div>

        <motion.div
          initial={{ opacity: 0, y: 12 }}
          animate={{ opacity: 1, y: 0 }}
          transition={{ duration: 0.4, delay: 0.1 }}
        >
          {children}
        </motion.div>
      </div>
    </div>
  );
}
