import { hasRenderableNode } from "../_utils/vue.js";
import { computed, createVNode, defineComponent, isVNode } from "vue";
import { Dropdown, Typography } from "antdv-next";
import { EllipsisOutlined } from "@antdv-next/icons";
//#region components/conversations/Item.tsx
function _isSlot(s) {
	return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !isVNode(s);
}
var stopPropagation = (event) => {
	event.stopPropagation();
};
var renderWithPriority = (render, slotRender, info) => {
	if (slotRender) return slotRender(info);
	if (render !== void 0) return typeof render === "function" ? render(info.item, info) : render;
	return info.originNode;
};
var ConversationsItem = /* @__PURE__ */ defineComponent({
	name: "XConversationsItem",
	inheritAttrs: false,
	props: {
		info: {
			type: Object,
			required: true
		},
		index: {
			type: Number,
			default: 0
		},
		prefixCls: {
			type: String,
			default: "antd-conversations"
		},
		direction: {
			type: String,
			default: "ltr"
		},
		menu: {
			type: Object,
			default: void 0
		},
		active: {
			type: Boolean,
			default: false
		},
		labelRender: {
			type: [
				String,
				Number,
				Object,
				Array,
				Function
			],
			default: void 0
		},
		iconRender: {
			type: [
				String,
				Number,
				Object,
				Array,
				Function
			],
			default: void 0
		},
		labelRenderSlot: {
			type: Function,
			default: void 0
		},
		iconRenderSlot: {
			type: Function,
			default: void 0
		},
		classes: {
			type: [
				String,
				Array,
				Object
			],
			default: void 0
		},
		style: {
			type: [
				String,
				Object,
				Array
			],
			default: void 0
		},
		onClick: {
			type: Function,
			default: void 0
		}
	},
	setup(props) {
		const mergedClasses = computed(() => {
			const disabled = props.info.disabled;
			return [
				props.classes,
				`${props.prefixCls}-item`,
				{
					[`${props.prefixCls}-item-active`]: props.active && !disabled,
					[`${props.prefixCls}-item-disabled`]: disabled
				}
			];
		});
		const menuProps = computed(() => {
			if (!props.menu) return void 0;
			const { trigger: _trigger, ...other } = props.menu;
			return other;
		});
		const renderMenuTrigger = (conversation) => {
			const originTriggerNode = createVNode(EllipsisOutlined, {
				"onClick": stopPropagation,
				"class": `${props.prefixCls}-menu-icon`
			}, null);
			if (!props.menu?.trigger) return originTriggerNode;
			return typeof props.menu.trigger === "function" ? props.menu.trigger(conversation, { originNode: originTriggerNode }) : props.menu.trigger;
		};
		return () => {
			let _slot;
			const disabled = props.info.disabled;
			const labelNode = renderWithPriority(props.labelRender, props.labelRenderSlot, {
				item: props.info,
				index: props.index,
				active: props.active,
				originNode: props.info.label
			});
			const iconNode = renderWithPriority(props.iconRender, props.iconRenderSlot, {
				item: props.info,
				index: props.index,
				active: props.active,
				originNode: props.info.icon
			});
			return createVNode("li", {
				"title": typeof props.info.label === "string" ? props.info.label : void 0,
				"class": mergedClasses.value,
				"style": props.style,
				"onClick": () => {
					if (!disabled) props.onClick?.(props.info.key, props.info);
				}
			}, [
				hasRenderableNode(iconNode) && createVNode("div", { "class": `${props.prefixCls}-icon` }, [iconNode]),
				createVNode(Typography.Text, { "class": `${props.prefixCls}-label` }, _isSlot(labelNode) ? labelNode : { default: () => [labelNode] }),
				!disabled && props.menu && createVNode("div", { "onClick": stopPropagation }, [createVNode(Dropdown, {
					"menu": menuProps.value,
					"placement": props.direction === "rtl" ? "bottomLeft" : "bottomRight",
					"trigger": ["click"],
					"disabled": disabled,
					"getPopupContainer": menuProps.value?.getPopupContainer
				}, _isSlot(_slot = renderMenuTrigger(props.info)) ? _slot : { default: () => [_slot] })])
			]);
		};
	}
});
//#endregion
export { ConversationsItem as default };
