import { _objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { _objectWithoutProperties } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js";
import Badge$1 from "../badge/index.js";
import { warning } from "../../utils/warning.js";
import React, { Component } from "react";
import { Tabs } from "antd";
import classNames from "classnames";
import "./index.less";
//#region src/components/tabs/index.tsx
const _excluded = ["tab"];
const prefix = "pisell-lowcode-";
var Tabs$1 = class extends Component {
	constructor(..._args) {
		var _this$props$activeKey;
		super(..._args);
		this.state = { activeKey: (_this$props$activeKey = this.props.activeKey) !== null && _this$props$activeKey !== void 0 ? _this$props$activeKey : this.props.defaultActiveKey };
		this._handleChange = (key) => {
			this.setActiveKey(key);
		};
		this.setActiveKey = (key) => {
			const { onChange = () => {} } = this.props;
			this.setState({ activeKey: key });
			onChange(key);
		};
		this.getActiveKey = () => {
			return this.state.activeKey;
		};
		this.renderIconLabelTabBar = (props, DefaultTabBar) => {
			var _this$props;
			const { items, sidebarWidth } = this.props;
			let wrapStyle = { gap: props.tabBarGutter };
			if (["left", "right"].includes(props.tabPosition)) wrapStyle = _objectSpread2(_objectSpread2({}, wrapStyle), {}, { width: sidebarWidth || 130 });
			return /* @__PURE__ */ React.createElement("div", {
				className: classNames("pisell-lowcode-tabs-nav", `${prefix}tab-bar-wrap`, `${prefix}tab-bar-wrap-${props.tabPosition}`, (_this$props = this.props) === null || _this$props === void 0 ? void 0 : _this$props.className),
				style: wrapStyle
			}, this.filterHiddenTabs(items).map((item) => {
				return /* @__PURE__ */ React.createElement("div", {
					className: classNames(`${prefix}tab-bar-item`, { [`${prefix}tab-bar-item-active`]: item.key === props.activeKey }),
					key: item.key,
					onClick: (e) => props.onTabClick(item.key, e)
				}, /* @__PURE__ */ React.createElement(Badge$1, {
					count: item.badge,
					offset: [0, 6]
				}, /* @__PURE__ */ React.createElement("div", { className: `${prefix}tab-bar-icon-wrap` }, item.icon)), /* @__PURE__ */ React.createElement("span", { className: `${prefix}tab-bar-label` }, item.label));
			}), props.extra);
		};
		this.filterHiddenTabs = (tabs) => {
			return tabs.filter((item) => !item.hidden);
		};
	}
	componentDidMount() {
		document.body.id = "body";
	}
	componentDidUpdate(prevProps) {
		if (prevProps.activeKey !== this.props.activeKey) this.setState({ activeKey: this.props.activeKey });
	}
	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) {
			warning("Tabs.TabPane is deprecated. Please use `items` directly.");
			items = children.map((node) => {
				if (React.isValidElement(node)) {
					const { key, props } = node;
					const _ref = props || {}, { tab } = _ref, restProps = _objectWithoutProperties(_ref, _excluded);
					return _objectSpread2(_objectSpread2({ key: String(key) }, restProps), {}, { label: tab });
				}
				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 _objectSpread2(_objectSpread2({}, item), {}, { label: /* @__PURE__ */ React.createElement("div", { style: { margin: "0 9px" } }, /* @__PURE__ */ React.createElement(Badge$1, {
				styleType: "default",
				count: item.badge,
				offset: [18, 10]
			}, /* @__PURE__ */ React.createElement("span", { className: `${prefix}tab-bar-label` }, item.label))) });
		});
		return /* @__PURE__ */ React.createElement(Tabs, _objectSpread2(_objectSpread2(_objectSpread2({}, props), otherProps), {}, {
			items,
			activeKey,
			onChange: this._handleChange
		}));
	}
};
Tabs$1.TabPane = Tabs.TabPane;
//#endregion
export { Tabs$1 as default };
