import { useCallback as p, useState as l, useEffect as d } from "react";
import e from "dayjs";
import h from "dayjs/plugin/utc";
import T from "dayjs/plugin/timezone";
import z from "dayjs/plugin/localizedFormat";
import "dayjs/locale/zh-cn";
import "dayjs/locale/en";
import { formatToDatetime as I } from "../Util/index.js";
e.extend(h);
e.extend(T);
e.extend(z);
const g = e.tz.guess(), x = (t) => t >= 0 && t < 6 ? { phase: "dawn", icon: "🌒" } : t >= 6 && t < 12 ? { phase: "morning", icon: "🌞" } : t >= 12 && t < 18 ? { phase: "afternoon", icon: "🌞" } : { phase: "night", icon: "🌒" };
function y(t = g, n = "zh") {
  const o = p(() => {
    const i = n === "zh" ? "zh-cn" : "en", c = n === "zh" ? "zh-cn" : "en-us";
    e.locale(i);
    const r = e().tz(t), m = r.hour(), { phase: f, icon: u } = x(m);
    return {
      formattedTime: r.format("LT"),
      fullDateTime: I(r.toDate(), { tz: t, locale: c }),
      phase: f,
      icon: u,
      rawTime: r
    };
  }, [t, n]), [s, a] = l(o());
  return d(() => {
    a(o());
    const i = setInterval(() => {
      a(o());
    }, 6e3);
    return () => {
      clearInterval(i);
    };
  }, [t, n, o]), s;
}
export {
  y as default
};
