import { defineComponent as q, mergeModels as P, useModel as K, ref as c, createBlock as A, openBlock as h, unref as e, withCtx as a, createElementVNode as W, createVNode as i, createCommentVNode as D, toDisplayString as N, createTextVNode as X, computed as H, mergeProps as Y, isRef as J, watch as ie, withModifiers as ne } from "vue";
import { X as Z, e as ue, Y as oe, I as Q, ai as ee, aj as re, aa as te, b3 as se, b4 as de, o as me, aH as pe, aK as U, ak as ge, h as be, i as fe, c as T, k as x, a as G } from "./start-CE9SawgU.js";
import "vue-i18n";
import { storeToRefs as ve } from "pinia";
import "./header-Bn1EKnBE.js";
import { e as _, E as ce, n as F, T as B, c as Ae, o as he } from "./topBarRoutes-CBd5qLxn.js";
import Se from "./IsActiveStatusCell-xz7XnAYP.js";
import { E as Ve } from "./EditAttributeMapping-CrfwYxpD.js";
const Ee = /* @__PURE__ */ q({
  __name: "RerunAllMappings",
  props: /* @__PURE__ */ P({
    type: {},
    loading: { type: Boolean }
  }, {
    modelValue: { type: Boolean },
    modelModifiers: {}
  }),
  emits: /* @__PURE__ */ P(["save"], ["update:modelValue"]),
  setup(w) {
    const s = {
      all: {
        title: "datahub-ui.etl.rerunAllMappings",
        description: "datahub-ui.etl.rerunAllMappingsDescription",
        warning: "datahub-ui.etl.rerunAffectedAttributesWarning"
      },
      selected: {
        title: "datahub-ui.etl.rerunSelectedMapping",
        description: "datahub-ui.etl.rerunSelectedMappingDescription",
        warning: ""
      }
    }, f = K(w, "modelValue"), n = c(!1);
    return (t, d) => (h(), A(e(Z), {
      modelValue: f.value,
      "onUpdate:modelValue": d[2] || (d[2] = (g) => f.value = g),
      title: t.$t(s[t.type].title),
      "min-width": "600px",
      "max-width": "800px"
    }, {
      actions: a(() => [
        i(e(Q), {
          text: t.$t("datahub-ui.dh-shared.save"),
          loading: t.loading,
          color: "primary",
          onClick: d[0] || (d[0] = (g) => t.$emit("save", n.value))
        }, null, 8, ["text", "loading"])
      ]),
      default: a(() => [
        W("div", null, N(t.$t(s[t.type].description)), 1),
        i(e(ue), {
          modelValue: n.value,
          "onUpdate:modelValue": d[1] || (d[1] = (g) => n.value = g),
          label: t.$t("datahub-ui.etl.rerunManualTracking"),
          class: "my-4"
        }, null, 8, ["modelValue", "label"]),
        s[t.type].warning ? (h(), A(e(oe), {
          key: 0,
          icon: "lucide:triangle-alert",
          type: "error"
        }, {
          default: a(() => [
            X(N(t.$t(s[t.type].warning)), 1)
          ]),
          _: 1
        })) : D("", !0)
      ]),
      _: 1
    }, 8, ["modelValue", "title"]));
  }
}), we = { class: "chip-content" }, $e = /* @__PURE__ */ q({
  __name: "EditEtlDetails",
  props: {
    id: {},
    pluginName: {},
    row: {}
  },
  setup(w) {
    const s = w, {
      table: f,
      isLoading: n,
      showChangeDialog: t,
      showError: d,
      onAddRow: g,
      onEditRow: S,
      onDeleteRows: V,
      batchApiCalls: E
    } = ee({
      addApi: _.create,
      editApi: _.update,
      deleteApi: _.delete
    }), v = c(!1), y = c("all"), I = c([]), M = c([]), $ = c(), C = H(
      () => s.row ? `"${s.row?.sourceAttributeSet.name}" - "${s.row?.destinationAttributeSet.name}"` : ""
    ), k = H(() => ({
      attributeSetMapId: Number(s.id),
      hideInactive: M.value[0] === 0
    }));
    async function O(l) {
      try {
        n.value = !0, y.value === "all" ? await F.rerunMappings(
          Number(s.id),
          l
        ) : await Promise.all(
          I.value.map(
            (o) => F.rerunMapping(Number(o), l)
          )
        ), v.value = !1;
      } finally {
        n.value = !1;
      }
    }
    function L(l) {
      y.value = l, v.value = !0;
    }
    function R(l) {
      l.m?.destinationAttributeNotMappable || (t.value = !0, $.value = l);
    }
    async function b(l, o) {
      switch (l) {
        case B.CUSTOM_SCOPE:
          R({ ...o[0], em: null });
          return;
        case B.DELETE:
          await E(
            V,
            o.map(({ em: { id: u } }) => [u]),
            !1
          );
          return;
        case B.RERUN_MAPPING:
          return I.value = o.map(({ em: { id: u } }) => u), L("selected");
        case B.ADD_MAPPING:
          try {
            n.value = !0, I.value = o.map(({ a: { id: u } }) => u), await Promise.all(
              I.value.map(
                (u) => _.addSourceAndMap(Number(s.id), u)
              )
            );
          } finally {
            n.value = !1;
          }
      }
    }
    async function z(l) {
      $.value.em ? await S(l) : await g(l), !d.value && (t.value = !1);
    }
    return (l, o) => (h(), A(e(re), { overflow: "hidden" }, {
      "toolbar-title": a(() => [
        X(N(l.$t("datahub-ui.etl.editMapping")) + " " + N(C.value), 1)
      ]),
      default: a(() => [
        l.id ? (h(), A(e(te), Y({
          key: 0,
          ref_key: "table",
          ref: f,
          "disable-actions": e(n),
          "custom-query": k.value,
          embedded: "",
          class: "flex-grow-1"
        }, e(ce), {
          onAction: b,
          onClickedRow: R
        }), {
          globalActions: a(({ disabled: u }) => [
            i(e(Q), {
              variant: "outlined",
              color: "primary",
              text: l.$t("datahub-ui.etl.rerunMappings"),
              disabled: u,
              onClick: o[0] || (o[0] = (j) => L("all"))
            }, null, 8, ["text", "disabled"])
          ]),
          filters: a(() => [
            i(e(se), {
              modelValue: M.value,
              "onUpdate:modelValue": o[1] || (o[1] = (u) => M.value = u),
              multiple: ""
            }, {
              default: a(() => [
                i(e(de), {
                  variant: "flat",
                  filter: ""
                }, {
                  default: a(() => [
                    W("span", we, N(l.$t("datahub-ui.etl.persistentFilter")), 1)
                  ]),
                  _: 1
                })
              ]),
              _: 1
            }, 8, ["modelValue"])
          ]),
          "cell-a.active": a(({ cellValue: u }) => [
            i(Se, {
              "cell-value": u !== !1
            }, null, 8, ["cell-value"])
          ]),
          modals: a(() => [
            v.value ? (h(), A(Ee, {
              key: 0,
              modelValue: v.value,
              "onUpdate:modelValue": o[2] || (o[2] = (u) => v.value = u),
              loading: e(n),
              type: y.value,
              onSave: O
            }, null, 8, ["modelValue", "loading", "type"])) : D("", !0),
            e(t) ? (h(), A(Ve, {
              key: 1,
              id: Number(l.id),
              modelValue: e(t),
              "onUpdate:modelValue": o[3] || (o[3] = (u) => J(t) ? t.value = u : null),
              "attribute-map": $.value.em,
              "destination-attribute": $.value.a,
              loading: e(n),
              "plugin-name": l.pluginName,
              onSave: z
            }, null, 8, ["id", "modelValue", "attribute-map", "destination-attribute", "loading", "plugin-name"])) : D("", !0)
          ]),
          _: 2
        }, 1040, ["disable-actions", "custom-query"])) : D("", !0)
      ]),
      _: 1
    }));
  }
}), ye = /* @__PURE__ */ me($e, [["__scopeId", "data-v-08b99ea7"]]), Ie = /* @__PURE__ */ q({
  __name: "CreateEtl",
  props: /* @__PURE__ */ P({
    pluginName: {}
  }, {
    modelValue: { type: Boolean },
    modelModifiers: {}
  }),
  emits: /* @__PURE__ */ P(["save"], ["update:modelValue"]),
  setup(w, { emit: s }) {
    const f = w, n = s, t = K(w, "modelValue"), d = Ae(f.pluginName), {
      languages: g,
      isLoadingLanguages: S,
      scopes: V,
      isLoadingScopes: E,
      isLoadingMatchingETLAttributeSetMap: v,
      matchingETLAttributeSetMap: y
    } = ve(d), { fetchMatchingETLAttributeSetMaps: I, attributeSetsApi: M } = d, $ = H(
      () => y.value.map(
        ({ sourceAttributeSet: p, destinationAttributeSet: r }) => `${p.name} -> ${r.name}`
      )
    ), C = c(null), k = c(null), O = `${f.pluginName}-etl-create`, L = c({
      dhSourceAttributeSetId: void 0,
      dhDestinationAttributeSetId: void 0,
      dhLanguageId: void 0,
      dhScopeId: void 0,
      parentETLAttributeSetId: void 0
    }), R = {
      dhSourceAttributeSetId: U,
      dhDestinationAttributeSetId: U,
      dhLanguageId: U,
      dhScopeId: U,
      parentETLAttributeSetId: {}
    }, {
      v$: b,
      isValid: z,
      dhSourceAttributeSetIdErrors: l,
      dhDestinationAttributeSetIdErrors: o,
      dhLanguageIdErrors: u,
      dhScopeIdErrors: j,
      parentETLAttributeSetIdErrors: ae
    } = pe(O, {
      rules: R,
      form: L
    });
    function le() {
      n("save", L.value);
    }
    return ie(
      () => L.value.dhDestinationAttributeSetId,
      async (p) => {
        if (!p) {
          y.value = [];
          return;
        }
        await I(p);
      },
      { immediate: !0 }
    ), (p, r) => (h(), A(e(Z), {
      modelValue: t.value,
      "onUpdate:modelValue": r[6] || (r[6] = (m) => t.value = m),
      title: p.$t("datahub-ui.dh-shared.newEtlMapping"),
      "min-width": "600px",
      "max-width": "600px"
    }, {
      actions: a(() => [
        i(e(Q), {
          disabled: !e(z),
          text: p.$t("datahub-ui.dh-shared.save"),
          color: "primary",
          onClick: le
        }, null, 8, ["disabled", "text"])
      ]),
      default: a(() => [
        i(e(ge), {
          onSubmit: r[5] || (r[5] = ne(() => {
          }, ["prevent"]))
        }, {
          default: a(() => [
            i(e(be), {
              class: "pa-0 mt-1",
              fluid: ""
            }, {
              default: a(() => [
                i(e(fe), null, {
                  default: a(() => [
                    i(e(T), null, {
                      default: a(() => [
                        i(e(x), {
                          data: e(M).getList,
                          text: C.value?.name,
                          label: p.$t("datahub-ui.dh-shared.sourceAttributeSet"),
                          "item-title": "name",
                          "item-value": "id",
                          "page-size": "",
                          select: "",
                          block: "",
                          "error-messages": e(l),
                          required: "",
                          "prepend-text": "",
                          search: "",
                          onChange: r[0] || (r[0] = (m) => {
                            C.value = m, e(b).dhSourceAttributeSetId.$model = m?.id;
                          })
                        }, null, 8, ["data", "text", "label", "error-messages"])
                      ]),
                      _: 1
                    }),
                    i(e(T), null, {
                      default: a(() => [
                        i(e(x), {
                          data: e(M).getList,
                          text: k.value?.name,
                          label: p.$t("datahub-ui.dh-shared.destinationAttributeSet"),
                          "item-title": "name",
                          "item-value": "id",
                          "page-size": "",
                          select: "",
                          block: "",
                          "error-messages": e(o),
                          required: "",
                          "prepend-text": "",
                          search: "",
                          onChange: r[1] || (r[1] = (m) => {
                            k.value = m, e(b).dhDestinationAttributeSetId.$model = m?.id;
                          })
                        }, null, 8, ["data", "text", "label", "error-messages"])
                      ]),
                      _: 1
                    }),
                    i(e(T), null, {
                      default: a(() => [
                        i(e(G), {
                          modelValue: e(b).dhLanguageId.$model,
                          "onUpdate:modelValue": r[2] || (r[2] = (m) => e(b).dhLanguageId.$model = m),
                          label: p.$t("datahub-ui.etl.language"),
                          "error-messages": e(u),
                          items: e(g),
                          loading: e(S),
                          "item-title": "description",
                          "item-value": "id",
                          required: "",
                          search: "",
                          "page-size": ""
                        }, null, 8, ["modelValue", "label", "error-messages", "items", "loading"])
                      ]),
                      _: 1
                    }),
                    i(e(T), null, {
                      default: a(() => [
                        i(e(G), {
                          modelValue: e(b).dhScopeId.$model,
                          "onUpdate:modelValue": r[3] || (r[3] = (m) => e(b).dhScopeId.$model = m),
                          label: p.$t("datahub-ui.etl.channel"),
                          "error-messages": e(j),
                          items: e(V),
                          loading: e(E),
                          "item-title": "name",
                          "item-value": "id",
                          required: "",
                          search: "",
                          "page-size": ""
                        }, null, 8, ["modelValue", "label", "error-messages", "items", "loading"])
                      ]),
                      _: 1
                    }),
                    i(e(T), null, {
                      default: a(() => [
                        i(e(G), {
                          modelValue: e(b).parentETLAttributeSetId.$model,
                          "onUpdate:modelValue": r[4] || (r[4] = (m) => e(b).parentETLAttributeSetId.$model = m),
                          label: p.$t("datahub-ui.etl.copyETLSetMaps"),
                          "error-messages": e(ae),
                          items: $.value,
                          loading: e(v),
                          readonly: !$.value.length,
                          clearable: ""
                        }, null, 8, ["modelValue", "label", "error-messages", "items", "loading", "readonly"])
                      ]),
                      _: 1
                    })
                  ]),
                  _: 1
                })
              ]),
              _: 1
            })
          ]),
          _: 1
        })
      ]),
      _: 1
    }, 8, ["modelValue", "title"]));
  }
}), Ue = /* @__PURE__ */ q({
  __name: "EtlListView",
  props: {
    pluginName: {}
  },
  setup(w) {
    const { table: s, isLoading: f, showChangeDialog: n, showError: t, onAddRow: d } = ee({
      addApi: F.create
    });
    async function g(S) {
      await d(S), !t.value && (n.value = !1);
    }
    return (S, V) => (h(), A(e(te), Y({
      ref_key: "table",
      ref: s,
      "disable-actions": e(f)
    }, e(he), {
      onCreate: V[1] || (V[1] = (E) => n.value = !0)
    }), {
      modals: a(() => [
        e(n) ? (h(), A(Ie, {
          key: 0,
          modelValue: e(n),
          "onUpdate:modelValue": V[0] || (V[0] = (E) => J(n) ? n.value = E : null),
          "plugin-name": S.pluginName,
          onSave: g
        }, null, 8, ["modelValue", "plugin-name"])) : D("", !0)
      ]),
      details: a(({ rowId: E, row: v }) => [
        i(ye, {
          id: E,
          "plugin-name": S.pluginName,
          row: v
        }, null, 8, ["id", "plugin-name", "row"])
      ]),
      _: 1
    }, 16, ["disable-actions"]));
  }
});
export {
  Ue as default
};
