"use client";
import { useState, useEffect } from "react";
import Schedule from "@/components/custom/Schedule";
import ScheduleAfter from "@/components/custom/ScheduleAfter";
import { getCookie, setCookie } from "cookies-next";

export default function ScheduleChooser() {
  const [showScheduleAfter, setShowScheduleAfter] = useState(false);

  useEffect(() => {
    const scheduleAfterCookie = getCookie("scheduleAfter");
    if (scheduleAfterCookie) {
      setShowScheduleAfter(true);
    }
  }, []);

  const handleFormSubmit = () => {
    setShowScheduleAfter(true);
    setCookie("scheduleAfter", "true", { maxAge: 3600, path: "/schedule" });
  };

  return (
    <>
      {showScheduleAfter ? (
        <ScheduleAfter />
      ) : (
        <Schedule onFormSubmit={handleFormSubmit} />
      )}
    </>
  );
}
