import { defineComponent as U, mergeModels as _, useModel as h, computed as y, watch as A, createBlock as N, openBlock as k, unref as o, withCtx as O, createElementVNode as w, createVNode as p } from "vue";
import { useI18n as C } from "vue-i18n";
import { storeToRefs as R } from "pinia";
import { u as S, h as V, b as $, l as F } from "./start-BYfL32Oe.mjs";
import "vue-router";
import "./header-Droxy2Kd.mjs";
import "./moment-h96o7c8I.mjs";
import { V as L } from "./constants-CwfsvyFM.mjs";
import "./IsActiveStatusCell-DlvB6_E-.mjs";
import "@vuelidate/validators";
import "./MultiLangScopeEditorsList.vue_vue_type_script_setup_true_lang-CWQeDnSm.mjs";
import "./DatahubDataTypeCompletenessRenderer.vue_vue_type_script_setup_true_lang-Btvu_WeF.mjs";
import "./topBarRoutes-0VuQ_i6D.mjs";
import "./VariantToVariantExtension-WcLvPNqG.mjs";
import { _ as q } from "./DatahubDataComplexValue.vue_vue_type_script_setup_true_lang-CDTiMGxi.mjs";
import "./DatahubDataTypeVariantValueEditor-f1gR3QCx.mjs";
import { u as Z } from "./pimDataType-HqY1K_h2.mjs";
const j = { class: "base-price" }, B = /* @__PURE__ */ U({
  __name: "PIMDataTypeBasePriceValueEditor",
  props: /* @__PURE__ */ _({
    modelValue: {},
    readOnly: { type: Boolean },
    attribute: {},
    massEditing: { type: Boolean },
    label: {},
    fieldName: {},
    dataTypeInstance: {},
    loading: { type: Boolean }
  }, {
    modelValue: {},
    modelModifiers: {}
  }),
  emits: /* @__PURE__ */ _(["validated", "update:model-value"], ["update:modelValue"]),
  setup(d) {
    const i = h(d, "modelValue"), { t: l } = C(), { root: P, dispatchEvent: M } = S(L), v = Z(), { isDimensionsLoading: b, dimensions: m } = R(v);
    v.ensureDimensions();
    const T = y(
      () => {
        var e, t;
        return (e = i.value) != null && e.dimensionId ? ((t = m.value.find(({ id: n }) => n === i.value.dimensionId)) == null ? void 0 : t.units) ?? [] : [];
      }
    ), r = y(() => {
      var e, t, n, a;
      return {
        unitId: (e = i.value) != null && e.dimensionId && !((t = i.value) != null && t.unitId) ? l("pim-plugin.base-price.unitIdError") : void 0,
        amount: (n = i.value) != null && n.dimensionId && Number((a = i.value) == null ? void 0 : a.amount) <= 0 ? l("pim-plugin.base-price.amountError") : void 0
      };
    });
    function u(e) {
      var t, n;
      e.dimensionId && (e.unitId = (n = (t = m.value.find(
        ({ id: a }) => a === e.dimensionId
      )) == null ? void 0 : t.baseUnit) == null ? void 0 : n.id), i.value = { ...i.value, ...e };
    }
    return A(
      () => !r.value.unitId && !r.value.amount,
      (e) => M({ data: e })
    ), (e, t) => (k(), N(o(q), {
      ref_key: "root",
      ref: P,
      header: e.massEditing ? void 0 : e.label
    }, {
      default: O(() => {
        var n, a, c, f, I, g, E;
        return [
          w("div", j, [
            p(o(V), {
              "model-value": (n = i.value) == null ? void 0 : n.dimensionId,
              label: o(l)("pim-plugin.base-price.dimension"),
              disabled: e.readOnly,
              items: o(m),
              loading: o(b),
              "item-title": "name",
              "item-value": "id",
              search: "",
              "onUpdate:modelValue": t[0] || (t[0] = (s) => u({ dimensionId: s }))
            }, null, 8, ["model-value", "label", "disabled", "items", "loading"]),
            p(o($), {
              "model-value": (a = i.value) == null ? void 0 : a.amount,
              label: o(l)("pim-plugin.base-price.relevantAmount"),
              disabled: e.readOnly || !((c = i.value) != null && c.dimensionId),
              "error-messages": (f = r.value) == null ? void 0 : f.amount,
              type: "number",
              "onUpdate:modelValue": t[1] || (t[1] = (s) => u({ amount: s }))
            }, null, 8, ["model-value", "label", "disabled", "error-messages"]),
            p(o(V), {
              "model-value": (I = i.value) == null ? void 0 : I.unitId,
              label: o(l)("pim-plugin.base-price.unit"),
              disabled: e.readOnly || !((g = i.value) != null && g.dimensionId),
              items: T.value,
              loading: o(b),
              "error-messages": (E = r.value) == null ? void 0 : E.unitId,
              "item-title": "name",
              "item-value": "id",
              search: "",
              "onUpdate:modelValue": t[2] || (t[2] = (s) => u({ unitId: s }))
            }, null, 8, ["model-value", "label", "disabled", "items", "loading", "error-messages"])
          ])
        ];
      }),
      _: 1
    }, 8, ["header"]));
  }
});
function D(d) {
  const i = d;
  i.__i18n = i.__i18n || [], i.__i18n.push({
    locale: "",
    resource: {
      "en-US": {
        "pim-plugin": {
          "base-price": {
            amountError: { t: 0, b: { t: 2, i: [{ t: 3 }], s: "Positive number expected" } },
            unitIdError: { t: 0, b: { t: 2, i: [{ t: 3 }], s: "Field is required" } },
            dimension: { t: 0, b: { t: 2, i: [{ t: 3 }], s: "Dimension" } },
            relevantAmount: { t: 0, b: { t: 2, i: [{ t: 3 }], s: "Relevant amount" } },
            unit: { t: 0, b: { t: 2, i: [{ t: 3 }], s: "Unit" } }
          }
        }
      },
      "de-DE": {
        "pim-plugin": {
          "base-price": {
            amountError: { t: 0, b: { t: 2, i: [{ t: 3 }], s: "Positive Zahl erwartet" } },
            unitIdError: { t: 0, b: { t: 2, i: [{ t: 3 }], s: "Das Feld ist erforderlich" } },
            dimension: { t: 0, b: { t: 2, i: [{ t: 3 }], s: "Dimension" } },
            relevantAmount: { t: 0, b: { t: 2, i: [{ t: 3 }], s: "Relevante Menge" } },
            unit: { t: 0, b: { t: 2, i: [{ t: 3 }], s: "Einheit" } }
          }
        }
      }
    }
  });
}
typeof D == "function" && D(B);
const se = /* @__PURE__ */ F(B, [["__scopeId", "data-v-2cbb9517"]]);
export {
  se as default
};
