import l from "@leaflink/snitch";
import { hashCode as i } from "./helpers.js";
const c = "ll";
function m(o, r, a = {}) {
  const e = a.global ? "" : `-${location.pathname}`, t = `${c}-${o}${e}`, s = JSON.stringify(r);
  try {
    localStorage.setItem(t, s);
  } catch (n) {
    (n == null ? void 0 : n.name) === "QuotaExceededError" ? l.log(`Your localStorage is full. Failed to save item for key: ${t}`) : l.log(`Failed to save value to localStorage for key: ${t}`);
  }
}
function g(o, r = {}) {
  const a = r.global ? "" : `-${location.pathname}`, e = localStorage.getItem(`${c}-${o}${a}`);
  if (e === null || e === "undefined")
    return null;
  try {
    return JSON.parse(e);
  } catch (t) {
    return l.error(t == null ? void 0 : t.message, { error: t }), null;
  }
}
function u(o, r = {}) {
  const a = r.global ? "" : `-${location.pathname}`, e = `${c}-${o}${a}`;
  if (localStorage.getItem(e) !== null)
    try {
      localStorage.removeItem(e);
    } catch (s) {
      l.error(s.message, { error: s });
    }
}
function p(o, r) {
  const a = JSON.parse(localStorage.getItem(o) || "{}");
  try {
    return (a[r] || {})[i(location.pathname)];
  } catch (e) {
    l.error(e == null ? void 0 : e.message, { error: e });
    return;
  }
}
function S(o, r) {
  const e = { ...JSON.parse(localStorage.getItem(o) || "{}") };
  e[r] && delete e[r][i(location.pathname)];
  try {
    localStorage.setItem(o, JSON.stringify(e));
  } catch (t) {
    (t == null ? void 0 : t.name) === "QuotaExceededError" ? l.log("Your localStorage is full. Failed to set item.") : l.log("Failed to set item to localStorage.");
  }
}
const I = {
  setItem: m,
  getItem: g,
  removeItem: u
};
export {
  g as getPersistentItem,
  p as getPersistentItem__deprecated,
  I as persistentStorage,
  u as removePersistentItem,
  S as removePersistentItem__deprecated,
  m as setPersistentItem
};
//# sourceMappingURL=storage.js.map
