import { useMemo as c, useState as z, useEffect as g } from "../../../../external/.pnpm/preact@10.28.2/node_modules/preact/hooks/dist/hooks.module.js";
import { getTimezoneOffsetFromFormattedDateString as p, getGMTSuffixForTimezoneOffset as E } from "../../../../core/Localization/datetime/restamper/utils.js";
import { clock as M } from "../../../../primitives/time/clock/main.js";
import { isWatchlistUnsubscribeToken as l } from "../../../../primitives/reactive/watchlist/main.js";
import _ from "../../../../core/Localization/datetime/restamper/restamper.js";
import { EMPTY_OBJECT as G, EMPTY_ARRAY as O } from "../../../../utils/value/constants.js";
import { boolOrFalse as S } from "../../../../utils/value/bool.js";
const { getTimezoneTime: U, getUsedTimezone: F } = (() => {
  const o = /\d{2}:\d{2}(?=:\d{2}(?:\.\d+)?\s+([AP]M))/i, m = /^GMT|0(?=\d:00)|:00/g, e = _();
  return { getTimezoneTime: (t, T = Date.now()) => {
    e.tz = t;
    const { formatted: n } = e(T), [i = "", f = ""] = n?.match(o) ?? O, a = p(n), u = `${i}${f && ` ${f}`}`, d = E(a).replace(m, "");
    return [u, d];
  }, getUsedTimezone: (t) => (e.tz = t, e.tz.current) };
})(), N = ({ timezone: o, withClock: m = !1 } = G) => {
  const e = c(() => S(m), [m]), s = c(() => F(o), [o]), [r, t] = z(() => Date.now()), [T, n] = c(() => U(s, r), [r, s]);
  return g(() => {
    if (e)
      return M.subscribe((i) => {
        l(i) || t(i.now);
      });
  }, [t, e]), { clockTime: T, GMTOffset: n, timestamp: r, timezone: s };
};
export {
  N as default,
  U as getTimezoneTime,
  F as getUsedTimezone
};
