import { computed as V, defineComponent as F, mergeModels as W, useModel as q, ref as y, createBlock as v, openBlock as A, unref as e, withCtx as i, createElementVNode as J, createVNode as d, createCommentVNode as k, toDisplayString as _, createTextVNode as K, mergeProps as x, isRef as X, watch as re, withModifiers as ne } from "vue";
import { a7 as N, V as Z, W as ee, I as te, c as de, J as oe, E as Q, aa as ae, ac as ue, a3 as le, aS as se, aT as me, l as pe, az as be, aC as B, ad as fe, f as he, g as ge, a as C, h as R } from "./start-BYfL32Oe.mjs";
import { useI18n as j } from "vue-i18n";
import { storeToRefs as ce } from "pinia";
import "vue-router";
import { b as ve } from "./header-Droxy2Kd.mjs";
import "./moment-h96o7c8I.mjs";
import { k as z, T as L, c as Ae } from "./topBarRoutes-0VuQ_i6D.mjs";
import { e as U } from "./ETLAttributeMaps-CQdXyXVn.mjs";
import { n as Se, o as Ie, p as Ee } from "./DatahubDataTypeEditor.vue_vue_type_script_setup_true_lang-WxvRaHzL.mjs";
import { E as Ve } from "./EditAttributeMapping-DgbKIxwV.mjs";
const ye = {
  data: z.getList,
  gridId: "datahub-etl",
  rowSelection: ee.MULTI,
  hideGlobalSearch: !1,
  hideFilters: !1,
  hideColumnCustomization: !1,
  hidePagination: !1,
  sortType: Z.SINGLE,
  routableId: "etlId",
  createActions: !0,
  exactRowCount: !1,
  columns: [
    {
      id: "sourceAttributeSet.name",
      header: "datahub-ui.dh-shared.sourceAttributeSet",
      minWidth: 200,
      filterable: N.STRING,
      sortable: !0
    },
    {
      id: "destinationAttributeSet.name",
      header: "datahub-ui.etl.destinationAttributeSet",
      minWidth: 200,
      filterable: N.STRING,
      sortable: !0
    },
    {
      id: "scope.name",
      header: "datahub-ui.etl.outputChannel",
      minWidth: 200,
      filterable: N.STRING,
      sortable: !0
    },
    {
      id: "language.description",
      header: "datahub-ui.etl.language",
      minWidth: 200,
      filterable: N.STRING,
      sortable: !0
    },
    {
      id: "created",
      header: "datahub-ui.dh-table.created",
      minWidth: 200,
      filterable: N.DATE,
      sortable: !0
    },
    {
      id: "createdByUsername",
      header: "datahub-ui.dh-table.createdByUsername",
      minWidth: 200,
      isVisible: !1,
      filterable: !1,
      sortable: !1
    },
    {
      id: "modified",
      header: "datahub-ui.dh-table.modified",
      minWidth: 200,
      isVisible: !1,
      filterable: N.DATE,
      sortable: !0
    },
    {
      id: "modifiedByUsername",
      header: "datahub-ui.dh-table.modifiedByUsername",
      minWidth: 200,
      isVisible: !1,
      filterable: !1,
      sortable: !1
    }
  ]
}, Me = {
  data: U.getList,
  gridId: "datahub-etl-attributes",
  rowSelection: ee.SINGLE,
  hideGlobalSearch: !1,
  hideFilters: !1,
  hideColumnCustomization: !1,
  hidePagination: !1,
  sortType: Z.SINGLE,
  createActions: !1,
  lockedProperty: "m.destinationAttributeNotMappable",
  rowIdName: "a.id",
  // @ why don't work
  tableActions: [
    {
      title: "datahub-ui.etl.rerunMapping",
      event: L.RERUN_MAPPING,
      variant: "elevated",
      color: "primary",
      prepareIsHidden: ({ selectedRows: t }) => V(
        () => !!t.value.length && (t.value.some(
          ({ m: a }) => a.destinationAttributeNotMappable
        ) || t.value.every(({ em: a }) => !a))
      ),
      prepareIsDisabled: ({ selectedRows: t }) => V(
        () => !t.value.length || t.value.some(({ em: a }) => !a)
      )
    },
    {
      title: "datahub-ui.etl.addAndMap",
      event: L.ADD_MAPPING,
      variant: "elevated",
      color: "primary",
      prepareIsHidden: ({ selectedRows: t }) => V(
        () => !t.value.length || t.value.some(
          ({ em: a, m: s }) => a || s.destinationAttributeNotMappable
        )
      ),
      prepareIsDisabled: ({ selectedRows: t }) => V(() => !t.value.length)
    },
    {
      icon: "delete",
      title: "common.delete",
      event: L.DELETE,
      color: "alert",
      prepareIsDisabled: ({ selectedRows: t }) => V(
        () => !t.value.length || t.value.some(({ em: a }) => !a)
      )
    }
  ],
  columns: [
    {
      id: "sourceAttribute",
      header: "datahub-ui.dh-shared.sourceAttribute",
      minWidth: 200,
      filterable: !1,
      sortable: !1,
      accessor: ({ em: t }) => {
        const a = t == null ? void 0 : t.sourcePorts;
        return a != null && a.length ? a.map((s) => Se(s) + Ie(s)).join(", ") : j().t("datahub-ui.etl.emptySourceAttribute");
      }
    },
    {
      id: "extension",
      header: "datahub-ui.dh-shared.extension",
      minWidth: 200,
      filterable: !1,
      sortable: !1,
      accessor: ({ em: t }) => {
        const a = t == null ? void 0 : t.extensionName, s = ve[t == null ? void 0 : t.overrideChangeTrackingMode];
        return a ? a + (s ? ` (${j().t(s)})` : "") : "";
      }
    },
    {
      id: "destinationAttribute",
      header: "datahub-ui.etl.destinationAttribute",
      minWidth: 200,
      filterable: !1,
      sortable: !1,
      accessor: ({ a: t, em: a }) => `${t.name} ${Ee(a)}`
    },
    {
      id: "a.active",
      header: "datahub-ui.dh-table.isActive",
      width: 200,
      renderer: "IsActiveStatusCell",
      filterable: !1,
      sortable: !1
    },
    {
      id: "m.destinationAttributeNotMappable",
      header: "datahub-ui.etl.notMappable",
      width: 200,
      renderer: "CheckboxCell",
      filterable: !1,
      sortable: !1
    }
  ]
}, Te = /* @__PURE__ */ F({
  __name: "RerunAllMappings",
  props: /* @__PURE__ */ W({
    type: {},
    loading: { type: Boolean }
  }, {
    modelValue: { type: Boolean },
    modelModifiers: {}
  }),
  emits: /* @__PURE__ */ W(["save"], ["update:modelValue"]),
  setup(t) {
    const a = {
      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: ""
      }
    }, s = q(t, "modelValue"), r = y(!1);
    return (l, p) => (A(), v(e(te), {
      modelValue: s.value,
      "onUpdate:modelValue": p[2] || (p[2] = (h) => s.value = h),
      title: l.$t(a[l.type].title),
      "min-width": "600px",
      "max-width": "800px"
    }, {
      actions: i(() => [
        d(e(Q), {
          variant: "elevated",
          text: l.$t("datahub-ui.dh-shared.save"),
          loading: l.loading,
          onClick: p[0] || (p[0] = (h) => l.$emit("save", r.value))
        }, null, 8, ["text", "loading"])
      ]),
      default: i(() => [
        J("div", null, _(l.$t(a[l.type].description)), 1),
        d(e(de), {
          modelValue: r.value,
          "onUpdate:modelValue": p[1] || (p[1] = (h) => r.value = h),
          label: l.$t("datahub-ui.etl.rerunManualTracking"),
          class: "my-4"
        }, null, 8, ["modelValue", "label"]),
        a[l.type].warning ? (A(), v(e(oe), {
          key: 0,
          icon: "warning",
          type: "error"
        }, {
          default: i(() => [
            K(_(l.$t(a[l.type].warning)), 1)
          ]),
          _: 1
        })) : k("", !0)
      ]),
      _: 1
    }, 8, ["modelValue", "title"]));
  }
}), $e = { class: "chip-content" }, Ne = /* @__PURE__ */ F({
  __name: "EditEtlDetails",
  props: {
    id: {},
    pluginName: {}
  },
  setup(t) {
    const a = t, {
      table: s,
      isLoading: r,
      showChangeDialog: l,
      showError: p,
      onAddRow: h,
      onEditRow: c,
      onDeleteRows: S,
      batchApiCalls: I
    } = ae({
      addApi: U.create,
      editApi: U.update,
      deleteApi: U.delete
    }), E = y(!1), w = y("all"), M = y([]), T = y([]), $ = y(), P = V(() => ({
      attributeSetMapId: Number(a.id),
      hideInactive: T.value[0] === 0
    }));
    async function D(n) {
      try {
        r.value = !0, w.value === "all" ? await z.rerunMappings(
          Number(a.id),
          n
        ) : await Promise.all(
          M.value.map(
            (o) => z.rerunMapping(Number(o), n)
          )
        ), E.value = !1;
      } finally {
        r.value = !1;
      }
    }
    function G(n) {
      w.value = n, E.value = !0;
    }
    function b(n) {
      var o;
      (o = n.m) != null && o.destinationAttributeNotMappable || (l.value = !0, $.value = n);
    }
    async function H(n, o) {
      switch (n) {
        case L.DELETE:
          await I(
            S,
            o.map(({ em: { id: u } }) => [u]),
            !1
          );
          return;
        case L.RERUN_MAPPING:
          return M.value = o.map(({ em: { id: u } }) => u), G("selected");
        case L.ADD_MAPPING:
          try {
            r.value = !0, M.value = o.map(({ a: { id: u } }) => u), await Promise.all(
              M.value.map(
                (u) => U.addSourceAndMap(Number(a.id), u)
              )
            );
          } finally {
            r.value = !1;
          }
      }
    }
    async function O(n) {
      $.value.em ? await c(n) : await h(n), !p.value && (l.value = !1);
    }
    return (n, o) => (A(), v(e(ue), null, {
      "toolbar-title": i(() => [
        K(_(n.$t("datahub-ui.etl.editMapping")), 1)
      ]),
      default: i(() => [
        n.id ? (A(), v(e(le), x({
          key: 0,
          ref_key: "table",
          ref: s,
          "disable-actions": e(r),
          "custom-query": P.value
        }, e(Me), {
          onAction: H,
          onClickedRow: b
        }), {
          globalActions: i(({ disabled: u }) => [
            d(e(Q), {
              variant: "outlined",
              color: "primary",
              text: n.$t("datahub-ui.etl.rerunMappings"),
              disabled: u,
              onClick: o[0] || (o[0] = (Y) => G("all"))
            }, null, 8, ["text", "disabled"])
          ]),
          filters: i(() => [
            d(e(se), {
              modelValue: T.value,
              "onUpdate:modelValue": o[1] || (o[1] = (u) => T.value = u),
              multiple: ""
            }, {
              default: i(() => [
                d(e(me), {
                  variant: "flat",
                  filter: ""
                }, {
                  default: i(() => [
                    J("span", $e, _(n.$t("datahub-ui.etl.persistentFilter")), 1)
                  ]),
                  _: 1
                })
              ]),
              _: 1
            }, 8, ["modelValue"])
          ]),
          modals: i(() => [
            E.value ? (A(), v(Te, {
              key: 0,
              modelValue: E.value,
              "onUpdate:modelValue": o[2] || (o[2] = (u) => E.value = u),
              loading: e(r),
              type: w.value,
              onSave: D
            }, null, 8, ["modelValue", "loading", "type"])) : k("", !0),
            e(l) ? (A(), v(Ve, {
              key: 1,
              id: Number(n.id),
              modelValue: e(l),
              "onUpdate:modelValue": o[3] || (o[3] = (u) => X(l) ? l.value = u : null),
              "attribute-map": $.value.em,
              "destination-attribute": $.value.a,
              loading: e(r),
              onSave: O
            }, null, 8, ["id", "modelValue", "attribute-map", "destination-attribute", "loading"])) : k("", !0)
          ]),
          _: 1
        }, 16, ["disable-actions", "custom-query"])) : k("", !0)
      ]),
      _: 1
    }));
  }
}), Le = /* @__PURE__ */ pe(Ne, [["__scopeId", "data-v-9232fa5d"]]), we = /* @__PURE__ */ F({
  __name: "CreateEtl",
  props: /* @__PURE__ */ W({
    pluginName: {}
  }, {
    modelValue: { type: Boolean },
    modelModifiers: {}
  }),
  emits: /* @__PURE__ */ W(["save"], ["update:modelValue"]),
  setup(t, { emit: a }) {
    const s = t, r = a, l = q(t, "modelValue"), p = Ae(s.pluginName), {
      attributeSets: h,
      isLoadingAttributeSets: c,
      languages: S,
      isLoadingLanguages: I,
      scopes: E,
      isLoadingScopes: w,
      isLoadingMatchingETLAttributeSetMap: M,
      matchingETLAttributeSetMap: T
    } = ce(p), { fetchMatchingETLAttributeSetMaps: $ } = p, P = V(
      () => T.value.map(
        ({ sourceAttributeSet: f, destinationAttributeSet: m }) => `${f.name} -> ${m.name}`
      )
    ), D = y({
      dhSourceAttributeSetId: void 0,
      dhDestinationAttributeSetId: void 0,
      dhLanguageId: void 0,
      dhScopeId: void 0,
      parentETLAttributeSetId: void 0
    }), G = {
      dhSourceAttributeSetId: B,
      dhDestinationAttributeSetId: B,
      dhLanguageId: B,
      dhScopeId: B,
      parentETLAttributeSetId: {}
    }, {
      v$: b,
      isValid: H,
      dhSourceAttributeSetIdErrors: O,
      dhDestinationAttributeSetIdErrors: n,
      dhLanguageIdErrors: o,
      dhScopeIdErrors: u,
      parentETLAttributeSetIdErrors: Y
    } = be({
      rules: G,
      form: D
    });
    function ie() {
      r("save", D.value);
    }
    return re(
      () => D.value.dhDestinationAttributeSetId,
      async (f) => {
        if (!f) {
          T.value = [];
          return;
        }
        await $(f);
      },
      { immediate: !0 }
    ), (f, m) => (A(), v(e(te), {
      modelValue: l.value,
      "onUpdate:modelValue": m[6] || (m[6] = (g) => l.value = g),
      title: f.$t("datahub-ui.dh-shared.newAttribute"),
      "min-width": "600px",
      "max-width": "600px"
    }, {
      actions: i(() => [
        d(e(Q), {
          variant: "elevated",
          disabled: !e(H),
          text: f.$t("datahub-ui.dh-shared.save"),
          onClick: ie
        }, null, 8, ["disabled", "text"])
      ]),
      default: i(() => [
        d(e(fe), {
          onSubmit: m[5] || (m[5] = ne(() => {
          }, ["prevent"]))
        }, {
          default: i(() => [
            d(e(he), {
              class: "pa-0 mt-1",
              fluid: ""
            }, {
              default: i(() => [
                d(e(ge), null, {
                  default: i(() => [
                    d(e(C), null, {
                      default: i(() => [
                        d(e(R), {
                          modelValue: e(b).dhSourceAttributeSetId.$model,
                          "onUpdate:modelValue": m[0] || (m[0] = (g) => e(b).dhSourceAttributeSetId.$model = g),
                          label: f.$t("datahub-ui.dh-shared.sourceAttributeSet"),
                          "error-messages": e(O),
                          items: e(h),
                          loading: e(c),
                          "item-title": "name",
                          "item-value": "id",
                          clearable: "",
                          search: "",
                          "page-size": ""
                        }, null, 8, ["modelValue", "label", "error-messages", "items", "loading"])
                      ]),
                      _: 1
                    }),
                    d(e(C), null, {
                      default: i(() => [
                        d(e(R), {
                          modelValue: e(b).dhDestinationAttributeSetId.$model,
                          "onUpdate:modelValue": m[1] || (m[1] = (g) => e(b).dhDestinationAttributeSetId.$model = g),
                          label: f.$t("datahub-ui.etl.destinationAttributeSet"),
                          "error-messages": e(n),
                          items: e(h),
                          loading: e(c),
                          "item-title": "name",
                          "item-value": "id",
                          clearable: "",
                          search: "",
                          "page-size": ""
                        }, null, 8, ["modelValue", "label", "error-messages", "items", "loading"])
                      ]),
                      _: 1
                    }),
                    d(e(C), null, {
                      default: i(() => [
                        d(e(R), {
                          modelValue: e(b).dhLanguageId.$model,
                          "onUpdate:modelValue": m[2] || (m[2] = (g) => e(b).dhLanguageId.$model = g),
                          label: f.$t("datahub-ui.etl.language"),
                          "error-messages": e(o),
                          items: e(S),
                          loading: e(I),
                          "item-title": "description",
                          "item-value": "id",
                          clearable: "",
                          search: "",
                          "page-size": ""
                        }, null, 8, ["modelValue", "label", "error-messages", "items", "loading"])
                      ]),
                      _: 1
                    }),
                    d(e(C), null, {
                      default: i(() => [
                        d(e(R), {
                          modelValue: e(b).dhScopeId.$model,
                          "onUpdate:modelValue": m[3] || (m[3] = (g) => e(b).dhScopeId.$model = g),
                          label: f.$t("datahub-ui.etl.channel"),
                          "error-messages": e(u),
                          items: e(E),
                          loading: e(w),
                          "item-title": "name",
                          "item-value": "id",
                          clearable: "",
                          search: "",
                          "page-size": ""
                        }, null, 8, ["modelValue", "label", "error-messages", "items", "loading"])
                      ]),
                      _: 1
                    }),
                    d(e(C), null, {
                      default: i(() => [
                        d(e(R), {
                          modelValue: e(b).parentETLAttributeSetId.$model,
                          "onUpdate:modelValue": m[4] || (m[4] = (g) => e(b).parentETLAttributeSetId.$model = g),
                          label: f.$t("datahub-ui.etl.copyETLSetMaps"),
                          "error-messages": e(Y),
                          items: P.value,
                          loading: e(M),
                          readonly: !P.value.length,
                          clearable: ""
                        }, null, 8, ["modelValue", "label", "error-messages", "items", "loading", "readonly"])
                      ]),
                      _: 1
                    })
                  ]),
                  _: 1
                })
              ]),
              _: 1
            })
          ]),
          _: 1
        })
      ]),
      _: 1
    }, 8, ["modelValue", "title"]));
  }
}), Fe = /* @__PURE__ */ F({
  __name: "EtlListView",
  props: {
    pluginName: {}
  },
  setup(t) {
    const { table: a, isLoading: s, showChangeDialog: r, showError: l, onAddRow: p } = ae({
      addApi: z.create
    });
    async function h(c) {
      await p(c), !l.value && (r.value = !1);
    }
    return (c, S) => (A(), v(e(le), x({
      ref_key: "table",
      ref: a,
      "disable-actions": e(s)
    }, e(ye), {
      onCreate: S[1] || (S[1] = (I) => r.value = !0)
    }), {
      modals: i(() => [
        e(r) ? (A(), v(we, {
          key: 0,
          modelValue: e(r),
          "onUpdate:modelValue": S[0] || (S[0] = (I) => X(r) ? r.value = I : null),
          "plugin-name": c.pluginName,
          onSave: h
        }, null, 8, ["modelValue", "plugin-name"])) : k("", !0)
      ]),
      details: i(({ rowId: I }) => [
        d(Le, {
          id: I,
          "plugin-name": c.pluginName
        }, null, 8, ["id", "plugin-name"])
      ]),
      _: 1
    }, 16, ["disable-actions"]));
  }
});
export {
  Fe as default
};
