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