import e from "../PlIcon24/PlIcon24.js";
import "../PlIcon24/index.js";
import t from "./pl-file-dialog.module.js";
import { normalizeExtensions as n } from "./utils.js";
import { computed as r, createCommentVNode as i, createElementBlock as a, createElementVNode as o, createVNode as s, defineComponent as c, normalizeClass as l, openBlock as u, reactive as d, toDisplayString as f, unref as p, withModifiers as m } from "vue";
import { getRawPlatformaInstance as h } from "@platforma-sdk/model";
var g = {
	key: 1,
	class: "alert-error"
}, _ = /* @__PURE__ */ c({
	__name: "Local",
	props: {
		importFiles: { type: Function },
		multi: { type: Boolean },
		extensions: {}
	},
	setup(c) {
		let _ = c, v = d({ error: void 0 }), y = r(() => _.multi ? "Drag & Drop files here or click to add" : "Drag & Drop file here or click to add"), b = async (e) => {
			let t = h()?.lsDriver?.fileToImportHandle;
			if (!t) return console.error("API getPlatformaRawInstance().lsDriver.fileToImportHandle is not available");
			let r = n(_.extensions), i = await Promise.all([...e.dataTransfer?.files ?? []].filter((e) => !!e).filter((e) => r ? r.some((t) => e.name.endsWith(t)) : !0).map((e) => t(e)));
			i.length && _.importFiles({ files: i });
		}, x = async () => {
			let e = _.extensions ? [{
				name: "All Files",
				extensions: [..._.extensions]
			}] : [];
			_.multi ? h()?.lsDriver.showOpenMultipleFilesDialog({
				title: "Select files to import",
				filters: e
			}).then(({ files: e }) => {
				e && _.importFiles({ files: e });
			}).catch((e) => v.error = e) : h()?.lsDriver.showOpenSingleFileDialog({
				title: "Select file to import",
				filters: e
			}).then(({ file: e }) => {
				e && _.importFiles({ files: [e] });
			}).catch((e) => v.error = e);
		};
		return (n, r) => (u(), a("div", {
			class: l(p(t).local),
			onDrop: b,
			onDragover: r[0] ||= m(() => {}, ["prevent"]),
			onClick: x
		}, [
			s(p(e), { name: "cloud-upload" }),
			o("span", null, f(y.value), 1),
			c.extensions ? (u(), a("span", {
				key: 0,
				class: l(p(t).supported)
			}, "Supported formats: " + f(c.extensions.join(", ")), 3)) : i("", !0),
			v.error ? (u(), a("span", g, f(v.error), 1)) : i("", !0)
		], 34));
	}
});
export { _ as default };

//# sourceMappingURL=Local.vue2.js.map