import { defineComponent as g, mergeModels as d, useModel as N, computed as k, watch as P, createBlock as U, openBlock as B, unref as o, mergeProps as M, withCtx as m, createVNode as p } from "vue";
import { useI18n as T } from "vue-i18n";
import { j as _, d as s } from "./start-CE9SawgU.js";
import "pinia";
import "./header-Bn1EKnBE.js";
import { a as C } from "./utils-D5jQofdq.js";
import { b as c } from "./packing-unit-value.json_vue_type_i18n_index_0_src_true_lang-DIfyUy2H.js";
const n = 1, D = {
  hideGlobalSearch: !0,
  hidePagination: !0,
  canReorderHeaders: !1,
  hideRemove: !1,
  hideNoData: !1,
  hideNoDataDescription: !0,
  hideNoDataComment: !0,
  minRowCount: 0,
  columns: [
    {
      id: "ean",
      header: "pim-plugin.packing-unit.ean",
      minWidth: 200
    },
    {
      id: "amount",
      header: "pim-plugin.packing-unit.amount",
      minWidth: 200
    }
  ]
}, O = /* @__PURE__ */ g({
  __name: "PIMDataTypePackagingUnitValueEditor",
  props: /* @__PURE__ */ d({
    modelValue: {},
    readOnly: { type: Boolean },
    attribute: {},
    massEditing: { type: Boolean },
    label: {},
    fieldName: {},
    dataTypeInstance: {},
    loading: { type: Boolean },
    succeeded: { type: Boolean }
  }, {
    modelValue: {},
    modelModifiers: {}
  }),
  emits: /* @__PURE__ */ d(["validated", "update:model-value", "initialized"], ["update:modelValue"]),
  setup(i, { emit: f }) {
    const u = i, v = f, e = N(i, "modelValue"), { t: y } = T(), b = k(
      () => C({
        tableOptions: D,
        data: e.value,
        readonly: u.readOnly,
        tableName: u.label,
        createTitle: "pim-plugin.packing-unit.newPackingUnit",
        t: y
      })
    );
    function h() {
      e.value || (e.value = []), e.value.push({ ean: null, amount: null });
    }
    function V({ rowIndex: a }) {
      e.value.splice(a, 1);
    }
    return P(
      () => e.value?.every(
        ({ ean: a, amount: r }) => !!(a && r >= n)
      ) ?? !0,
      (a) => {
        v("validated", a);
      },
      { deep: !0 }
    ), (a, r) => (B(), U(o(_), M({ "table-name": a.label }, b.value, {
      onCreate: h,
      onRemove: V
    }), {
      "cell-ean": m(({ rowIndex: l }) => [
        p(o(s), {
          modelValue: e.value[l].ean,
          "onUpdate:modelValue": (t) => e.value[l].ean = t,
          readonly: a.readOnly,
          error: !e.value[l].ean
        }, null, 8, ["modelValue", "onUpdate:modelValue", "readonly", "error"])
      ]),
      "cell-amount": m(({ rowIndex: l }) => [
        p(o(s), {
          modelValue: e.value[l].amount,
          "onUpdate:modelValue": (t) => e.value[l].amount = t,
          modelModifiers: { number: !0 },
          readonly: a.readOnly,
          min: o(n),
          error: e.value[l].amount < o(n),
          type: "number"
        }, null, 8, ["modelValue", "onUpdate:modelValue", "readonly", "min", "error"])
      ]),
      _: 1
    }, 16, ["table-name"]));
  }
});
typeof c == "function" && c(O);
export {
  O as default
};
