import { defineComponent as V, inject as B, computed as b, ref as n, watch as W, onBeforeMount as D, createBlock as g, openBlock as h, unref as t, withCtx as p, createVNode as d, mergeProps as H, createElementVNode as M, createElementBlock as q, Fragment as j } from "vue";
import { useRouter as z } from "vue-router";
import { storeToRefs as F } from "pinia";
import { ai as Q, ae as J, j as K, ag as X, k as Y, b2 as Z, I as ee, aq as ae, ah as te, o as ie } from "./start-CE9SawgU.js";
import "vue-i18n";
import "./header-Bn1EKnBE.js";
import { L as se } from "./localPluginIntercom-4lCtV0uu.js";
import { c as oe, p as re, i as ue } from "./topBarRoutes-CBd5qLxn.js";
const ne = {
  // data: groupsApi.getAttributes,
  gridId: "datahub-group-attributes",
  hideGlobalSearch: !1,
  minRowCount: 1,
  hidePagination: !0,
  canReorderHeaders: !1,
  reloadOnLocaleChange: !0,
  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,
      className: "monospaced"
    },
    {
      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
    }
  ]
}, de = { class: "d-flex flex-column ma-4" }, le = /* @__PURE__ */ V({
  __name: "AttributeGroupsView",
  props: {
    pluginName: {}
  },
  setup(A) {
    const w = A, y = z(), l = oe(w.pluginName), { groups: _, isGroupsLoading: R } = F(l), { groupsApi: o } = l, { navigationItem: L } = B(se), C = b(
      () => re(
        L.name,
        ue.ATTRIBUTE_GROUPS_MANAGE
      )
    ), { isLoading: I, showError: f, onAddRow: N, onEditRow: k, onDeleteRows: G } = Q({
      addApi: o.addAttribute,
      editApi: o.updateAttributes,
      deleteApi: o.removeAttribute
    }), i = n(), c = n(!1), m = n(!1), s = n([]), r = n(""), v = b({
      get: () => r.value ? s.value.filter(({ key: e, name: a }) => e?.includes(r.value) || a?.toLocaleLowerCase().includes(r.value)) : s.value,
      set: (e) => {
        s.value = e;
      }
    }), T = b(() => ({
      groupId: i.value?.id || 0,
      flagListAll: m.value
    }));
    function U() {
      y.push({ name: C.value });
    }
    async function E(e) {
      try {
        c.value = !0;
        const { data: a } = await o.getAttributes({ groupId: e });
        s.value = a;
      } catch (a) {
        console.log(a.message);
      } finally {
        c.value = !1;
      }
    }
    async function O(e) {
      await N(i.value?.id, e.id), f.value || s.value.push(e);
    }
    async function S(e) {
      await k(i.value?.id, te(e));
    }
    async function $({ row: e }) {
      await G(i.value?.id, e.id), f.value || (s.value = s.value.filter(({ id: a }) => a !== e.id));
    }
    function x({ query: e }) {
      r.value = e?.toLocaleLowerCase() || "";
    }
    return W(
      () => i.value?.id,
      (e) => {
        s.value = [], e && E(e);
      },
      { immediate: !1 }
    ), D(l.fetchAttributeGroups), (e, a) => (h(), g(t(J), { class: "sheet" }, {
      sidebar: p(() => [
        M("div", de, [
          t(R) ? (h(), g(t(Z), {
            key: 0,
            class: "mx-auto",
            width: "4",
            size: "40"
          })) : (h(), q(j, { key: 1 }, [
            d(t(ee), {
              text: e.$t("datahub-ui.dh-shared.manageGroups"),
              variant: "outlined",
              color: "primary",
              class: "mb-4",
              onClick: U
            }, null, 8, ["text"]),
            d(t(ae), {
              items: t(_),
              "active-id": i.value?.id,
              onSelected: a[0] || (a[0] = (u) => i.value = u)
            }, null, 8, ["items", "active-id"])
          ], 64))
        ])
      ]),
      default: p(() => [
        d(t(K), H({
          data: v.value,
          "onUpdate:data": a[2] || (a[2] = (u) => v.value = u),
          "is-loading": c.value,
          readonly: !i.value,
          "table-name": e.$t("datahub-ui.dh-shared.assignedAttributes"),
          class: "pa-4",
          "can-reorder-rows": !r.value
        }, t(ne), {
          onRemove: $,
          onRecalculate: x,
          "onUpdate:data": S
        }), {
          actions: p(({ readonly: u }) => [
            d(t(X), {
              modelValue: m.value,
              "onUpdate:modelValue": a[1] || (a[1] = (P) => m.value = P),
              label: e.$t("datahub-ui.dh-shared.unassignedAttributesOnly"),
              color: "primary",
              class: "mr-4"
            }, null, 8, ["modelValue", "label"]),
            d(t(Y), {
              data: t(o).getUnassignedAttributes,
              text: e.$t("datahub-ui.dh-shared.newAttribute"),
              disabled: u,
              "show-skeleton": t(I),
              "custom-query": T.value,
              "item-title": "name",
              "item-value": "id",
              color: "primary",
              "page-size": "",
              search: "",
              onChange: O
            }, null, 8, ["data", "text", "disabled", "show-skeleton", "custom-query"])
          ]),
          _: 1
        }, 16, ["data", "is-loading", "readonly", "table-name", "can-reorder-rows"])
      ]),
      _: 1
    }));
  }
}), Ae = /* @__PURE__ */ ie(le, [["__scopeId", "data-v-eabc39dd"]]);
export {
  Ae as default
};
