"use client";

import { useEffect, useState } from "react";
import { fetchTodayJalali } from "@/lib/api";

export const useTodayJalali = () => {
  const [todayJalali, setTodayJalali] = useState<number | null>(null);
  const [loading, setLoading] = useState(true);
  const [error, setError] = useState<string | null>(null);

  useEffect(() => {
    const getDate = async () => {
      try {
        setLoading(true);
        const date = await fetchTodayJalali();
        setTodayJalali(date);
      } catch (err: any) {
        console.error(err);
        setError(err.message || "Unknown error");
      } finally {
        setLoading(false);
      }
    };
    getDate();
  }, []);

  return { todayJalali, loading, error };
};
