import useXComponentConfig from "../_utils/hooks/use-x-component-config.js";
import { isEmptyNode } from "../_utils/vue.js";
import Item from "./Item.js";
import style_default from "./style/index.js";
import { Transition, computed, createVNode, defineComponent, isVNode, mergeProps, ref, useAttrs, useSlots } from "vue";
import { useConfig } from "antdv-next/config-provider/context";
//#region components/actions/Actions.tsx
function _isSlot(s) {
	return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !isVNode(s);
}
function getMotionTransitionProps(motionName) {
	return {
		name: motionName,
		appear: true,
		enterFromClass: `${motionName} ${motionName}-enter ${motionName}-appear ${motionName}-appear-prepare ${motionName}-enter-prepare ${motionName}-enter-start`,
		enterActiveClass: `${motionName} ${motionName}-enter ${motionName}-appear ${motionName}-appear-prepare ${motionName}-enter-prepare`,
		enterToClass: `${motionName} ${motionName}-enter ${motionName}-appear ${motionName}-appear-active ${motionName}-enter-active`,
		leaveFromClass: `${motionName} ${motionName}-leave`,
		leaveActiveClass: `${motionName} ${motionName}-leave ${motionName}-leave-active`,
		leaveToClass: `${motionName} ${motionName}-leave ${motionName}-leave-active`
	};
}
var XActions = /* @__PURE__ */ defineComponent({
	name: "AxActions",
	inheritAttrs: false,
	props: {
		items: {
			type: Array,
			default: () => []
		},
		onClick: {
			type: Function,
			default: void 0
		},
		dropdownProps: {
			type: Object,
			default: void 0
		},
		variant: {
			type: String,
			default: "borderless"
		},
		prefixCls: {
			type: String,
			default: "antd-actions"
		},
		rootClass: {
			type: String,
			default: ""
		},
		class: {
			type: [
				String,
				Array,
				Object
			],
			default: void 0
		},
		style: {
			type: [
				String,
				Object,
				Array
			],
			default: void 0
		},
		classes: {
			type: Object,
			default: () => ({})
		},
		styles: {
			type: Object,
			default: () => ({})
		},
		fadeIn: {
			type: Boolean,
			default: false
		},
		fadeInLeft: {
			type: Boolean,
			default: false
		}
	},
	setup(props, { expose }) {
		const configCtx = useConfig();
		const attrs = useAttrs();
		const slots = useSlots();
		const contextConfig = useXComponentConfig("actions");
		const rootRef = ref();
		const [hashId, cssVarCls] = style_default(computed(() => props.prefixCls));
		const rootPrefixCls = computed(() => configCtx.value.getPrefixCls());
		const motionName = computed(() => {
			if (!props.fadeIn && !props.fadeInLeft) return "";
			return `${rootPrefixCls.value}-x-fade${props.fadeInLeft ? "-left" : ""}`;
		});
		const transitionProps = computed(() => {
			if (!motionName.value) return null;
			return getMotionTransitionProps(motionName.value);
		});
		expose({ get nativeElement() {
			return rootRef.value;
		} });
		const domAttrs = computed(() => {
			const { class: _class, style: _style, ...rest } = attrs;
			return rest;
		});
		const mergedClasses = computed(() => {
			return {
				...contextConfig.value.classes,
				...props.classes
			};
		});
		const mergedStyles = computed(() => {
			return {
				...contextConfig.value.styles,
				...props.styles
			};
		});
		const getNamedSlot = (name) => slots[name] ?? slots[name.replace(/[A-Z]/g, (s) => `-${s.toLowerCase()}`)];
		const renderList = () => createVNode("div", { "class": [`${props.prefixCls}-list`, `${props.prefixCls}-variant-${props.variant}`] }, [props.items.map((item, idx) => {
			const slotInfo = {
				item,
				index: idx,
				originNode: item.icon
			};
			const slottedIcon = getNamedSlot("iconRender")?.(slotInfo);
			const slotActionNode = getNamedSlot("actionRender")?.({
				item,
				index: idx,
				originNode: item.actionRender !== void 0 ? typeof item.actionRender === "function" ? item.actionRender(item) : item.actionRender : void 0
			});
			const mergedItem = {
				...item,
				icon: slottedIcon !== void 0 && !isEmptyNode(slottedIcon) ? slottedIcon : item.icon,
				actionRender: slotActionNode !== void 0 && !isEmptyNode(slotActionNode) ? slotActionNode : item.actionRender
			};
			return createVNode(Item, {
				"key": item.key ?? idx,
				"item": mergedItem,
				"onClick": props.onClick,
				"dropdownProps": props.dropdownProps,
				"prefixCls": props.prefixCls,
				"classes": mergedClasses.value,
				"styles": mergedStyles.value
			}, null);
		})]);
		return () => {
			let _slot;
			return createVNode("div", mergeProps({ "ref": rootRef }, domAttrs.value, {
				"class": [
					props.prefixCls,
					contextConfig.value.classes?.root,
					props.rootClass,
					props.classes?.root,
					hashId.value,
					cssVarCls.value,
					attrs.class,
					props.class,
					{ [`${props.prefixCls}-rtl`]: configCtx.value.direction === "rtl" }
				],
				"style": [
					contextConfig.value.style,
					contextConfig.value.styles?.root,
					props.styles?.root,
					attrs.style,
					props.style
				]
			}), [transitionProps.value ? createVNode(Transition, transitionProps.value, _isSlot(_slot = renderList()) ? _slot : { default: () => [_slot] }) : renderList()]);
		};
	}
});
//#endregion
export { XActions, XActions as default };
