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/tabs/index.tsx
var tabs_exports = {};
__export(tabs_exports, {
  default: () => tabs_default
});
module.exports = __toCommonJS(tabs_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_warning = require("../../utils/warning");
var import_badge = __toESM(require("./../badge"));
var import_classnames = __toESM(require("classnames"));
var import_index = require("./index.less");
var prefix = "pisell-lowcode-";
var Tabs = class extends import_react.Component {
  state = {
    activeKey: this.props.activeKey ?? this.props.defaultActiveKey
  };
  componentDidMount() {
    document.body.id = "body";
  }
  componentDidUpdate(prevProps) {
    if (prevProps.activeKey !== this.props.activeKey) {
      this.setState({ activeKey: this.props.activeKey });
    }
  }
  _handleChange = (key) => {
    this.setActiveKey(key);
  };
  // 编辑器里可以通过 this.$(refId).setActiveKey(key) 调用
  setActiveKey = (key) => {
    const { onChange = () => {
    } } = this.props;
    this.setState({ activeKey: key });
    onChange(key);
  };
  // 编辑器里可以通过 this.$(refId).getActiveKey() 调用
  getActiveKey = () => {
    return this.state.activeKey;
  };
  renderIconLabelTabBar = (props, DefaultTabBar) => {
    var _a;
    const { items, sidebarWidth } = this.props;
    let wrapStyle = {
      gap: props.tabBarGutter
    };
    if (["left", "right"].includes(props.tabPosition)) {
      wrapStyle = {
        ...wrapStyle,
        width: sidebarWidth || 130
      };
    }
    return /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: (0, import_classnames.default)(
          "pisell-lowcode-tabs-nav",
          `${prefix}tab-bar-wrap`,
          `${prefix}tab-bar-wrap-${props.tabPosition}`,
          (_a = this.props) == null ? void 0 : _a.className
        ),
        style: wrapStyle
      },
      this.filterHiddenTabs(items).map((item) => {
        return /* @__PURE__ */ import_react.default.createElement(
          "div",
          {
            className: (0, import_classnames.default)(`${prefix}tab-bar-item`, {
              [`${prefix}tab-bar-item-active`]: item.key === props.activeKey
            }),
            key: item.key,
            onClick: (e) => props.onTabClick(item.key, e)
          },
          /* @__PURE__ */ import_react.default.createElement(import_badge.default, { count: item.badge, offset: [0, 6] }, /* @__PURE__ */ import_react.default.createElement("div", { className: `${prefix}tab-bar-icon-wrap` }, item.icon)),
          /* @__PURE__ */ import_react.default.createElement("span", { className: `${prefix}tab-bar-label` }, item.label)
        );
      }),
      props.extra
    );
  };
  filterHiddenTabs = (tabs) => {
    return tabs.filter((item) => !item.hidden);
  };
  render() {
    const { props } = this;
    const { activeKey } = this.state;
    const { children, type } = props;
    let items = props.items;
    let otherProps = {};
    if (!props.items && Array.isArray(children) && children.length > 0) {
      (0, import_warning.warning)("Tabs.TabPane is deprecated. Please use `items` directly.");
      items = children.map((node) => {
        if (import_react.default.isValidElement(node)) {
          const { key, props: props2 } = node;
          const { tab, ...restProps } = props2 || {};
          const item = {
            key: String(key),
            ...restProps,
            label: tab
          };
          return item;
        }
        return null;
      }).filter(Boolean);
    }
    items = this.filterHiddenTabs(items);
    if (type === "icon-label") {
      otherProps = {
        renderTabBar: this.renderIconLabelTabBar,
        type: "line"
      };
    }
    if (type === "line") {
      items = items.map((item) => {
        return {
          ...item,
          label: /* @__PURE__ */ import_react.default.createElement("div", { style: { margin: "0 9px" } }, /* @__PURE__ */ import_react.default.createElement(import_badge.default, { styleType: "default", count: item.badge, offset: [18, 10] }, /* @__PURE__ */ import_react.default.createElement("span", { className: `${prefix}tab-bar-label` }, item.label)))
        };
      });
    }
    return /* @__PURE__ */ import_react.default.createElement(
      import_antd.Tabs,
      {
        ...props,
        ...otherProps,
        items,
        activeKey,
        onChange: this._handleChange
      }
    );
  }
};
Tabs.TabPane = import_antd.Tabs.TabPane;
var tabs_default = Tabs;
