import { Transition, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, onBeforeUnmount, onMounted, openBlock, ref, unref, withCtx } from "vue";
import { ScalarIcon } from "@scalar/components";
//#region src/components/ImportCollection/DropEventListener.vue?vue&type=script&setup=true&lang.ts
var _hoisted_1 = {
	key: 0,
	class: "bg-b-2 fixed right-1/2 bottom-1/2 z-50 h-64 w-64 translate-x-1/2 translate-y-1/2 rounded-xl border transition-opacity duration-200 md:right-10 md:bottom-10 md:translate-x-0 md:translate-y-0"
};
var _hoisted_2 = { class: "flex h-full flex-col items-center justify-center" };
var DropEventListener_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
	__name: "DropEventListener",
	emits: ["input"],
	setup(__props, { emit: __emit }) {
		const emit = __emit;
		const isDragging = ref(false);
		let dragCounter = 0;
		onMounted(() => {
			document.addEventListener("dragenter", handleDragEnter);
			document.addEventListener("dragleave", handleDragLeave);
			document.addEventListener("dragover", handleDragOver);
			document.addEventListener("drop", handleDrop);
		});
		onBeforeUnmount(() => {
			document.removeEventListener("dragenter", handleDragEnter);
			document.removeEventListener("dragover", handleDragOver);
			document.removeEventListener("dragleave", handleDragLeave);
			document.removeEventListener("drop", handleDrop);
		});
		function isFromApp(event) {
			return event.dataTransfer?.types.includes("text/html") ?? false;
		}
		function handleDrop(event) {
			event.preventDefault();
			isDragging.value = false;
			dragCounter = 0;
			if (isFromApp(event)) return;
			if (event.dataTransfer) {
				const droppedText = event.dataTransfer.getData("text").replace(/^blob:/, "");
				if (droppedText) emit("input", droppedText, null, "drop");
				else if (event.dataTransfer.files.length > 0) {
					const file = event.dataTransfer.files[0];
					if (!file) return;
					const reader = new FileReader();
					reader.onload = (e) => {
						if (e.target && typeof e.target.result === "string") emit("input", e.target.result, null, "drop");
					};
					reader.readAsText(file);
				}
			}
		}
		function handleDragOver(event) {
			event.preventDefault();
		}
		function handleDragLeave(event) {
			event.preventDefault();
			dragCounter--;
			if (dragCounter === 0) isDragging.value = false;
		}
		function handleDragEnter(event) {
			event.preventDefault();
			dragCounter++;
			if (isFromApp(event)) return;
			if (event.dataTransfer) {
				const items = event.dataTransfer.items;
				for (const item of items) if (item?.kind === "string" || item?.type?.includes("json") || item?.type?.includes("yml") || item?.type?.includes("yaml")) {
					isDragging.value = true;
					return;
				}
			}
			isDragging.value = false;
		}
		return (_ctx, _cache) => {
			return openBlock(), createBlock(Transition, {
				enterActiveClass: "transition-opacity duration-200",
				enterFromClass: "opacity-0",
				leaveActiveClass: "transition-opacity duration-200",
				leaveToClass: "opacity-0"
			}, {
				default: withCtx(() => [isDragging.value ? (openBlock(), createElementBlock("div", _hoisted_1, [createElementVNode("div", _hoisted_2, [createElementVNode("div", null, [createVNode(unref(ScalarIcon), {
					icon: "Download",
					size: "xl",
					thickness: "2"
				})]), _cache[0] || (_cache[0] = createElementVNode("div", { class: "text-c-1 m-4 text-center" }, " Drop your OpenAPI document here ", -1))])])) : createCommentVNode("", true)]),
				_: 1
			});
		};
	}
});
//#endregion
export { DropEventListener_vue_vue_type_script_setup_true_lang_default as default };

//# sourceMappingURL=DropEventListener.vue.script.js.map