import { hasRenderableNode } from "../_utils/vue.js";
import { STATUS_ICON_MAP } from "./Status.js";
import { Transition, computed, createVNode, defineComponent } from "vue";
import { useConfig } from "antdv-next/config-provider/context";
import { LeftOutlined, RightOutlined } from "@antdv-next/icons";
//#region components/thought-chain/Node.tsx
var Node_default = /* @__PURE__ */ defineComponent({
	name: "ThoughtChainNode",
	props: {
		item: {
			type: Object,
			required: true
		},
		index: {
			type: Number,
			required: true
		},
		isLast: {
			type: Boolean,
			default: false
		},
		prefixCls: {
			type: String,
			required: true
		},
		lineStyle: {
			type: [Boolean, String],
			default: "solid"
		},
		expanded: {
			type: Boolean,
			default: true
		},
		classes: {
			type: Object,
			default: () => ({})
		},
		styles: {
			type: Object,
			default: () => ({})
		},
		iconRenderSlot: {
			type: Function,
			default: void 0
		},
		titleRenderSlot: {
			type: Function,
			default: void 0
		},
		descriptionRenderSlot: {
			type: Function,
			default: void 0
		},
		contentRenderSlot: {
			type: Function,
			default: void 0
		},
		footerRenderSlot: {
			type: Function,
			default: void 0
		}
	},
	emits: ["toggleExpand"],
	setup(props, { emit }) {
		const configCtx = useConfig();
		const isRtl = computed(() => configCtx.value.direction === "rtl");
		const nodePrefixCls = computed(() => `${props.prefixCls}-node`);
		const resolvedLineStyle = computed(() => {
			if (props.lineStyle === false || props.isLast) return "none";
			if (props.lineStyle === true) return "solid";
			return props.lineStyle;
		});
		const statusCls = computed(() => `${props.prefixCls}-status`);
		const createSharedSlotInfo = (collapsible) => ({
			item: props.item,
			index: props.index,
			expanded: props.expanded,
			collapsible,
			toggleExpand: () => emit("toggleExpand")
		});
		const renderIcon = (collapsible) => {
			const { item, index } = props;
			const defaultIcon = createVNode("span", { "class": `${nodePrefixCls.value}-index-icon` }, [index + 1]);
			const originNode = item.icon === false ? null : item.status ? STATUS_ICON_MAP[item.status] : item.icon ?? defaultIcon;
			const iconNode = props.iconRenderSlot ? props.iconRenderSlot({
				...createSharedSlotInfo(collapsible),
				originNode,
				status: item.status
			}) : originNode;
			if (!hasRenderableNode(iconNode)) return null;
			return createVNode("div", {
				"class": [
					statusCls.value,
					`${nodePrefixCls.value}-icon`,
					props.classes?.itemIcon,
					{
						[`${statusCls.value}-${item.status}`]: item.status,
						[`${nodePrefixCls.value}-icon-${resolvedLineStyle.value}`]: typeof props.lineStyle !== "boolean" && resolvedLineStyle.value !== "none"
					}
				],
				"style": props.styles?.itemIcon
			}, [iconNode]);
		};
		const renderHeader = (contentNode) => {
			const { item } = props;
			const cls = nodePrefixCls.value;
			const hasContent = hasRenderableNode(contentNode);
			const collapsible = !!item.collapsible && hasContent;
			const collapseIcon = collapsible ? createVNode("span", {
				"class": `${cls}-collapse-icon`,
				"style": { transform: props.expanded ? "rotate(90deg)" : isRtl.value ? "rotate(-90deg)" : "rotate(0deg)" }
			}, [isRtl.value ? createVNode(LeftOutlined, null, null) : createVNode(RightOutlined, null, null)]) : null;
			const titleNode = props.titleRenderSlot ? props.titleRenderSlot({
				...createSharedSlotInfo(collapsible),
				originNode: item.title
			}) : item.title;
			const descriptionNode = props.descriptionRenderSlot ? props.descriptionRenderSlot({
				...createSharedSlotInfo(collapsible),
				originNode: item.description
			}) : item.description;
			const hasTitle = hasRenderableNode(titleNode);
			const hasDescription = hasRenderableNode(descriptionNode);
			return createVNode("div", {
				"class": [`${cls}-header`, props.classes?.itemHeader],
				"style": props.styles?.itemHeader
			}, [hasTitle && createVNode("div", {
				"class": [`${cls}-title`, {
					[`${cls}-collapsible`]: collapsible,
					[`${props.prefixCls}-motion-blink`]: item.blink
				}],
				"onClick": collapsible ? () => emit("toggleExpand") : void 0
			}, [titleNode, collapseIcon]), hasDescription && createVNode("div", { "class": `${cls}-description` }, [descriptionNode])]);
		};
		function onBeforeEnter(el) {
			el.style.height = "0";
			el.style.opacity = "0";
		}
		function onEnter(el) {
			const htmlEl = el;
			htmlEl.style.height = `${htmlEl.scrollHeight}px`;
			htmlEl.style.opacity = "1";
		}
		function onAfterEnter(el) {
			el.style.height = "";
			el.style.opacity = "";
		}
		function onBeforeLeave(el) {
			el.style.height = `${el.scrollHeight}px`;
			el.style.opacity = "1";
		}
		function onLeave(el) {
			el.offsetHeight;
			el.style.height = "0";
			el.style.opacity = "0";
		}
		function onAfterLeave(el) {
			el.style.height = "";
			el.style.opacity = "";
		}
		return () => {
			const { item } = props;
			const cls = nodePrefixCls.value;
			const slotInfoCollapsible = !!item.collapsible && (hasRenderableNode(item.content) || !!props.contentRenderSlot);
			const contentNode = props.contentRenderSlot ? props.contentRenderSlot({
				...createSharedSlotInfo(slotInfoCollapsible),
				originNode: item.content
			}) : item.content;
			const hasContent = hasRenderableNode(contentNode);
			const collapsible = !!item.collapsible && hasContent;
			const footerNode = props.footerRenderSlot ? props.footerRenderSlot({
				...createSharedSlotInfo(collapsible),
				originNode: item.footer
			}) : item.footer;
			const showContent = hasContent && (!collapsible || props.expanded);
			return createVNode("div", {
				"class": [`${cls}`, props.classes?.item],
				"style": props.styles?.item
			}, [renderIcon(collapsible), createVNode("div", { "class": `${cls}-box` }, [
				renderHeader(contentNode),
				hasContent && createVNode(Transition, {
					"name": `${props.prefixCls}-collapse`,
					"onBeforeEnter": onBeforeEnter,
					"onEnter": onEnter,
					"onAfterEnter": onAfterEnter,
					"onBeforeLeave": onBeforeLeave,
					"onLeave": onLeave,
					"onAfterLeave": onAfterLeave
				}, { default: () => [showContent ? createVNode("div", null, [createVNode("div", {
					"class": [`${cls}-content`, props.classes?.itemContent],
					"style": props.styles?.itemContent
				}, [createVNode("div", { "class": `${cls}-content-box` }, [contentNode])])]) : null] }),
				hasRenderableNode(footerNode) && createVNode("div", {
					"class": [`${cls}-footer`, props.classes?.itemFooter],
					"style": props.styles?.itemFooter
				}, [footerNode])
			])]);
		};
	}
});
//#endregion
export { Node_default as default };
