import {
  useEffectOnce
} from "/build/_shared/chunk-7NMI3PDC.js";
import {
  init_esm2 as init_esm,
  useFetcher,
  useRevalidator
} from "/build/_shared/chunk-ZC2TL3GZ.js";
import {
  require_react
} from "/build/_shared/chunk-PECDPABK.js";
import {
  createHotContext,
  init_remix_hmr
} from "/build/_shared/chunk-G7KTOMTD.js";
import {
  __commonJS,
  __toESM
} from "/build/_shared/chunk-PNG5AS42.js";

// ../../node_modules/toggle-selection/index.js
var require_toggle_selection = __commonJS({
  "../../node_modules/toggle-selection/index.js"(exports, module) {
    module.exports = function() {
      var selection = document.getSelection();
      if (!selection.rangeCount) {
        return function() {
        };
      }
      var active = document.activeElement;
      var ranges = [];
      for (var i = 0; i < selection.rangeCount; i++) {
        ranges.push(selection.getRangeAt(i));
      }
      switch (active.tagName.toUpperCase()) {
        case "INPUT":
        case "TEXTAREA":
          active.blur();
          break;
        default:
          active = null;
          break;
      }
      selection.removeAllRanges();
      return function() {
        selection.type === "Caret" && selection.removeAllRanges();
        if (!selection.rangeCount) {
          ranges.forEach(function(range) {
            selection.addRange(range);
          });
        }
        active && active.focus();
      };
    };
  }
});

// ../../node_modules/copy-to-clipboard/index.js
var require_copy_to_clipboard = __commonJS({
  "../../node_modules/copy-to-clipboard/index.js"(exports, module) {
    "use strict";
    var deselectCurrent = require_toggle_selection();
    var clipboardToIE11Formatting = {
      "text/plain": "Text",
      "text/html": "Url",
      "default": "Text"
    };
    var defaultMessage = "Copy to clipboard: #{key}, Enter";
    function format(message) {
      var copyKey = (/mac os x/i.test(navigator.userAgent) ? "\u2318" : "Ctrl") + "+C";
      return message.replace(/#{\s*key\s*}/g, copyKey);
    }
    function copy(text, options) {
      var debug, message, reselectPrevious, range, selection, mark, success = false;
      if (!options) {
        options = {};
      }
      debug = options.debug || false;
      try {
        reselectPrevious = deselectCurrent();
        range = document.createRange();
        selection = document.getSelection();
        mark = document.createElement("span");
        mark.textContent = text;
        mark.ariaHidden = "true";
        mark.style.all = "unset";
        mark.style.position = "fixed";
        mark.style.top = 0;
        mark.style.clip = "rect(0, 0, 0, 0)";
        mark.style.whiteSpace = "pre";
        mark.style.webkitUserSelect = "text";
        mark.style.MozUserSelect = "text";
        mark.style.msUserSelect = "text";
        mark.style.userSelect = "text";
        mark.addEventListener("copy", function(e) {
          e.stopPropagation();
          if (options.format) {
            e.preventDefault();
            if (typeof e.clipboardData === "undefined") {
              debug && console.warn("unable to use e.clipboardData");
              debug && console.warn("trying IE specific stuff");
              window.clipboardData.clearData();
              var format2 = clipboardToIE11Formatting[options.format] || clipboardToIE11Formatting["default"];
              window.clipboardData.setData(format2, text);
            } else {
              e.clipboardData.clearData();
              e.clipboardData.setData(options.format, text);
            }
          }
          if (options.onCopy) {
            e.preventDefault();
            options.onCopy(e.clipboardData);
          }
        });
        document.body.appendChild(mark);
        range.selectNodeContents(mark);
        selection.addRange(range);
        var successful = document.execCommand("copy");
        if (!successful) {
          throw new Error("copy command was unsuccessful");
        }
        success = true;
      } catch (err) {
        debug && console.error("unable to copy using execCommand: ", err);
        debug && console.warn("trying IE specific stuff");
        try {
          window.clipboardData.setData(options.format || "text", text);
          options.onCopy && options.onCopy(window.clipboardData);
          success = true;
        } catch (err2) {
          debug && console.error("unable to copy using clipboardData: ", err2);
          debug && console.error("falling back to prompt");
          message = format("message" in options ? options.message : defaultMessage);
          window.prompt(message, text);
        }
      } finally {
        if (selection) {
          if (typeof selection.removeRange == "function") {
            selection.removeRange(range);
          } else {
            selection.removeAllRanges();
          }
        }
        if (mark) {
          document.body.removeChild(mark);
        }
        reselectPrevious();
      }
      return success;
    }
    module.exports = copy;
  }
});

// app/hooks/useMount.ts
init_remix_hmr();
if (import.meta) {
  import.meta.hot = createHotContext(
    //@ts-expect-error
    "app/hooks/useMount.ts"
  );
  import.meta.hot.lastModified = "1710795853618.504";
}
var useMount = (fn) => {
  useEffectOnce(() => {
    fn();
  });
};

// app/hooks/useRevalidateOnReconnect.ts
init_remix_hmr();
init_esm();
var import_react2 = __toESM(require_react(), 1);
if (import.meta) {
  import.meta.hot = createHotContext(
    //@ts-expect-error
    "app/hooks/useRevalidateOnReconnect.ts"
  );
  import.meta.hot.lastModified = "1710795853618.6821";
}
var useRevalidateOnReconnect = () => {
  const { revalidate } = useRevalidator();
  (0, import_react2.useEffect)(() => {
    window.addEventListener("online", revalidate);
    return () => {
      window.removeEventListener("online", revalidate);
    };
  }, [revalidate]);
};

// app/hooks/useRevalidateOnFocus.ts
init_remix_hmr();
init_esm();
var import_react4 = __toESM(require_react(), 1);
if (import.meta) {
  import.meta.hot = createHotContext(
    //@ts-expect-error
    "app/hooks/useRevalidateOnFocus.ts"
  );
  import.meta.hot.lastModified = "1710795853618.6357";
}
var useRevalidateOnFocus = () => {
  const { revalidate } = useRevalidator();
  (0, import_react4.useEffect)(() => {
    window.addEventListener("focus", revalidate);
    return () => {
      window.removeEventListener("focus", revalidate);
    };
  }, [revalidate]);
  (0, import_react4.useEffect)(() => {
    const onVisibilityChange = () => {
      if (document.visibilityState === "visible") {
        revalidate();
      }
    };
    window.addEventListener("visibilitychange", onVisibilityChange);
    return () => {
      window.removeEventListener("visibilitychange", onVisibilityChange);
    };
  }, [revalidate]);
};

// app/hooks/index.ts
init_remix_hmr();

// app/hooks/useCopyToClipboard.ts
init_remix_hmr();
var import_copy_to_clipboard = __toESM(require_copy_to_clipboard(), 1);
var import_react7 = __toESM(require_react(), 1);

// app/hooks/useMountedState.ts
init_remix_hmr();
var import_react5 = __toESM(require_react(), 1);
if (import.meta) {
  import.meta.hot = createHotContext(
    //@ts-expect-error
    "app/hooks/useMountedState.ts"
  );
  import.meta.hot.lastModified = "1710795853618.5469";
}
var useMountedState = () => {
  const mountedRef = (0, import_react5.useRef)(false);
  const get = (0, import_react5.useCallback)(() => mountedRef.current, []);
  (0, import_react5.useEffect)(() => {
    mountedRef.current = true;
    return () => {
      mountedRef.current = false;
    };
  }, []);
  return get;
};

// app/hooks/useSetState.ts
init_remix_hmr();
var import_react6 = __toESM(require_react(), 1);
if (import.meta) {
  import.meta.hot = createHotContext(
    //@ts-expect-error
    "app/hooks/useSetState.ts"
  );
  import.meta.hot.lastModified = "1710795853618.7314";
}
var useSetState = (initialState = {}) => {
  const [state, set] = (0, import_react6.useState)(initialState);
  const setState = (0, import_react6.useCallback)((patch) => {
    set((prevState) => Object.assign({}, prevState, patch instanceof Function ? patch(prevState) : patch));
  }, []);
  return [state, setState];
};

// app/hooks/useCopyToClipboard.ts
if (import.meta) {
  import.meta.hot = createHotContext(
    //@ts-expect-error
    "app/hooks/useCopyToClipboard.ts"
  );
  import.meta.hot.lastModified = "1710795853618.1943";
}
var useCopyToClipboard = () => {
  const isMounted = useMountedState();
  const [state, setState] = useSetState({
    value: void 0,
    error: void 0,
    noUserInteraction: true
  });
  const copyToClipboard = (0, import_react7.useCallback)((value) => {
    if (!isMounted()) {
      return;
    }
    let noUserInteraction;
    let normalizedValue;
    try {
      if (typeof value !== "string" && typeof value !== "number") {
        const error = new Error(`Cannot copy typeof ${typeof value} to clipboard, must be a string`);
        if (true)
          console.error(error);
        setState({
          value,
          error,
          noUserInteraction: true
        });
        return;
      } else if (value === "") {
        const error = new Error(`Cannot copy empty string to clipboard.`);
        if (true)
          console.error(error);
        setState({
          value,
          error,
          noUserInteraction: true
        });
        return;
      }
      normalizedValue = value.toString();
      noUserInteraction = (0, import_copy_to_clipboard.default)(normalizedValue);
      setState({
        value: normalizedValue,
        error: void 0,
        noUserInteraction
      });
    } catch (error) {
      setState({
        value: normalizedValue,
        error,
        noUserInteraction
      });
    }
  }, []);
  return [state, copyToClipboard];
};

// app/hooks/useFetcherWithReset.ts
init_remix_hmr();
init_esm();
var import_react9 = __toESM(require_react(), 1);
if (import.meta) {
  import.meta.hot = createHotContext(
    //@ts-expect-error
    "app/hooks/useFetcherWithReset.ts"
  );
  import.meta.hot.lastModified = "1710795853618.4194";
}
function useFetcherWithReset(opts) {
  const fetcher = useFetcher(opts);
  const [data, setData] = (0, import_react9.useState)(fetcher.data);
  (0, import_react9.useEffect)(() => {
    if (fetcher.state === "idle") {
      setData(fetcher.data);
    }
  }, [fetcher.state, fetcher.data]);
  return {
    ...fetcher,
    data,
    reset: () => setData(void 0)
  };
}

// app/hooks/useKey.ts
init_remix_hmr();
var import_react11 = __toESM(require_react(), 1);

// app/hooks/useEvent.ts
init_remix_hmr();
var import_react10 = __toESM(require_react(), 1);

// app/hooks/misc/util.ts
init_remix_hmr();
if (import.meta) {
  import.meta.hot = createHotContext(
    //@ts-expect-error
    "app/hooks/misc/util.ts"
  );
  import.meta.hot.lastModified = "1710795853618.1538";
}
function on(obj, ...args) {
  if (obj && obj.addEventListener) {
    obj.addEventListener(...args);
  }
}
function off(obj, ...args) {
  if (obj && obj.removeEventListener) {
    obj.removeEventListener(...args);
  }
}
var isBrowser = typeof window !== "undefined";

// app/hooks/useEvent.ts
if (import.meta) {
  import.meta.hot = createHotContext(
    //@ts-expect-error
    "app/hooks/useEvent.ts"
  );
  import.meta.hot.lastModified = "1711033456007.6113";
}
var defaultTarget = isBrowser ? window : null;
var isListenerType1 = (target) => {
  return !!target.addEventListener;
};
var isListenerType2 = (target) => {
  return !!target.on;
};
var useEvent = (name, handler, target = defaultTarget, options) => {
  (0, import_react10.useEffect)(() => {
    if (!handler) {
      return;
    }
    if (!target) {
      return;
    }
    if (isListenerType1(target)) {
      on(target, name, handler, options);
    } else if (isListenerType2(target)) {
      target.on(name, handler, options);
    }
    return () => {
      if (isListenerType1(target)) {
        off(target, name, handler, options);
      } else if (isListenerType2(target)) {
        target.off(name, handler, options);
      }
    };
  }, [name, handler, target, JSON.stringify(options)]);
};
var useEvent_default = useEvent;

// app/hooks/useKey.ts
if (import.meta) {
  import.meta.hot = createHotContext(
    //@ts-expect-error
    "app/hooks/useKey.ts"
  );
  import.meta.hot.lastModified = "1711033456007.7192";
}
var createKeyPredicate = (keyFilter) => typeof keyFilter === "function" ? keyFilter : typeof keyFilter === "string" ? (event) => event.key === keyFilter : keyFilter ? () => true : () => false;
var useKey = (key, fn = () => {
}, opts = {}, deps = [key]) => {
  const { event = "keydown", target, options } = opts;
  const useMemoHandler = (0, import_react11.useMemo)(() => {
    const predicate = createKeyPredicate(key);
    const handler = (handlerEvent) => {
      if (predicate(handlerEvent)) {
        return fn(handlerEvent);
      }
    };
    return handler;
  }, deps);
  useEvent_default(event, useMemoHandler, target, options);
};

// app/hooks/index.ts
if (import.meta) {
  import.meta.hot = createHotContext(
    //@ts-expect-error
    "app/hooks/index.ts"
  );
  import.meta.hot.lastModified = "1710795853618.0906";
}

export {
  useCopyToClipboard,
  useFetcherWithReset,
  useKey,
  useMount,
  useRevalidateOnReconnect,
  useRevalidateOnFocus
};
//# sourceMappingURL=/build/_shared/chunk-B7TG3BDD.js.map
