import { defineComponent as B, mergeModels as R, useModel as c, computed as s, watch as C, createBlock as D, openBlock as U, unref as u, mergeProps as K, withCtx as y, createVNode as g } from "vue";
import { useI18n as S } from "vue-i18n";
import { j as w, d as f } from "./start-CE9SawgU.js";
import "pinia";
import "./header-Bn1EKnBE.js";
const L = /* @__PURE__ */ B({
  __name: "SettingMultiValue",
  props: /* @__PURE__ */ R({
    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(r) {
    const a = r, t = c(r, "modelValue"), i = c(r, "valid"), { t: v } = S(), b = s(
      () => typeof a.options?.hasKey != "boolean" || a.options.hasKey
    ), h = s(() => ({
      data: t.value || [],
      minRowCount: 1,
      hideGlobalSearch: !0,
      tableName: a.options?.helperText,
      createActions: !0,
      columns: [
        ...b.value ? [
          {
            id: "key",
            header: a.options?.keyLabel || "",
            sortable: !1,
            width: 200
          }
        ] : [],
        {
          id: "value",
          header: a.options?.valueLabel || "",
          sortable: !1
        }
      ]
    })), p = s(() => {
      if (!Array.isArray(t.value) && !a.options?.keyPattern && !a.options?.valuePattern)
        return [];
      const e = a.options.keyErrorMessage || v("setting-plugin.setting-multi-value.regex"), l = a.options.valueErrorMessage || v("setting-plugin.setting-multi-value.regex");
      return t.value.map(({ value: o, key: n }) => {
        const _ = d(
          n,
          a.options.keyPattern,
          e
        ), P = d(
          o,
          a.options.valuePattern,
          l
        );
        return {
          keyError: _,
          valueError: P
        };
      });
    });
    function d(e, l, o) {
      return l && !new RegExp(l).test(e) ? o : void 0;
    }
    function A({ rowIndex: e }) {
      if (!Array.isArray(t.value)) {
        t.value = [];
        return;
      }
      t.value = t.value.filter((l, o) => o !== e);
    }
    function M() {
      const e = { key: "", value: "" };
      Array.isArray(t.value) ? t.value.push(e) : t.value = [e];
    }
    function m(e, l) {
      Array.isArray(t.value) || (t.value = []), t.value[e] = {
        ...t.value[e],
        ...l
      };
    }
    C(
      t,
      (e) => {
        if (!Array.isArray(e)) {
          i.value = !0, t.value = [];
          return;
        }
        i.value = e.every(({ key: l, value: o }) => l && o);
      },
      { immediate: !0 }
    );
    const V = t.value?.map(({ key: e }) => e) || [];
    function E(e) {
      return !!(a.options?.keyDisabledIfSet && e && V.includes(e));
    }
    return (e, l) => (U(), D(u(w), K(h.value, {
      onCreate: M,
      onRemove: A
    }), {
      "cell-key": y(({ rowIndex: o }) => [
        g(u(f), {
          "model-value": t.value?.[o]?.key,
          "error-messages": p.value[o]?.keyError,
          pattern: e.options?.keyPattern,
          disabled: E(t.value?.[o]?.key),
          "onUpdate:modelValue": (n) => m(o, { key: n })
        }, null, 8, ["model-value", "error-messages", "pattern", "disabled", "onUpdate:modelValue"])
      ]),
      "cell-value": y(({ rowIndex: o }) => [
        g(u(f), {
          "model-value": t.value?.[o]?.value,
          "error-messages": p.value[o]?.valueError,
          pattern: e.options?.valuePattern,
          "onUpdate:modelValue": (n) => m(o, { value: n })
        }, null, 8, ["model-value", "error-messages", "pattern", "onUpdate:modelValue"])
      ]),
      _: 1
    }, 16));
  }
});
function k(r) {
  const a = r;
  a.__i18n = a.__i18n || [], a.__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: "Muss mit " }, { t: 4, k: "pattern" }, { t: 3, v: " übereinstimmen" }] } }
          }
        }
      }
    }
  });
}
typeof k == "function" && k(L);
export {
  L as default
};
