const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_objectWithoutProperties = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js");
const require_index = require("../../../badge/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
require("./TabCard.less");
//#region src/components/PisellCards/components/TabCard/TabCard.tsx
const _excluded = [
	"tabKey",
	"label",
	"icon",
	"badge",
	"onClick",
	"direction",
	"size",
	"render",
	"active",
	"disabled",
	"loading",
	"className",
	"style",
	"children",
	"dataSource"
];
/**
* TabCard 标签卡片组件
* 用于导航、分类切换、筛选等场景
*
* @example
* ```tsx
* <TabCard
*   tabKey="home"
*   label="首页"
*   icon={<HomeOutlined />}
*   active={{ value: true }}
*   onClick={(key) => console.log(key)}
* />
* ```
*/
const TabCard = (props) => {
	const { tabKey, label, icon, badge, onClick, direction = "horizontal", size = "medium", render, active, disabled, loading, className, style, children, dataSource } = props, restProps = require_objectWithoutProperties._objectWithoutProperties(props, _excluded);
	(0, react.useEffect)(() => {
		document.body.id = "body";
	}, []);
	console.log("propsprops", props);
	/**
	* 合并状态样式
	* 优先级：loading > disabled > active
	*/
	const mergedStyle = (0, react.useMemo)(() => {
		let finalStyle = require_objectSpread2._objectSpread2({}, style);
		if ((loading === null || loading === void 0 ? void 0 : loading.value) && (loading === null || loading === void 0 ? void 0 : loading.style)) finalStyle = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, finalStyle), loading.style);
		else if ((disabled === null || disabled === void 0 ? void 0 : disabled.value) && (disabled === null || disabled === void 0 ? void 0 : disabled.style)) finalStyle = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, finalStyle), disabled.style);
		else if ((active === null || active === void 0 ? void 0 : active.value) && (active === null || active === void 0 ? void 0 : active.style)) finalStyle = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, finalStyle), active.style);
		return finalStyle;
	}, [
		style,
		active,
		disabled,
		loading
	]);
	/**
	* 合并状态类名
	*/
	const mergedClassName = (0, react.useMemo)(() => {
		return (0, classnames.default)("tab-card", `tab-card--${direction}`, `tab-card--${size}`, className, {
			"tab-card--active": active === null || active === void 0 ? void 0 : active.value,
			"tab-card--disabled": disabled === null || disabled === void 0 ? void 0 : disabled.value,
			"tab-card--loading": loading === null || loading === void 0 ? void 0 : loading.value
		}, (active === null || active === void 0 ? void 0 : active.value) && (active === null || active === void 0 ? void 0 : active.className), (disabled === null || disabled === void 0 ? void 0 : disabled.value) && (disabled === null || disabled === void 0 ? void 0 : disabled.className), (loading === null || loading === void 0 ? void 0 : loading.value) && (loading === null || loading === void 0 ? void 0 : loading.className));
	}, [
		className,
		direction,
		size,
		active,
		disabled,
		loading
	]);
	/**
	* 处理点击事件
	*/
	const handleClick = (0, react.useCallback)((e) => {
		if ((loading === null || loading === void 0 ? void 0 : loading.value) || (disabled === null || disabled === void 0 ? void 0 : disabled.value)) {
			e.preventDefault();
			return;
		}
		if ((active === null || active === void 0 ? void 0 : active.onChange) && !active.value) active.onChange(true);
		if (onClick) onClick(tabKey, e);
	}, [
		tabKey,
		onClick,
		active,
		loading,
		disabled
	]);
	/**
	* 渲染状态的 extra 内容
	* 优先级：loading > disabled > active
	*/
	const renderExtra = (0, react.useCallback)(() => {
		if ((loading === null || loading === void 0 ? void 0 : loading.value) && (loading === null || loading === void 0 ? void 0 : loading.extra)) return /* @__PURE__ */ react.default.createElement("div", { className: "tab-card__extra" }, loading.extra);
		if ((disabled === null || disabled === void 0 ? void 0 : disabled.value) && (disabled === null || disabled === void 0 ? void 0 : disabled.extra)) return /* @__PURE__ */ react.default.createElement("div", { className: "tab-card__extra" }, disabled.extra);
		if ((active === null || active === void 0 ? void 0 : active.value) && (active === null || active === void 0 ? void 0 : active.extra)) return /* @__PURE__ */ react.default.createElement("div", { className: "tab-card__extra" }, active.extra);
		return null;
	}, [
		active,
		disabled,
		loading
	]);
	/**
	* 渲染标签内容
	*/
	const renderContent = (0, react.useCallback)(() => {
		if (render) return render(props);
		return /* @__PURE__ */ react.default.createElement("div", { className: "tab-card__content" }, icon && /* @__PURE__ */ react.default.createElement("div", { className: "tab-card__icon" }, icon), /* @__PURE__ */ react.default.createElement("div", { className: "tab-card__label-wrapper" }, badge ? /* @__PURE__ */ react.default.createElement(require_index.default, {
			count: badge.count,
			dot: badge.dot,
			color: badge.color,
			offset: badge.offset
		}, /* @__PURE__ */ react.default.createElement("span", { className: "tab-card__label" }, label)) : /* @__PURE__ */ react.default.createElement("span", { className: "tab-card__label" }, label)));
	}, [
		icon,
		label,
		badge,
		render,
		props
	]);
	return /* @__PURE__ */ react.default.createElement("div", require_objectSpread2._objectSpread2({
		className: mergedClassName,
		style: mergedStyle,
		onClick: handleClick,
		"data-active": active === null || active === void 0 ? void 0 : active.value,
		"data-disabled": disabled === null || disabled === void 0 ? void 0 : disabled.value,
		"data-loading": loading === null || loading === void 0 ? void 0 : loading.value,
		"data-tab-key": tabKey,
		role: "tab",
		"aria-selected": active === null || active === void 0 ? void 0 : active.value,
		"aria-disabled": disabled === null || disabled === void 0 ? void 0 : disabled.value,
		tabIndex: (disabled === null || disabled === void 0 ? void 0 : disabled.value) ? -1 : 0
	}, restProps), renderContent(), renderExtra(), children);
};
const Provider = (props) => /* @__PURE__ */ react.default.createElement(TabCard, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, props === null || props === void 0 ? void 0 : props.props), props));
//#endregion
exports.default = Provider;
