import { defineComponent as b, mergeModels as k, useModel as $, ref as y, computed as M, watch as g, createBlock as V, openBlock as D, unref as F, mergeProps as w, createSlots as x, renderList as j, withCtx as N, resolveDynamicComponent as z } from "vue";
import { a5 as H, i as X } from "./start-BYfL32Oe.mjs";
import "vue-i18n";
import "pinia";
import "vue-router";
import "./header-Droxy2Kd.mjs";
import { h as K } from "./moment-h96o7c8I.mjs";
import P from "./SettingInput-BF07m4Qz.mjs";
import { _ as J } from "./SettingCheckbox.vue_vue_type_script_setup_true_lang-C9l0H1RS.mjs";
import { _ as U } from "./SettingCombobox.vue_vue_type_script_setup_true_lang-Co4EnMf5.mjs";
import { _ as q } from "./SettingDatePicker.vue_vue_type_script_setup_true_lang-LQXTyKlI.mjs";
var B = /* @__PURE__ */ ((e) => (e.INPUT = "input", e.CHECKBOX = "checkbox", e.DATE_PICKER = "actindo-date-picker", e.COMBOBOX = "actindo-combobox", e))(B || {});
const Q = {
  input: {
    component: P
    // renderComponent: "SettingInput",
    // renderImportPath:
    //   "/Actindo/Modules/Actindo/Setting/Resources/vue3/external-components/SettingInput.mjs",
  },
  checkbox: {
    component: J
    // renderComponent: "SettingCheckbox",
    // renderImportPath:
    //   "/Actindo/Modules/Actindo/Setting/Resources/vue3/external-components/SettingCheckbox.mjs",
  },
  "actindo-combobox": {
    component: U
    // renderComponent: "SettingCombobox",
    // renderImportPath:
    //   "/Actindo/Modules/Actindo/Setting/Resources/vue3/external-components/SettingCombobox.mjs",
  },
  "actindo-date-picker": {
    component: q
    // renderComponent: "SettingDatePicker",
    // renderImportPath:
    //   "/Actindo/Modules/Actindo/Setting/Resources/vue3/external-components/SettingDatePicker.mjs",
  }
};
function W(e, o, t, n) {
  return e <= t && t <= o || e <= n && n <= o ? !0 : t < e && o < n;
}
function G(e) {
  for (let o = 0; o < e.length - 1; o++)
    for (let t = o + 1; t < e.length; t++)
      if (t in e && W(
        e[o].valid_from,
        e[o].valid_to,
        e[t].valid_from,
        e[t].valid_to
      ))
        return `Dates overlap! Rows: ${e[o].index} and ${e[t].index}; Vat codes: ${e[o].nintendo_vat_code} and ${e[t].nintendo_vat_code}`;
  return "";
}
function S(e) {
  const o = [];
  let t = "";
  return e.forEach(
    ({
      tax_zone_match_criterion: n,
      valid_from: p,
      valid_to: s,
      nintendo_vat_code: l
    }, v) => {
      const m = n;
      o[m] || (o[m] = []), o[m].push({
        index: v + 1,
        valid_from: new Date(p).getTime(),
        valid_to: new Date(s).getTime(),
        nintendo_vat_code: l
      });
    }
  ), o.forEach((n) => {
    n.length && (t = t || G(n));
  }), t;
}
const E = {
  validateTaxZoneMatchCriterionRows: S
}, O = (e) => {
  const [o, t, ...n] = e.split(".");
  return [t, o, ...n].join("/");
}, A = (e) => /^\d{1,2}\/\d{1,2}\/\d{4}$/.test(e), I = ([e, o, t], n, p) => {
  let s = n[e], l = n[o];
  if (!s || !l)
    return;
  if (K.locale() == "de" && (s = O(s), l = O(l)), !A(s) || !A(l))
    return "date format is incorrect, the date must be seperated by '/' e.g. '1/1/2020'";
  const m = Date.parse(s) + t + Date.parse(l);
  return !Function("return " + m)() && `Row ${p + 1} for data ${JSON.stringify(n)} broke condition "${n[e]}" ${t} "${n[o]}"`;
}, L = /* @__PURE__ */ b({
  __name: "SettingMultiBuilder",
  props: /* @__PURE__ */ k({
    modelValue: {},
    data: {},
    options: {},
    settings: {},
    loading: { type: Boolean },
    readonly: { type: Boolean },
    isDefault: { type: Boolean }
  }, {
    modelValue: { default: () => [] },
    modelModifiers: {},
    valid: { type: Boolean, default: !0 },
    validModifiers: {}
  }),
  emits: ["update:modelValue", "update:valid"],
  setup(e) {
    const o = e, t = $(e, "modelValue"), n = $(e, "valid"), p = y({}), s = y(""), l = y([]), v = M(() => ({
      data: t.value || [],
      minRowCount: 1,
      hideGlobalSearch: !0,
      canReorderRows: !1,
      createActions: [{ icon: "add_circle" }],
      columns: l.value
    }));
    function m() {
      const i = {};
      Array.isArray(t.value) ? t.value.push(i) : t.value = [i];
    }
    function _({ rowIndex: i }) {
      if (!Array.isArray(t.value)) {
        t.value = [];
        return;
      }
      t.value = t.value.filter((a, u) => u !== i);
    }
    const C = ({ id: i }, a) => `${i}-${a}`;
    return g(
      () => {
        var i;
        return (i = o.options) == null ? void 0 : i.options;
      },
      (i) => {
        l.value = [], Array.isArray(i) && (l.value = i.map((a, u) => {
          a.type === B.COMBOBOX && a.loadItems && a.remote && a.displayField && a.valueField && H(a.remote).then(({ data: d }) => {
            l.value[u].properties.items = d.map((h) => ({
              [a.valueField]: h[a.valueField],
              [a.displayField]: h[a.displayField]
            }));
          });
          const r = Q[a.type], { properties: f, vueComponents: c } = "component" in r ? {
            properties: {
              ...a,
              component: r.component
            },
            vueComponents: void 0
          } : {
            properties: a,
            vueComponents: { ...r }
          };
          return {
            id: `id${u}`,
            header: "",
            properties: f,
            vueComponents: c
          };
        }));
      },
      { immediate: !0 }
    ), g(
      [p, s],
      ([i, a]) => {
        n.value = !a && Object.values(i).every(Boolean);
      },
      { deep: !0 }
    ), g(
      t,
      (i) => {
        var u;
        const a = [];
        try {
          if ((u = o.options) != null && u.validationRules || !Array.isArray(i))
            return;
          const { rowValidation: r, customValidation: f } = o.options.validationRules;
          i.forEach(
            (c, d) => r.forEach(
              (h) => a.push(I(h, c, d))
            )
          ), f.forEach((c) => {
            const d = E[c];
            if (!d)
              return console.error(
                `Custom validation function "${c}" does not exist in setting multi builder."`
              );
            a.push(d(i));
          });
        } finally {
          s.value = a.filter(Boolean).join(`
`);
        }
      },
      { deep: !0 }
    ), (i, a) => (D(), V(F(X), w(v.value, {
      onCreate: m,
      onRemove: _
    }), x({ _: 2 }, [
      j(l.value, (u) => ({
        name: `cell-${u.id}`,
        fn: N(({ cell: r, row: f, rowIndex: c }) => [
          (D(), V(z(r.properties.component ?? r.CellRenderer), {
            modelValue: f[r.properties.serializationName],
            "onUpdate:modelValue": (d) => f[r.properties.serializationName] = d,
            valid: p.value[C(r, c)],
            options: r.properties,
            readonly: !r.properties.serializationName,
            "onUpdate:valid": (d) => p.value[C(r, c)] = d
          }, null, 40, ["modelValue", "onUpdate:modelValue", "valid", "options", "readonly", "onUpdate:valid"]))
        ])
      }))
    ]), 1040));
  }
});
function R(e) {
  const o = e;
  o.__i18n = o.__i18n || [], o.__i18n.push({
    locale: "",
    resource: {
      "en-US": {
        "setting-plugin": {
          "setting-input": {
            regex: { t: 0, b: { t: 2, i: [{ t: 3, v: "Has to match " }, { t: 4, k: "pattern" }] } }
          }
        }
      },
      "de-DE": {
        "setting-plugin": {
          "setting-input": {
            regex: { t: 0, b: { t: 2, i: [{ t: 3, v: "Has to match " }, { t: 4, k: "pattern" }] } }
          }
        }
      }
    }
  });
}
typeof R == "function" && R(L);
export {
  L as default
};
