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/components/pisellLookup/hooks/useSearchState.ts
var useSearchState_exports = {};
__export(useSearchState_exports, {
  useSearchState: () => useSearchState
});
module.exports = __toCommonJS(useSearchState_exports);
var import_react = require("react");
var useSearchState = (options) => {
  const {
    value,
    defaultValue = "",
    visible: visibleProp,
    defaultVisible = false,
    onChange,
    onVisibleChange,
    onOpen,
    onClose
  } = options;
  const isControlledKeyword = value !== void 0;
  const isControlledVisible = visibleProp !== void 0;
  const [internalKeyword, setInternalKeyword] = (0, import_react.useState)(defaultValue);
  const [internalVisible, setInternalVisible] = (0, import_react.useState)(defaultVisible);
  const keyword = isControlledKeyword ? value : internalKeyword;
  const visible = isControlledVisible ? visibleProp : internalVisible;
  const setKeyword = (0, import_react.useCallback)(
    (newValue) => {
      if (!isControlledKeyword) {
        setInternalKeyword(newValue);
      }
      onChange == null ? void 0 : onChange(newValue);
    },
    [isControlledKeyword, onChange]
  );
  const setVisible = (0, import_react.useCallback)(
    (newVisible) => {
      const oldVisible = visible;
      if (!isControlledVisible) {
        setInternalVisible(newVisible);
      }
      onVisibleChange == null ? void 0 : onVisibleChange(newVisible);
      if (newVisible && !oldVisible) {
        onOpen == null ? void 0 : onOpen();
      } else if (!newVisible && oldVisible) {
        onClose == null ? void 0 : onClose();
      }
    },
    [isControlledVisible, visible, onVisibleChange, onOpen, onClose]
  );
  const open = (0, import_react.useCallback)(() => {
    setVisible(true);
  }, [setVisible]);
  const close = (0, import_react.useCallback)(() => {
    setVisible(false);
  }, [setVisible]);
  const toggle = (0, import_react.useCallback)(() => {
    setVisible(!visible);
  }, [setVisible, visible]);
  return {
    keyword,
    setKeyword,
    visible,
    setVisible,
    open,
    close,
    toggle,
    isControlledKeyword,
    isControlledVisible
  };
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useSearchState
});
