import { _objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import MemoizedPisellBasicGrid from "../PisellBasicGrid/PisellBasicGrid.js";
import PisellScrollView_default from "../PisellScrollView/index.js";
import { useTabsState } from "./hooks/useTabsState.js";
import { getRowKey } from "./utils/getRowKey.js";
import React, { forwardRef, useImperativeHandle, useRef } from "react";
import classNames from "classnames";
import "./PisellSuperTabs.less";
//#region src/components/PisellSuperTabs/PisellSuperTabs.tsx
/**
* PisellSuperTabs 组件
* @description 通用导航框架封装的全能型 Tab 组件
* @template T - 数据源项的类型
*/
const PisellSuperTabs = (props, ref) => {
	const { className, style, dataSource = [], rowKey = "key", value, id, defaultValue, onChange, renderItem, gridProps = {}, scrollViewProps = {}, children, slotLeft, slotRight, slotTop, slotBottom, tabItemClassName, tabItemStyle, slotLeftClassName, slotRightClassName, slotTopClassName, slotBottomClassName, slotLeftStyle, slotRightStyle, slotTopStyle, slotBottomStyle, isControlled = true, __designMode } = props;
	const containerRef = useRef(null);
	const { activeKey, handleTabChange } = useTabsState({
		value,
		defaultValue,
		onChange,
		isControlled: isControlled !== null && isControlled !== void 0 ? isControlled : false
	});
	const scrollItemByRowKey = (key) => {
		const item = document.querySelector(`.pisell-super-tabs-item-${id}-${key}`);
		console.log(`.pisell-super-tabs-item-${id}-${key}`);
		if (item) item.scrollIntoView({ behavior: "smooth" });
	};
	useImperativeHandle(ref, () => {
		if (__designMode) return containerRef.current;
		return { scrollItemByRowKey };
	});
	return /* @__PURE__ */ React.createElement("div", {
		className: classNames("pisell-super-tabs", className),
		style,
		id,
		ref: containerRef
	}, /* @__PURE__ */ React.createElement("div", {
		className: classNames("pisell-super-tabs-slot-top-" + id, slotTopClassName),
		style: slotTopStyle
	}, slotTop), /* @__PURE__ */ React.createElement("div", {
		className: classNames("pisell-super-tabs-slot-left-" + id, slotLeftClassName),
		style: slotLeftStyle
	}, slotLeft), /* @__PURE__ */ React.createElement(PisellScrollView_default, scrollViewProps, /* @__PURE__ */ React.createElement(MemoizedPisellBasicGrid, _objectSpread2(_objectSpread2({}, gridProps), {}, {
		dataSource,
		rowKey,
		renderItem: (item, index) => {
			const key = getRowKey(item, index, rowKey);
			const active = key === String(activeKey);
			let content;
			if (renderItem) if (typeof renderItem === "function") content = renderItem({
				dataSource: item,
				index,
				onClick: () => {
					if (item.customClick) return;
					handleTabChange(key, item);
				},
				tabsState: {
					activeKey,
					handleTabChange
				},
				tabsProps: props,
				active: { value: active }
			});
			else content = renderItem;
			else content = item["label"];
			return /* @__PURE__ */ React.createElement("div", {
				key,
				className: classNames("pisell-super-tabs-item", `pisell-super-tabs-item-${id}-${key}`, { "pisell-super-tabs-item--active": active }, tabItemClassName),
				style: tabItemStyle
			}, content);
		}
	}))), /* @__PURE__ */ React.createElement("div", { className: "pisell-super-tabs-content" }, children), /* @__PURE__ */ React.createElement("div", {
		className: classNames("pisell-super-tabs-slot-right-" + id, slotRightClassName),
		style: slotRightStyle
	}, slotRight), /* @__PURE__ */ React.createElement("div", {
		className: classNames("pisell-super-tabs-slot-bottom-" + id, slotBottomClassName),
		style: slotBottomStyle
	}, slotBottom));
};
PisellSuperTabs.displayName = "PisellSuperTabs";
var PisellSuperTabs_default = forwardRef(PisellSuperTabs);
//#endregion
export { PisellSuperTabs_default as default };
