import { useState as f, useEffect as p } from "react";
const i = /* @__PURE__ */ new Set();
let h = !1, c = "";
const r = typeof window < "u";
function n() {
  if (!r) return;
  const t = window.location.href;
  t !== c && (c = t, i.forEach((e) => e(window.location)));
}
function d() {
  if (!r || h) return;
  h = !0;
  const t = history.pushState;
  history.pushState = function(...s) {
    const a = t.apply(this, s);
    return n(), a;
  };
  const e = history.replaceState;
  history.replaceState = function(...s) {
    const a = e.apply(this, s);
    return n(), a;
  }, window.addEventListener("popstate", n), window.addEventListener("hashchange", n);
}
function l(t) {
  return r && (d(), i.add(t)), () => {
    i.delete(t);
  };
}
function u(t) {
  return {
    href: t.href,
    origin: t.origin,
    host: t.host,
    hostname: t.hostname,
    pathname: t.pathname,
    port: t.port,
    protocol: t.protocol,
    search: t.search,
    hash: t.hash
  };
}
const w = {
  href: "",
  origin: "",
  host: "",
  hostname: "",
  port: "",
  protocol: "",
  pathname: "",
  search: "",
  hash: ""
};
function y() {
  const [t, e] = f(() => r ? u(window.location) : w);
  return p(() => {
    if (r)
      return l((o) => {
        e(u(o));
      });
  }, []), t;
}
export {
  y as default,
  y as useLocationState
};
