import { AttachmentContextKey } from "./context.js";
import { computed, createVNode, defineComponent, inject, isVNode, mergeProps, ref } from "vue";
import { Upload } from "antdv-next";
//#region components/attachments/PlaceholderUploader.tsx
function _isSlot(s) {
	return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !isVNode(s);
}
var PlaceholderUploader = /* @__PURE__ */ defineComponent({
	name: "XPlaceholderUploader",
	inheritAttrs: false,
	props: {
		prefixCls: {
			type: String,
			required: true
		},
		type: {
			type: String,
			required: true
		},
		placeholder: {
			type: [
				String,
				Number,
				Object,
				Array,
				Function
			],
			default: void 0
		},
		upload: {
			type: Object,
			default: void 0
		},
		class: {
			type: [
				String,
				Array,
				Object
			],
			default: void 0
		},
		style: {
			type: [
				String,
				Object,
				Array
			],
			default: void 0
		}
	},
	setup(props, { attrs, slots }) {
		const context = inject(AttachmentContextKey, {});
		const dragIn = ref(false);
		const placeholderCls = computed(() => `${props.prefixCls}-placeholder`);
		const disabled = computed(() => {
			const disabledValue = context.disabled;
			return typeof disabledValue === "boolean" ? disabledValue : disabledValue?.value ?? false;
		});
		const isConfig = computed(() => {
			const placeholder = props.placeholder;
			return !!placeholder && typeof placeholder === "object" && !Array.isArray(placeholder) && !isVNode(placeholder);
		});
		const placeholderConfig = computed(() => {
			if (!isConfig.value) return {};
			return props.placeholder;
		});
		const renderConfigNode = () => {
			const iconOriginNode = placeholderConfig.value.icon;
			const titleOriginNode = placeholderConfig.value.title;
			const descriptionOriginNode = placeholderConfig.value.description;
			const iconNode = slots.placeholderIcon?.({
				type: props.type,
				originNode: iconOriginNode
			}) ?? iconOriginNode;
			const titleNode = slots.placeholderTitle?.({
				type: props.type,
				originNode: titleOriginNode
			}) ?? titleOriginNode;
			const descriptionNode = slots.placeholderDescription?.({
				type: props.type,
				originNode: descriptionOriginNode
			}) ?? descriptionOriginNode;
			return createVNode("div", { "class": `${placeholderCls.value}-inner` }, [
				createVNode("span", { "class": `${placeholderCls.value}-icon` }, [iconNode]),
				createVNode("span", { "class": `${placeholderCls.value}-title` }, [titleNode]),
				createVNode("span", { "class": `${placeholderCls.value}-description` }, [descriptionNode])
			]);
		};
		const onDragEnter = () => {
			dragIn.value = true;
		};
		const onDragLeave = (e) => {
			if (!e.currentTarget.contains(e.relatedTarget)) dragIn.value = false;
		};
		const onDrop = () => {
			dragIn.value = false;
		};
		return () => {
			const originNode = isConfig.value ? renderConfigNode() : slots.default?.() || props.placeholder;
			const node = slots.placeholder?.({
				type: props.type,
				originNode
			}) ?? originNode;
			return createVNode("div", {
				"class": [
					placeholderCls.value,
					{
						[`${placeholderCls.value}-drag-in`]: dragIn.value,
						[`${placeholderCls.value}-disabled`]: disabled.value
					},
					props.class,
					attrs.class
				],
				"style": [props.style, attrs.style],
				"onDragenter": onDragEnter,
				"onDragleave": onDragLeave,
				"onDrop": onDrop,
				"aria-hidden": disabled.value
			}, [createVNode(Upload.Dragger, mergeProps(props.upload, attrs, {
				"showUploadList": false,
				"style": {
					padding: 0,
					border: 0,
					background: "transparent"
				}
			}), _isSlot(node) ? node : { default: () => [node] })]);
		};
	}
});
//#endregion
export { PlaceholderUploader as default };
