import { defineComponent as O, mergeModels as v, useModel as C, computed as c, watch as N, createBlock as z, openBlock as B, unref as d, mergeProps as R, withCtx as V, createElementVNode as i, createTextVNode as k, toDisplayString as n, createVNode as m } from "vue";
import { useI18n as F } from "vue-i18n";
import { u as _, aw as L, ax as P, d as p, ay as S } from "./start-CE9SawgU.js";
import "pinia";
import "./header-Bn1EKnBE.js";
import { V as H } from "./constants-CwfsvyFM.js";
import "@vuelidate/validators";
import "./TreeView.vue_vue_type_style_index_0_scoped_0bd14ef7_lang-CZieIjgg.js";
import "./DatahubDataTypeCompletenessRenderer.vue_vue_type_script_setup_true_lang-5buor0oX.js";
import "./topBarRoutes-CBd5qLxn.js";
import "./IsActiveStatusCell-xz7XnAYP.js";
import "./VariantToVariantExtension-DUC3WSrH.js";
import "./DatahubDataTypeVariantValueEditor-9WYNJneN.js";
import "./dataTypes-DocW2t0g.js";
import { b } from "./image-value.json_vue_type_i18n_index_0_src_true_lang-CWHYrlaa.js";
const W = /* @__PURE__ */ O({
  __name: "DatahubDataTypeImageValueEditor",
  props: /* @__PURE__ */ v({
    modelValue: {},
    readOnly: { type: Boolean },
    attribute: {},
    massEditing: { type: Boolean },
    label: {},
    fieldName: {},
    dataTypeInstance: {},
    loading: { type: Boolean },
    succeeded: { type: Boolean },
    baseFolder: { default: "/.ecmfileimage_tmp/" },
    uploadEndpoint: { default: "Actindo.Modules.Actindo.ECM.Upload.upload" },
    downloadEndpoint: { default: "Actindo.Modules.Actindo.ECM.Download.download" },
    previewImageWidth: { default: 300 },
    previewImageHeight: { default: 300 }
  }, {
    modelValue: {},
    modelModifiers: {}
  }),
  emits: /* @__PURE__ */ v(["validated", "update:model-value", "initialized"], ["update:modelValue"]),
  setup(g, { emit: h }) {
    const o = g, T = h, r = C(g, "modelValue"), { t: u } = F(), { root: E, dispatchEvent: w } = _(H), f = c(
      () => r.value?.images?.filter(
        ({ permanentDelete: e }) => !e
      ) ?? []
    ), M = c(() => [
      {
        title: u("datahub-plugin.image-value.addImage"),
        event: "createImage"
      }
    ]), U = ({ id: e }) => e ? L(`${o.downloadEndpoint}?id=${encodeURIComponent(e)}`) : null, I = c(() => ({
      modelValue: f.value,
      readonly: o.readOnly,
      canRemove: !o.readOnly,
      tableName: o.label,
      createActions: M.value,
      isLoading: o.loading,
      getDownloadLink: U,
      previewPrefix: `&width=${o.previewImageWidth}&height=${o.previewImageHeight}`,
      getAltText: "title",
      hideSearch: !0,
      hideReplace: !0,
      addImage: D,
      hideNoDataDescription: !0
    }));
    function A(e) {
      r.value = {
        ...r.value,
        images: [
          ...r.value?.images?.filter(
            ({ permanentDelete: t }) => t
          ) ?? [],
          ...e
        ]
      };
    }
    const D = () => ({
      id: null,
      title: null,
      caption: null,
      altText: null,
      imageTags: null,
      sortOrder: null
    });
    async function $({
      oldImage: e,
      file: t
    }) {
      const a = Math.random().toString(36).substring(2), l = encodeURIComponent(o.baseFolder);
      let s = `${o.uploadEndpoint}?id=${l}`;
      a && (s = `${s}&prefix=${a}`);
      const { data: y } = await S(s, t);
      e.id = o.baseFolder + y, e.name = y, e.size = t.size, e.mimeType = t.type, e.link = void 0;
    }
    function x({ image: e }) {
      e.permanentDelete = !0;
    }
    return N(
      f,
      (e) => {
        const t = !!(!e.length || e.every(({ permanentDelete: a, id: l }) => a || l));
        w({ data: t }), T("validated", t);
      },
      { deep: !0, immediate: !0 }
    ), (e, t) => (B(), z(d(P), R({
      ref_key: "root",
      ref: E
    }, I.value, {
      onReplace: $,
      onRemove: x,
      "onUpdate:modelValue": A
    }), {
      editor: V(({ item: a }) => [
        m(d(p), {
          modelValue: a.title,
          "onUpdate:modelValue": (l) => a.title = l,
          modelModifiers: { lazy: !0 },
          label: e.$t("common.title"),
          readonly: e.readOnly,
          class: "mt-4"
        }, null, 8, ["modelValue", "onUpdate:modelValue", "label", "readonly"]),
        m(d(p), {
          modelValue: a.caption,
          "onUpdate:modelValue": (l) => a.caption = l,
          modelModifiers: { lazy: !0 },
          label: d(u)("datahub-plugin.image-value.caption"),
          readonly: e.readOnly,
          class: "mt-4"
        }, null, 8, ["modelValue", "onUpdate:modelValue", "label", "readonly"]),
        m(d(p), {
          modelValue: a.altText,
          "onUpdate:modelValue": (l) => a.altText = l,
          modelModifiers: { lazy: !0 },
          label: d(u)("datahub-plugin.image-value.altText"),
          readonly: e.readOnly,
          class: "mt-4"
        }, null, 8, ["modelValue", "onUpdate:modelValue", "label", "readonly"]),
        m(d(p), {
          modelValue: a.imageTags,
          "onUpdate:modelValue": (l) => a.imageTags = l,
          modelModifiers: { lazy: !0 },
          label: d(u)("datahub-plugin.image-value.imageTags"),
          readonly: e.readOnly,
          class: "mt-4"
        }, null, 8, ["modelValue", "onUpdate:modelValue", "label", "readonly"])
      ]),
      details: V(({ item: a }) => [
        i("div", null, n(a.name), 1),
        i("div", null, n(a.caption), 1),
        i("div", null, n(a.altText), 1),
        i("div", null, n(a.imageTags), 1),
        i("div", null, n(a.mimeType), 1),
        i("div", null, n(a.created), 1),
        k(" " + n(a), 1)
      ]),
      _: 1
    }, 16));
  }
});
typeof b == "function" && b(W);
export {
  W as default
};
