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 TextContent from "./components/TextContent.js";
import IconWrapper from "./components/IconWrapper.js";
import BadgeWrapper from "./components/BadgeWrapper.js";
import React, { useCallback, useEffect, useMemo } from "react";
import classNames from "classnames";
import "./TextCard.less";
//#region src/components/PisellCards/components/TextCard/TextCard.tsx
const _excluded = [
	"text",
	"variant",
	"size",
	"clickable",
	"prefixIcon",
	"suffixIcon",
	"iconConfig",
	"tag",
	"tagConfig",
	"badge",
	"prefixSlot",
	"suffixSlot",
	"textConfig",
	"widthMode",
	"width",
	"maxWidth",
	"onClick",
	"render",
	"active",
	"disabled",
	"loading",
	"className",
	"style",
	"children",
	"dataSource"
];
/**
* TextCard 文本卡片组件
* 用于展示带图标、文本、标签和角标的信息项，常用于 Tab 项、列表项等
*
* @example
* ```tsx
* // 基础用法
* <TextCard text="Tab title" />
*
* // 带图标和角标
* <TextCard
*   text="Password"
*   prefixIcon={<BellIcon />}
*   badge={{ type: 'number', content: 99 }}
*   variant="filled"
*   active={{ value: true }}
* />
* ```
*/
const TextCard = (props) => {
	const { text, variant = "text", size = "default", clickable = true, prefixIcon, suffixIcon, iconConfig, tag, tagConfig, badge, prefixSlot, suffixSlot, textConfig, widthMode = "auto", width, maxWidth = 400, onClick, render, active, disabled, loading, className, style, children, dataSource } = props, restProps = _objectWithoutProperties(props, _excluded);
	/**
	* 合并状态样式
	* 优先级：loading > disabled > active
	*/
	const mergedStyle = useMemo(() => {
		let finalStyle = _objectSpread2({}, style);
		if (widthMode === "auto") {
			finalStyle.width = "auto";
			finalStyle.maxWidth = maxWidth;
		} else if (widthMode === "fixed" && width) finalStyle.width = width;
		else if (widthMode === "full") {
			finalStyle.width = "100%";
			finalStyle.minWidth = 28;
		}
		if ((loading === null || loading === void 0 ? void 0 : loading.value) && (loading === null || loading === void 0 ? void 0 : loading.style)) finalStyle = _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 = _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 = _objectSpread2(_objectSpread2({}, finalStyle), active.style);
		return finalStyle;
	}, [
		style,
		active,
		disabled,
		loading,
		widthMode,
		width,
		maxWidth
	]);
	/**
	* 合并状态类名
	*/
	const mergedClassName = useMemo(() => {
		return classNames("text-card", `text-card--${variant}`, `text-card--${size}`, className, {
			"text-card--active": active === null || active === void 0 ? void 0 : active.value,
			"text-card--disabled": disabled === null || disabled === void 0 ? void 0 : disabled.value,
			"text-card--loading": loading === null || loading === void 0 ? void 0 : loading.value,
			"text-card--clickable": clickable && !(disabled === null || disabled === void 0 ? void 0 : disabled.value) && !(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,
		variant,
		size,
		active,
		disabled,
		loading,
		clickable
	]);
	/**
	* 处理点击事件
	*/
	const handleClick = useCallback((event) => {
		if ((disabled === null || disabled === void 0 ? void 0 : disabled.value) || (loading === null || loading === void 0 ? void 0 : loading.value) || !clickable) {
			event.preventDefault();
			return;
		}
		if ((active === null || active === void 0 ? void 0 : active.onChange) && !active.value) active.onChange(true);
		if (onClick) onClick(event);
	}, [
		onClick,
		active,
		disabled,
		loading,
		clickable
	]);
	/**
	* 渲染状态的 extra 内容
	* 优先级：loading > disabled > active
	*/
	const renderExtra = useCallback(() => {
		if ((loading === null || loading === void 0 ? void 0 : loading.value) && (loading === null || loading === void 0 ? void 0 : loading.extra)) return /* @__PURE__ */ React.createElement("div", { className: "text-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.createElement("div", { className: "text-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.createElement("div", { className: "text-card__extra" }, active.extra);
		return null;
	}, [
		active,
		disabled,
		loading
	]);
	useEffect(() => {
		document.body.id = "body";
	}, []);
	/**
	* 渲染主内容
	*/
	const renderContent = useCallback(() => {
		if (render) return render(props);
		return /* @__PURE__ */ React.createElement(React.Fragment, null, prefixSlot || prefixIcon && /* @__PURE__ */ React.createElement(IconWrapper, {
			icon: prefixIcon,
			config: iconConfig,
			position: "prefix"
		}), /* @__PURE__ */ React.createElement(TextContent, {
			text,
			textConfig,
			active
		}), suffixSlot || /* @__PURE__ */ React.createElement(React.Fragment, null, tag && /* @__PURE__ */ React.createElement("div", {
			className: "text-card__tag",
			style: tagConfig === null || tagConfig === void 0 ? void 0 : tagConfig.style
		}, tag), suffixIcon && /* @__PURE__ */ React.createElement(IconWrapper, {
			icon: suffixIcon,
			config: iconConfig,
			position: "suffix"
		})));
	}, [
		render,
		props,
		prefixSlot,
		prefixIcon,
		iconConfig,
		text,
		textConfig,
		suffixSlot,
		tag,
		tagConfig,
		suffixIcon,
		active
	]);
	return /* @__PURE__ */ React.createElement(BadgeWrapper, { badge }, /* @__PURE__ */ React.createElement("div", _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,
		role: "button",
		"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));
};
/**
* Provider 包装器
* 兼容 PisellCards 系统的 props 传递方式
*/
const Provider = (props) => /* @__PURE__ */ React.createElement(TextCard, _objectSpread2(_objectSpread2({}, props === null || props === void 0 ? void 0 : props.props), props));
//#endregion
export { Provider as default };
