import d from "../../../core/Localization/datetime/restamper/restamper.js";
import { createWatchlist as h, isWatchlistUnsubscribeToken as k } from "../../reactive/watchlist/main.js";
import { clock as y } from "../clock/main.js";
import { timezoneToSystem as S, systemToTimezone as T } from "../../../core/Localization/datetime/restamper/utils.js";
import { isNull as z } from "../../../utils/value/is.js";
import { struct as W } from "../../../utils/struct/main.js";
import { enumerable as c, getter as x } from "../../../utils/struct/property.js";
const $ = (() => {
  const u = /* @__PURE__ */ new Map(), r = d(), a = (n = Date.now()) => {
    const t = new Date(S(r, n)), e = T(r, t.setHours(0, 0, 0, 0)), s = T(r, t.setDate(t.getDate() + 1));
    return [e, s - e];
  };
  return (n) => {
    r.tz = n;
    const t = r.tz.current;
    return u.get(t) ?? (() => {
      let e = null, s = null, m = null;
      const l = () => (r.tz = t, e ?? a()[0]), p = (o = Date.now()) => {
        r.tz = t, [e, s] = a(o);
      }, { cancelSubscriptions: w, requestNotification: D, subscribe: g, on: f } = h({
        timestamp: l
      });
      f.resume = () => {
        m = y.subscribe((o) => {
          if (k(o)) return;
          const { now: i } = o;
          if (z(e) || z(s)) return p(i);
          i - e < s || (p(i), D());
        });
      }, f.idle = () => {
        m?.(), e = s = m = null;
      };
      const b = W({
        cancelSubscriptions: c(w),
        timestamp: x(l),
        timezone: c(t),
        subscribe: c(g)
      });
      return u.set(t, b), b;
    })();
  };
})();
export {
  $ as default,
  $ as today
};
