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/PisellTabbar2/hooks/useActiveKey.ts
var useActiveKey_exports = {};
__export(useActiveKey_exports, {
  default: () => useActiveKey_default
});
module.exports = __toCommonJS(useActiveKey_exports);
var import_react = require("react");
var useActiveKey = (props) => {
  const { initialActiveKey = [], onChange } = props;
  const [activeKey, _setActiveKey] = (0, import_react.useState)(initialActiveKey);
  const [panelVisible, setPanelVisible] = (0, import_react.useState)(false);
  const setActiveKey = (level, key, cKey) => {
    const newActiveKey = [...activeKey];
    if (key === newActiveKey[level]) {
      if (level === 0 || level === 1) {
        setPanelVisible(!panelVisible);
        return;
      }
      return;
    }
    if (level === 0) {
      setPanelVisible(true);
    }
    if (level === 1) {
      setPanelVisible(false);
    }
    newActiveKey.splice(level + 1);
    newActiveKey[level] = String(key);
    if (cKey !== void 0) {
      newActiveKey[level + 1] = String(cKey);
      if (level === 0) {
        newActiveKey[level + 2] = String(0);
      }
    }
    _setActiveKey(newActiveKey);
    onChange == null ? void 0 : onChange(newActiveKey);
  };
  const getActiveKey = (level) => {
    return activeKey[level];
  };
  return {
    activeKey,
    setActiveKey,
    getActiveKey,
    panelVisible,
    /**
     * 内部设置方法，用于同步外部传入的 value
     * 会进行深比较，避免不必要的更新
     */
    _setActiveKey: (value) => {
      if (JSON.stringify(value) !== JSON.stringify(activeKey)) {
        _setActiveKey(value || initialActiveKey);
      }
    }
  };
};
var useActiveKey_default = useActiveKey;
