var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/hooks/useLocalStorage.ts
var useLocalStorage_exports = {};
__export(useLocalStorage_exports, {
  useLocalStorage: () => useLocalStorage
});
module.exports = __toCommonJS(useLocalStorage_exports);
var import_react = require("react");

// src/util/storage.ts
var StorageService = class {
  // this seems to be a bug in eslint as 'paramter-properties' is a special syntax of typescript
  constructor(storage) {
    this.storage = storage;
  }
  get(key) {
    const value = this.storage.getItem(key);
    if (value === null) {
      return null;
    }
    return JSON.parse(value);
  }
  set(key, value) {
    this.storage.setItem(key, JSON.stringify(value));
  }
  delete(key) {
    this.storage.removeItem(key);
  }
  deleteAll() {
    this.storage.clear();
  }
};
var LocalStorageService = class extends StorageService {
  constructor() {
    super(window.localStorage);
  }
};

// src/hooks/useLocalStorage.ts
var useLocalStorage = (key, initValue) => {
  const get = (0, import_react.useCallback)(() => {
    if (typeof window === "undefined") {
      return initValue;
    }
    const storageService = new LocalStorageService();
    const value = storageService.get(key);
    return value || initValue;
  }, [initValue, key]);
  const [storedValue, setStoredValue] = (0, import_react.useState)(get);
  const setValue = (0, import_react.useCallback)((value) => {
    const newValue = value instanceof Function ? value(storedValue) : value;
    const storageService = new LocalStorageService();
    storageService.set(key, value);
    setStoredValue(newValue);
  }, [storedValue, setStoredValue, key]);
  (0, import_react.useEffect)(() => {
    setStoredValue(get());
  }, []);
  return [storedValue, setValue];
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useLocalStorage
});
//# sourceMappingURL=useLocalStorage.js.map