"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const React = require("react");
function useURLQueryState(key, defaultValue) {
  const parsed = parse(window.location.search);
  const initialValue = parsed[key] ? JSON.parse(parsed[key]) : defaultValue;
  const [formState, setFormState] = React.useState(initialValue);
  const value = formState;
  const setValue = (partialValue) => {
    const newFormState = { ...value, ...partialValue };
    setFormState(newFormState);
    const curSearch = parse(window.location.search);
    curSearch[key] = JSON.stringify(newFormState);
    const searchParams = new URLSearchParams(curSearch);
    window.history.replaceState({}, document.title, `?${searchParams.toString()}`);
  };
  return [value, setValue];
}
const parse = (search) => Object.fromEntries(new URLSearchParams(search).entries());
exports.useURLQueryState = useURLQueryState;
