var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/PisellTabbar2/PisellTabbar.tsx
var PisellTabbar_exports = {};
__export(PisellTabbar_exports, {
  default: () => PisellTabbar_default
});
module.exports = __toCommonJS(PisellTabbar_exports);
var import_react = __toESM(require("react"));
var import_classnames = __toESM(require("classnames"));
var import_components = require("./components");
var import_hooks = require("./hooks");
var import_utils = require("./utils");
var import_constants = require("./constants");
var import_mock = __toESM(require("./mock"));
var import_PisellTabbar = require("./PisellTabbar.less");
var PisellTabbar = (props) => {
  const {
    dataSource = (props == null ? void 0 : props.__designMode) ? import_mock.default : import_mock.default,
    value,
    onChange,
    className,
    style,
    levelConfig: customLevelConfig,
    expandConfig,
    maxLevel = 3
  } = props;
  const { setActiveKey, getActiveKey, _setActiveKey, panelVisible, activeKey } = (0, import_hooks.useActiveKey)({
    initialActiveKey: value || (0, import_utils.getDefaultActiveKey)(dataSource, "id"),
    onChange
  });
  const { expand, toggleExpand, getExpand } = (0, import_hooks.useExpand)();
  console.log("panelVisiblepanelVisible", panelVisible);
  (0, import_react.useEffect)(() => {
    if (value) {
      _setActiveKey(value);
    }
  }, [JSON.stringify(value)]);
  const getLevelConfig = (0, import_react.useCallback)(
    (level) => {
      return {
        ...import_constants.DEFAULT_LEVEL_CONFIG[level],
        ...customLevelConfig == null ? void 0 : customLevelConfig[level]
      };
    },
    [customLevelConfig]
  );
  const handleLevel1Change = (0, import_react.useCallback)(
    (key, item) => {
      var _a, _b;
      if (item.childrenMaxLevel !== void 0 && item.childrenMaxLevel < 2) {
        setActiveKey(0, key, 0);
      } else {
        setActiveKey(
          0,
          key,
          ((_a = item == null ? void 0 : item.children) == null ? void 0 : _a.length) ? (_b = item == null ? void 0 : item.children[0]) == null ? void 0 : _b.id : void 0
        );
      }
    },
    [setActiveKey]
  );
  const handleLevel2Change = (0, import_react.useCallback)(
    (key, item) => {
      var _a;
      setActiveKey(1, key, ((_a = item == null ? void 0 : item.children) == null ? void 0 : _a.length) ? 0 : void 0);
    },
    [setActiveKey]
  );
  const handleLevel3Change = (0, import_react.useCallback)(
    (key) => {
      setActiveKey(2, key);
    },
    [setActiveKey]
  );
  const level1DataSource = (0, import_react.useMemo)(
    () => (0, import_utils.addDataSourceItemsByKey)(dataSource, import_constants.LEVEL_ADD_ITEMS.level1),
    [dataSource]
  );
  const renderLevel2 = (0, import_react.useCallback)(
    (panelProps) => {
      if (maxLevel < 2) return null;
      const childrenMaxLevel = panelProps.dataSource.childrenMaxLevel || 2;
      if (childrenMaxLevel < 2) {
        return renderLevel3(panelProps, true);
      }
      let _dataSource = panelProps.dataSource.children || [];
      if (_dataSource.length) {
        _dataSource = (0, import_utils.addDataSourceItemsByKey)(
          _dataSource,
          import_constants.LEVEL_ADD_ITEMS.level2
        );
      }
      return /* @__PURE__ */ import_react.default.createElement(
        import_components.TabbarLevel,
        {
          skuId: `sku-list-tabbar-${panelProps.dataSource.id}`,
          dataSource: _dataSource,
          activePanelKey: getActiveKey(1),
          level: "level2",
          setActivePanelKey: handleLevel2Change,
          expand: getExpand("level2"),
          handleExpand: () => toggleExpand("level2"),
          renderChildren: renderLevel3,
          levelConfig: getLevelConfig("level2"),
          expandConfig,
          positionId: getLevelConfig("level2").positionId,
          superTabsProps: {
            className: "pisell-tabbar-level-2",
            style: {
              width: "104px"
            },
            gridProps: {
              direction: "vertical",
              style: {
                padding: "16px 4px"
              },
              gap: 12
            },
            startSlot: null,
            scrollViewProps: {
              overflow: "y",
              width: "100%",
              height: "100%",
              style: {
                padding: 0
              },
              scrollActionsConfig: {
                type: "tbArrows",
                show: true
              }
            }
          }
        }
      );
    },
    [
      maxLevel,
      getActiveKey,
      handleLevel2Change,
      getExpand,
      toggleExpand,
      getLevelConfig,
      expandConfig
    ]
  );
  const renderLevel3 = (0, import_react.useCallback)(
    (panelProps2, isLevel2) => {
      if (maxLevel < 3) return null;
      let _dataSource2 = panelProps2.dataSource.children || [];
      if (_dataSource2.length) {
        _dataSource2 = (0, import_utils.addDataSourceItemsByKey)(
          _dataSource2,
          import_constants.LEVEL_ADD_ITEMS.level3
        );
      }
      return /* @__PURE__ */ import_react.default.createElement(
        import_components.TabbarLevel,
        {
          skuId: `sku-list-tabbar-${panelProps2.dataSource.id}`,
          dataSource: _dataSource2,
          activePanelKey: getActiveKey(isLevel2 ? 1 : 2),
          level: "level3",
          setActivePanelKey: isLevel2 ? handleLevel2Change : handleLevel3Change,
          expand: getExpand(isLevel2 ? "level2" : "level3"),
          handleExpand: () => toggleExpand(isLevel2 ? "level2" : "level3"),
          levelConfig: getLevelConfig("level3"),
          expandConfig,
          positionId: getLevelConfig(isLevel2 ? "level2" : "level3").positionId
        }
      );
    },
    [
      maxLevel,
      getActiveKey,
      handleLevel3Change,
      getExpand,
      toggleExpand,
      getLevelConfig,
      expandConfig
    ]
  );
  (0, import_react.useEffect)(() => {
    document.body.id = "body";
  }, []);
  console.log("activeKeyactiveKey", activeKey);
  return dataSource.length ? /* @__PURE__ */ import_react.default.createElement("div", { className: (0, import_classnames.default)("pisell-tabbar2", className), style }, /* @__PURE__ */ import_react.default.createElement(
    import_components.TabbarLevel,
    {
      skuId: "sku-list-tabbar",
      dataSource: level1DataSource,
      activePanelKey: getActiveKey(0),
      level: "level1",
      setActivePanelKey: handleLevel1Change,
      expand: getExpand("level1"),
      handleExpand: () => toggleExpand("level1"),
      renderChildren: renderLevel2,
      levelConfig: getLevelConfig("level1"),
      expandConfig,
      superTabsProps: {
        gridProps: {
          direction: "vertical",
          style: {
            padding: "16px 4px"
          },
          gap: 12
        },
        panelStyle: {
          position: "absolute",
          top: 40,
          right: 0,
          height: "calc(100% - 40px)",
          transition: "0.3s ease-in-out"
        },
        startSlot: null,
        scrollViewProps: {
          overflow: "y",
          width: "100%",
          height: "100%",
          style: {
            padding: 0
          },
          scrollActionsConfig: {
            type: "tbArrows",
            show: true
          }
        }
      },
      positionId: getLevelConfig("level1").positionId,
      level2PositionId: getLevelConfig("level2").positionId,
      panelVisible
    }
  )) : null;
};
PisellTabbar.displayName = "PisellTabbar";
PisellTabbar.getDefaultActiveKey = import_utils.getDefaultActiveKey;
var PisellTabbar_default = PisellTabbar;
