import { defineComponent as g, mergeModels as m, useModel as N, computed as k, watch as P, createBlock as U, openBlock as M, unref as o, mergeProps as T, withCtx as d, createVNode as p } from "vue";
import { useI18n as _ } from "vue-i18n";
import { i as B, b as s } from "./start-BYfL32Oe.mjs";
import "pinia";
import "vue-router";
import "./header-Droxy2Kd.mjs";
import "./moment-h96o7c8I.mjs";
import { a as C } from "./utils-DmzbWX5j.mjs";
import { b as c } from "./packing-unit-value.json_vue_type_i18n_index_0_src_true_lang-DIfyUy2H.mjs";
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__ */ m({
    modelValue: {},
    readOnly: { type: Boolean },
    attribute: {},
    massEditing: { type: Boolean },
    label: {},
    fieldName: {},
    dataTypeInstance: {},
    loading: { type: Boolean }
  }, {
    modelValue: {},
    modelModifiers: {}
  }),
  emits: /* @__PURE__ */ m(["validated", "update:model-value"], ["update:modelValue"]),
  setup(i, { emit: f }) {
    const u = i, v = f, e = N(i, "modelValue"), { t: y } = _(), 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(
      () => {
        var a;
        return ((a = e.value) == null ? void 0 : a.every(
          ({ ean: r, amount: l }) => !!(r && l >= n)
        )) ?? !0;
      },
      (a) => {
        v("validated", a);
      },
      { deep: !0 }
    ), (a, r) => (M(), U(o(B), T({ "table-name": a.label }, b.value, {
      onCreate: h,
      onRemove: V
    }), {
      "cell-ean": d(({ 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": d(({ 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
};
