import { defineComponent as $, inject as V, computed as m, ref as n, watch as B, onMounted as D, createBlock as f, openBlock as b, unref as a, withCtx as p, createVNode as u, mergeProps as H, createElementVNode as M, createElementBlock as j, Fragment as z } from "vue";
import { useRouter as F } from "vue-router";
import { storeToRefs as J } from "pinia";
import { aa as K, a6 as Q, i as X, j as Y, a4 as Z, E as q, ak as ee, a9 as te, l as ae } from "./start-BYfL32Oe.mjs";
import "vue-i18n";
import "./header-Droxy2Kd.mjs";
import "./moment-h96o7c8I.mjs";
import { L as ie } from "./localPluginIntercom-Q4ih1XJC.mjs";
import { c as se, p as oe, R as re } from "./topBarRoutes-0VuQ_i6D.mjs";
const de = {
  // data: groupsApi.getAttributes,
  gridId: "datahub-group-attributes",
  hideGlobalSearch: !1,
  minRowCount: 1,
  hidePagination: !0,
  canReorderHeaders: !1,
  columns: [
    {
      id: "id",
      header: "common.id",
      isVisible: !1,
      minWidth: 200
    },
    {
      id: "active",
      header: "datahub-ui.dh-table.status",
      renderer: "IsActiveStatusCell",
      minWidth: 100,
      width: 150
    },
    {
      id: "key",
      header: "datahub-ui.dh-table.key",
      minWidth: 200
    },
    {
      id: "name",
      header: "datahub-ui.dh-table.name",
      minWidth: 200
    },
    {
      id: "description",
      header: "datahub-ui.dh-table.description",
      minWidth: 200
    },
    {
      id: "ownerPluginName",
      header: "datahub-ui.dh-table.ownerPluginName",
      minWidth: 200
    },
    {
      id: "readOnly",
      header: "datahub-ui.dh-table.readOnly",
      renderer: "CheckboxCell",
      width: 150
    }
  ]
}, ne = { class: "d-flex flex-column ma-4" }, ue = /* @__PURE__ */ $({
  __name: "AttributeGroupsView",
  props: {
    pluginName: {}
  },
  setup(A) {
    const g = A, w = F(), l = se(g.pluginName), {
      attributes: _,
      groups: R,
      isGroupsLoading: E
    } = J(l), { groupsApi: d } = l, { navigationItem: L } = V(ie), y = m(
      () => oe(L.name, re.ATTRIBUTE_GROUPS_MANAGE)
    ), { isLoading: G, showError: h, onAddRow: I, onEditRow: C, onDeleteRows: N } = K({
      addApi: d.addAttribute,
      editApi: d.updateAttributes,
      deleteApi: d.removeAttribute
    }), s = n(), c = n(!1), i = n([]), r = n(""), v = m({
      get: () => r.value ? i.value.filter(({ key: e, name: t }) => (e == null ? void 0 : e.includes(r.value)) || (t == null ? void 0 : t.toLocaleLowerCase().includes(r.value))) : i.value,
      set: (e) => {
        i.value = e;
      }
    }), T = m(
      () => _.value.filter(
        ({ key: e }) => i.value.every((t) => t.key !== e)
      )
    );
    function S() {
      w.push({ name: y.value });
    }
    async function k(e) {
      try {
        c.value = !0;
        const { data: t } = await d.getAttributes({ groupId: e });
        i.value = t;
      } catch (t) {
        console.log(t.message);
      } finally {
        c.value = !1;
      }
    }
    async function x(e, t) {
      await I(s.value.id, t.id), h.value || i.value.push(t);
    }
    async function P(e) {
      await C(s.value.id, te(e));
    }
    async function U({ row: e }) {
      await N(s.value.id, e.id), h.value || (i.value = i.value.filter(({ id: t }) => t !== e.id));
    }
    function W({ query: e }) {
      r.value = e == null ? void 0 : e.toLocaleLowerCase();
    }
    return B(
      () => {
        var e;
        return (e = s.value) == null ? void 0 : e.id;
      },
      (e) => {
        i.value = [], e && k(e);
      },
      { immediate: !1 }
    ), D(l.fetchAttributeGroups), (e, t) => (b(), f(a(Q), { class: "app-sheet" }, {
      sidebar: p(() => {
        var o;
        return [
          M("div", ne, [
            a(E) ? (b(), f(a(Z), {
              key: 0,
              class: "mx-auto",
              width: "4",
              size: "40"
            })) : (b(), j(z, { key: 1 }, [
              u(a(q), {
                text: e.$t("datahub-ui.dh-shared.manageGroups"),
                variant: "outlined",
                color: "primary",
                class: "mb-4",
                onClick: S
              }, null, 8, ["text"]),
              u(a(ee), {
                items: a(R),
                "active-id": (o = s.value) == null ? void 0 : o.id,
                onSelected: t[0] || (t[0] = (O) => s.value = O)
              }, null, 8, ["items", "active-id"])
            ], 64))
          ])
        ];
      }),
      default: p(() => [
        u(a(X), H({
          data: v.value,
          "onUpdate:data": t[1] || (t[1] = (o) => v.value = o),
          "is-loading": c.value,
          readonly: !s.value,
          "table-name": e.$t("datahub-ui.dh-shared.assignedAttributes"),
          class: "pa-4",
          "can-reorder-rows": !r.value
        }, a(de), {
          onRemove: U,
          onRecalculate: W,
          "onUpdate:data": P
        }), {
          actions: p(({ readonly: o }) => [
            u(a(Y), {
              data: T.value,
              text: e.$t("datahub-ui.dh-shared.newAttribute"),
              disabled: o,
              "show-skeleton": a(G),
              "item-title": "name",
              "item-value": "id",
              color: "primary",
              "page-size": "",
              search: "",
              onEvent: x
            }, null, 8, ["data", "text", "disabled", "show-skeleton"])
          ]),
          _: 1
        }, 16, ["data", "is-loading", "readonly", "table-name", "can-reorder-rows"])
      ]),
      _: 1
    }));
  }
}), ge = /* @__PURE__ */ ae(ue, [["__scopeId", "data-v-7fba9c7b"]]);
export {
  ge as default
};
