import { defineComponent as x, mergeModels as y, useModel as C, computed as c, watch as N, createBlock as R, openBlock as k, unref as d, mergeProps as z, withCtx as V, createElementVNode as i, createTextVNode as B, toDisplayString as n, createVNode as m } from "vue";
import { useI18n as F } from "vue-i18n";
import { u as _, ap as L, aq as P, b as p, ar as S, as as H } from "./start-BYfL32Oe.mjs";
import "pinia";
import "vue-router";
import "./header-Droxy2Kd.mjs";
import "./moment-h96o7c8I.mjs";
import { V as W } from "./constants-CwfsvyFM.mjs";
import "./IsActiveStatusCell-DlvB6_E-.mjs";
import "@vuelidate/validators";
import "./MultiLangScopeEditorsList.vue_vue_type_script_setup_true_lang-CWQeDnSm.mjs";
import "./DatahubDataTypeCompletenessRenderer.vue_vue_type_script_setup_true_lang-Btvu_WeF.mjs";
import "./topBarRoutes-0VuQ_i6D.mjs";
import "./VariantToVariantExtension-WcLvPNqG.mjs";
import "./DatahubDataTypeVariantValueEditor-f1gR3QCx.mjs";
import { b } from "./image-value.json_vue_type_i18n_index_0_src_true_lang-CWHYrlaa.mjs";
const j = /* @__PURE__ */ x({
  __name: "DatahubDataTypeImageValueEditor",
  props: /* @__PURE__ */ y({
    modelValue: {},
    readOnly: { type: Boolean },
    attribute: {},
    massEditing: { type: Boolean },
    label: {},
    fieldName: {},
    dataTypeInstance: {},
    loading: { 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__ */ y(["validated", "update:model-value"], ["update:modelValue"]),
  setup(g, { emit: h }) {
    const t = g, T = h, r = C(g, "modelValue"), { t: u } = F(), { root: E, dispatchEvent: w } = _(W), f = c(
      () => {
        var a, l;
        return ((l = (a = r.value) == null ? void 0 : a.images) == null ? void 0 : l.filter(
          ({ permanentDelete: e }) => !e
        )) ?? [];
      }
    ), U = c(() => [
      {
        title: u("datahub-plugin.image-value.addImage"),
        event: "createImage"
      }
    ]), M = ({ id: a }) => a ? L(
      S(),
      `${t.downloadEndpoint}?id=${encodeURIComponent(a)}`
    ) : null, I = c(() => ({
      modelValue: f.value,
      readonly: t.readOnly,
      canRemove: !t.readOnly,
      tableName: t.label,
      createActions: U.value,
      isLoading: t.loading,
      getDownloadLink: M,
      previewPrefix: `&width=${t.previewImageWidth}&height=${t.previewImageHeight}`,
      getAltText: "title",
      hideSearch: !0,
      hideReplace: !0,
      addImage: D,
      hideNoDataDescription: !0
    }));
    function A(a) {
      var l, e;
      r.value = {
        ...r.value,
        images: [
          ...((e = (l = r.value) == null ? void 0 : l.images) == null ? void 0 : e.filter(
            ({ permanentDelete: o }) => o
          )) ?? [],
          ...a
        ]
      };
    }
    const D = () => ({
      id: null,
      title: null,
      caption: null,
      altText: null,
      imageTags: null,
      sortOrder: null
    });
    async function $({
      oldImage: a,
      file: l
    }) {
      const e = Math.random().toString(36).substring(2), o = encodeURIComponent(t.baseFolder);
      let s = `${t.uploadEndpoint}?id=${o}`;
      e && (s = `${s}&prefix=${e}`);
      const { data: v } = await H(s, l);
      a.id = t.baseFolder + v, a.name = v, a.size = l.size, a.mimeType = l.type, a.link = void 0;
    }
    function O({ image: a }) {
      a.permanentDelete = !0;
    }
    return N(
      f,
      (a) => {
        const l = !!(!a.length || a.every(({ permanentDelete: e, id: o }) => e || o));
        w({ data: l }), T("validated", l);
      },
      { deep: !0, immediate: !0 }
    ), (a, l) => (k(), R(d(P), z({
      ref_key: "root",
      ref: E
    }, I.value, {
      onReplace: $,
      onRemove: O,
      "onUpdate:modelValue": A
    }), {
      editor: V(({ item: e }) => [
        m(d(p), {
          modelValue: e.title,
          "onUpdate:modelValue": (o) => e.title = o,
          modelModifiers: { lazy: !0 },
          label: a.$t("common.title"),
          readonly: a.readOnly,
          class: "mt-4"
        }, null, 8, ["modelValue", "onUpdate:modelValue", "label", "readonly"]),
        m(d(p), {
          modelValue: e.caption,
          "onUpdate:modelValue": (o) => e.caption = o,
          modelModifiers: { lazy: !0 },
          label: d(u)("datahub-plugin.image-value.caption"),
          readonly: a.readOnly,
          class: "mt-4"
        }, null, 8, ["modelValue", "onUpdate:modelValue", "label", "readonly"]),
        m(d(p), {
          modelValue: e.altText,
          "onUpdate:modelValue": (o) => e.altText = o,
          modelModifiers: { lazy: !0 },
          label: d(u)("datahub-plugin.image-value.altText"),
          readonly: a.readOnly,
          class: "mt-4"
        }, null, 8, ["modelValue", "onUpdate:modelValue", "label", "readonly"]),
        m(d(p), {
          modelValue: e.imageTags,
          "onUpdate:modelValue": (o) => e.imageTags = o,
          modelModifiers: { lazy: !0 },
          label: d(u)("datahub-plugin.image-value.imageTags"),
          readonly: a.readOnly,
          class: "mt-4"
        }, null, 8, ["modelValue", "onUpdate:modelValue", "label", "readonly"])
      ]),
      details: V(({ item: e }) => [
        i("div", null, n(e.name), 1),
        i("div", null, n(e.caption), 1),
        i("div", null, n(e.altText), 1),
        i("div", null, n(e.imageTags), 1),
        i("div", null, n(e.mimeType), 1),
        i("div", null, n(e.created), 1),
        B(" " + n(e), 1)
      ]),
      _: 1
    }, 16));
  }
});
typeof b == "function" && b(j);
export {
  j as default
};
