import useXComponentConfig from "../_utils/hooks/use-x-component-config.js";
import style_default from "./style/index.js";
import Node_default from "./Node.js";
import { computed, createVNode, defineComponent, mergeProps, ref, useAttrs, watch } from "vue";
import { useConfig } from "antdv-next/config-provider/context";
//#region components/thought-chain/ThoughtChain.tsx
var XThoughtChain = /* @__PURE__ */ defineComponent({
	name: "AxThoughtChain",
	inheritAttrs: false,
	props: {
		prefixCls: {
			type: String,
			default: "antd-thought-chain"
		},
		rootClass: {
			type: String,
			default: ""
		},
		style: {
			type: [
				String,
				Object,
				Array
			],
			default: void 0
		},
		class: {
			type: [
				String,
				Array,
				Object
			],
			default: void 0
		},
		styles: {
			type: Object,
			default: () => ({})
		},
		classes: {
			type: Object,
			default: () => ({})
		},
		items: {
			type: Array,
			default: () => []
		},
		defaultExpandedKeys: {
			type: Array,
			default: void 0
		},
		expandedKeys: {
			type: Array,
			default: void 0
		},
		line: {
			type: [Boolean, String],
			default: "solid"
		}
	},
	emits: ["update:expandedKeys", "expand"],
	setup(props, { emit, expose, slots }) {
		const attrs = useAttrs();
		const configCtx = useConfig();
		const contextConfig = useXComponentConfig("thoughtChain");
		const rootRef = ref();
		const [hashId, cssVarCls] = style_default(computed(() => props.prefixCls));
		const internalExpandedKeys = ref(props.defaultExpandedKeys ?? []);
		const mergedExpandedKeys = computed(() => props.expandedKeys !== void 0 ? props.expandedKeys : internalExpandedKeys.value);
		watch(() => props.expandedKeys, (val) => {
			if (val !== void 0) internalExpandedKeys.value = [...val];
		});
		function toggleExpand(key) {
			const keys = [...mergedExpandedKeys.value];
			const idx = keys.indexOf(key);
			if (idx >= 0) keys.splice(idx, 1);
			else keys.push(key);
			internalExpandedKeys.value = keys;
			emit("update:expandedKeys", keys);
			emit("expand", keys);
		}
		const domAttrs = computed(() => {
			const { class: _class, style: _style, ...rest } = attrs;
			return rest;
		});
		const prefixCls = computed(() => props.prefixCls);
		const mergedClasses = computed(() => {
			const ctx = contextConfig.value.classes ?? {};
			const prop = props.classes ?? {};
			const result = {};
			const keys = new Set([...Object.keys(ctx), ...Object.keys(prop)]);
			for (const k of keys) {
				const vals = [ctx[k], prop[k]].filter(Boolean).join(" ");
				if (vals) result[k] = vals;
			}
			return result;
		});
		const mergedStyles = computed(() => {
			const ctx = contextConfig.value.styles ?? {};
			const prop = props.styles ?? {};
			const result = {};
			const keys = new Set([...Object.keys(ctx), ...Object.keys(prop)]);
			for (const k of keys) result[k] = {
				...ctx[k],
				...prop[k]
			};
			return result;
		});
		expose({ get nativeElement() {
			return rootRef.value;
		} });
		return () => {
			const items = props.items;
			return createVNode("div", mergeProps({ "ref": rootRef }, domAttrs.value, {
				"class": [
					prefixCls.value,
					`${prefixCls.value}-box`,
					contextConfig.value.classes?.root,
					props.rootClass,
					props.classes?.root,
					hashId.value,
					cssVarCls.value,
					attrs.class,
					props.class,
					{ [`${prefixCls.value}-rtl`]: configCtx.value.direction === "rtl" }
				],
				"style": [
					contextConfig.value.style,
					contextConfig.value.styles?.root,
					props.styles?.root,
					attrs.style,
					props.style
				]
			}), [items.map((item, index) => {
				const key = item.key ?? String(index);
				return createVNode(Node_default, {
					"key": key,
					"item": item,
					"index": index,
					"isLast": index === items.length - 1,
					"prefixCls": prefixCls.value,
					"lineStyle": props.line,
					"expanded": mergedExpandedKeys.value.includes(key),
					"classes": mergedClasses.value,
					"styles": mergedStyles.value,
					"iconRenderSlot": slots.iconRender ?? slots["icon-render"] ? (info) => (slots.iconRender ?? slots["icon-render"])?.(info) : void 0,
					"titleRenderSlot": slots.title ? (info) => slots.title?.(info) : void 0,
					"descriptionRenderSlot": slots.description ? (info) => slots.description?.(info) : void 0,
					"contentRenderSlot": slots.content ? (info) => slots.content?.(info) : void 0,
					"footerRenderSlot": slots.footer ? (info) => slots.footer?.(info) : void 0,
					"onToggleExpand": () => toggleExpand(key)
				}, null);
			})]);
		};
	}
});
//#endregion
export { XThoughtChain, XThoughtChain as default };
