import { defineComponent as C, mergeModels as D, useModel as k, computed as b, watch as U, createBlock as S, openBlock as L, unref as v, mergeProps as w, withCtx as h, createVNode as A } from "vue";
import { useI18n as H } from "vue-i18n";
import { i as N, b as V } from "./start-BYfL32Oe.mjs";
import "pinia";
import "vue-router";
import "./header-Droxy2Kd.mjs";
import "./moment-h96o7c8I.mjs";
const x = /* @__PURE__ */ C({
  __name: "SettingMultiValue",
  props: /* @__PURE__ */ D({
    modelValue: {},
    data: {},
    options: {},
    settings: {},
    loading: { type: Boolean },
    readonly: { type: Boolean },
    isDefault: { type: Boolean }
  }, {
    modelValue: {},
    modelModifiers: {},
    valid: { type: Boolean, default: !0 },
    validModifiers: {}
  }),
  emits: ["update:modelValue", "update:valid"],
  setup(p) {
    const l = p, a = k(p, "modelValue"), d = k(p, "valid"), { t: m } = H(), E = b(() => {
      var e, o, t, r;
      return {
        data: a.value || [],
        minRowCount: 1,
        hideGlobalSearch: !0,
        tableName: (e = l.options) == null ? void 0 : e.helperText,
        createActions: [{ icon: "add_circle" }],
        columns: [
          ...(o = l.options) != null && o.hasKey ? [
            {
              id: "key",
              header: ((t = l.options) == null ? void 0 : t.keyLabel) || "",
              sortable: !1
            }
          ] : [],
          {
            id: "value",
            header: ((r = l.options) == null ? void 0 : r.valueLabel) || "",
            sortable: !1
          }
        ]
      };
    }), c = (e, o, t) => o && !new RegExp(o).test(e) ? t : void 0, g = b(() => {
      var t, r;
      if (!Array.isArray(a.value) && !((t = l.options) != null && t.keyPattern) && !((r = l.options) != null && r.valuePattern))
        return [];
      const e = l.options.keyErrorMessage || m("setting-plugin.setting-multi-value.regex"), o = l.options.valueErrorMessage || m("setting-plugin.setting-multi-value.regex");
      return a.value.map(({ value: s, key: n }) => {
        const u = c(
          n,
          l.options.keyPattern,
          e
        ), i = c(
          s,
          l.options.valuePattern,
          o
        );
        return {
          keyError: u,
          valueError: i
        };
      });
    });
    function M({ rowIndex: e }) {
      if (!Array.isArray(a.value)) {
        a.value = [];
        return;
      }
      a.value = a.value.filter((o, t) => t !== e);
    }
    function P() {
      const e = { key: "", value: "" };
      Array.isArray(a.value) ? a.value.push(e) : a.value = [e];
    }
    function y(e, o) {
      Array.isArray(a.value) || (a.value = []), a.value[e] = {
        ...a.value[e],
        ...o
      };
    }
    const B = (e) => {
      var o;
      return ((o = l.options) == null ? void 0 : o.keyDisabledIfSet) && e;
    };
    return U(a, (e) => {
      if (!Array.isArray(e)) {
        d.value = !0;
        return;
      }
      d.value = e.every(({ key: o, value: t }) => o && t);
    }), (e, o) => (L(), S(v(N), w(E.value, {
      onCreate: P,
      onRemove: M
    }), {
      "cell-key": h(({ rowIndex: t }) => {
        var r, s, n, u, i, f;
        return [
          A(v(V), {
            "model-value": (s = (r = a.value) == null ? void 0 : r[t]) == null ? void 0 : s.key,
            "error-messages": (n = g.value[t]) == null ? void 0 : n.keyError,
            pattern: (u = e.options) == null ? void 0 : u.keyPattern,
            disabled: B((f = (i = a.value) == null ? void 0 : i[t]) == null ? void 0 : f.key),
            "onUpdate:modelValue": (R) => y(t, { key: R })
          }, null, 8, ["model-value", "error-messages", "pattern", "disabled", "onUpdate:modelValue"])
        ];
      }),
      "cell-value": h(({ rowIndex: t }) => {
        var r, s, n, u;
        return [
          A(v(V), {
            "model-value": (s = (r = a.value) == null ? void 0 : r[t]) == null ? void 0 : s.value,
            "error-messages": (n = g.value[t]) == null ? void 0 : n.valueError,
            pattern: (u = e.options) == null ? void 0 : u.valuePattern,
            "onUpdate:modelValue": (i) => y(t, { value: i })
          }, null, 8, ["model-value", "error-messages", "pattern", "onUpdate:modelValue"])
        ];
      }),
      _: 1
    }, 16));
  }
});
function _(p) {
  const l = p;
  l.__i18n = l.__i18n || [], l.__i18n.push({
    locale: "",
    resource: {
      "en-US": {
        "setting-plugin": {
          "setting-multi-value": {
            regex: { t: 0, b: { t: 2, i: [{ t: 3, v: "Has to match " }, { t: 4, k: "pattern" }] } }
          }
        }
      },
      "de-DE": {
        "setting-plugin": {
          "setting-multi-value": {
            regex: { t: 0, b: { t: 2, i: [{ t: 3, v: "Has to match " }, { t: 4, k: "pattern" }] } }
          }
        }
      }
    }
  });
}
typeof _ == "function" && _(x);
export {
  x as default
};
