import useXComponentConfig from "../_utils/hooks/use-x-component-config.js";
import initCollapseTransition from "../_utils/transition.js";
import { hasRenderableNode } from "../_utils/vue.js";
import CarouselCard from "./components/CarouselCard.js";
import style_default from "./style/index.js";
import { Fragment, Transition, computed, createVNode, defineComponent, mergeProps, ref, useAttrs } from "vue";
import { useConfig } from "antdv-next/config-provider/context";
import { Popover } from "antdv-next";
import { RightOutlined } from "@antdv-next/icons";
//#region components/sources/Sources.tsx
var XSources = /* @__PURE__ */ defineComponent({
	name: "AxSources",
	inheritAttrs: false,
	props: {
		prefixCls: {
			type: String,
			default: "antdx-sources"
		},
		style: {
			type: [
				String,
				Object,
				Array
			],
			default: void 0
		},
		styles: {
			type: Object,
			default: () => ({})
		},
		class: {
			type: [
				String,
				Array,
				Object
			],
			default: void 0
		},
		classes: {
			type: Object,
			default: () => ({})
		},
		rootClass: {
			type: String,
			default: ""
		},
		inline: {
			type: Boolean,
			default: false
		},
		items: {
			type: Array,
			default: void 0
		},
		title: {
			type: [
				String,
				Number,
				Object
			],
			default: void 0
		},
		expandIconPosition: {
			type: String,
			default: "start"
		},
		onClick: {
			type: Function,
			default: void 0
		},
		popoverOverlayWidth: {
			type: [Number, String],
			default: 300
		},
		activeKey: {
			type: [String, Number],
			default: void 0
		},
		expanded: {
			type: Boolean,
			default: void 0
		},
		defaultExpanded: {
			type: Boolean,
			default: void 0
		}
	},
	emits: ["update:expanded", "expand"],
	setup(props, { slots, expose, emit }) {
		const configCtx = useConfig();
		const attrs = useAttrs();
		const contextConfig = useXComponentConfig("sources");
		const rootPrefixCls = computed(() => configCtx.value.getPrefixCls());
		const collapseTransition = computed(() => initCollapseTransition(rootPrefixCls.value));
		const rootRef = ref();
		const [hashId, cssVarCls] = style_default(computed(() => props.prefixCls));
		expose({ get nativeElement() {
			return rootRef.value;
		} });
		const innerExpanded = ref(props.defaultExpanded ?? true);
		const isExpand = computed(() => {
			if (props.expanded !== void 0) return props.expanded;
			return innerExpanded.value;
		});
		const toggleExpand = () => {
			const newExpand = !isExpand.value;
			if (props.expanded === void 0) innerExpanded.value = newExpand;
			emit("update:expanded", newExpand);
			emit("expand", newExpand);
		};
		const domAttrs = computed(() => {
			const { class: _class, style: _style, ...rest } = attrs;
			return rest;
		});
		const mergedCls = computed(() => [
			props.prefixCls,
			props.rootClass,
			contextConfig.value.classes?.root,
			props.classes?.root,
			hashId.value,
			cssVarCls.value,
			attrs.class,
			props.class,
			{
				[`${props.prefixCls}-inline`]: props.inline,
				[`${props.prefixCls}-rtl`]: configCtx.value.direction === "rtl"
			}
		]);
		const renderTitle = () => {
			const originNode = props.title;
			if (slots.title) return slots.title({ originNode });
			return originNode;
		};
		const renderItemNode = (slotName, item, index, originNode) => {
			const slot = slots[slotName];
			if (slot) return slot({
				item,
				index,
				originNode
			});
			return originNode;
		};
		return () => {
			const ContentNode = props.items ? createVNode("ul", { "class": `${props.prefixCls}-list` }, [props.items.map((item, index) => {
				const iconNode = renderItemNode("iconRender", item, index, item.icon);
				const titleNode = renderItemNode("titleRender", item, index, item.title);
				const descriptionNode = renderItemNode("description", item, index, item.description);
				return createVNode("li", {
					"key": item.key ?? index,
					"class": `${props.prefixCls}-list-item`,
					"onClick": () => props.onClick?.(item)
				}, [createVNode("a", {
					"class": `${props.prefixCls}-link`,
					"href": item.url,
					"target": "_blank",
					"rel": "noopener noreferrer"
				}, [
					hasRenderableNode(iconNode) && createVNode("span", { "class": `${props.prefixCls}-link-icon` }, [iconNode]),
					createVNode("span", { "class": `${props.prefixCls}-link-title` }, [titleNode]),
					hasRenderableNode(descriptionNode) && createVNode("span", { "class": `${props.prefixCls}-link-description` }, [descriptionNode])
				])]);
			})]) : slots.default?.();
			return createVNode("div", mergeProps({ "ref": rootRef }, domAttrs.value, {
				"class": mergedCls.value,
				"style": [
					contextConfig.value.style,
					contextConfig.value.styles?.root,
					props.styles?.root,
					attrs.style,
					props.style
				]
			}), [props.inline ? createVNode(Popover, {
				"content": createVNode(CarouselCard, {
					"classes": [
						props.prefixCls,
						hashId.value,
						cssVarCls.value,
						props.classes?.content
					],
					"style": props.styles?.content,
					"activeKey": props.activeKey,
					"prefixCls": props.prefixCls,
					"items": props.items,
					"onClick": props.onClick,
					"iconRenderSlot": slots.iconRender ? (info) => slots.iconRender?.(info) : void 0,
					"titleRenderSlot": slots.titleRender ? (info) => slots.titleRender?.(info) : void 0,
					"descriptionSlot": slots.description ? (info) => slots.description?.(info) : void 0
				}, null),
				"open": props.inline ? void 0 : false,
				"styles": { content: { width: typeof props.popoverOverlayWidth === "number" ? `${props.popoverOverlayWidth}px` : props.popoverOverlayWidth } },
				"placement": "top"
			}, { default: () => [createVNode("div", {
				"class": [
					props.prefixCls,
					`${props.prefixCls}-title-wrapper`,
					props.classes?.title
				],
				"style": props.styles?.title
			}, [createVNode("span", { "class": `${props.prefixCls}-title` }, [renderTitle()])])] }) : createVNode(Fragment, null, [createVNode("div", {
				"class": [
					`${props.prefixCls}-title-wrapper`,
					`${props.prefixCls}-icon-position-${props.expandIconPosition}`,
					props.classes?.title
				],
				"onClick": toggleExpand,
				"style": props.styles?.title
			}, [createVNode(RightOutlined, {
				"class": `${props.prefixCls}-title-down-icon`,
				"rotate": isExpand.value ? 90 : 0
			}, null), createVNode("span", { "class": `${props.prefixCls}-title` }, [renderTitle()])]), createVNode(Transition, collapseTransition.value, { default: () => [isExpand.value ? createVNode("div", {
				"class": [`${props.prefixCls}-content`, props.classes?.content],
				"style": props.styles?.content
			}, [ContentNode]) : null] })])]);
		};
	}
});
//#endregion
export { XSources, XSources as default };
