"use client";

import { useEffect } from "react";
import { AnimatePresence, motion } from "framer-motion";
import { useHashRoute } from "@/lib/router";
import Landing from "@/components/ppdb/Landing";
import RegisterView from "@/components/ppdb/RegisterView";
import AdminView from "@/components/ppdb/AdminView";

export default function Page() {
  const { route, query } = useHashRoute();
  const key = route || "beranda";

  useEffect(() => {
    window.scrollTo(0, 0);
  }, [key]);

  return (
    <div className="min-h-screen bg-background">
      <AnimatePresence mode="wait">
        <motion.div
          key={key}
          initial={{ opacity: 0, y: 14 }}
          animate={{ opacity: 1, y: 0 }}
          exit={{ opacity: 0, y: -14 }}
          transition={{ duration: 0.28, ease: "easeOut" }}
          className="flex flex-col"
        >
          {route === "daftar" ? (
            <RegisterView preJurusan={query.get("jurusan") || ""} />
          ) : route === "admin" ? (
            <AdminView />
          ) : (
            <Landing />
          )}
        </motion.div>
      </AnimatePresence>
    </div>
  );
}
