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