import { defineComponent as q, mergeModels as Z, useModel as ne, computed as k, createBlock as Q, openBlock as _, unref as e, withCtx as t, createVNode as a, createElementBlock as U, createTextVNode as se, toDisplayString as F, Fragment as j, createCommentVNode as re, createElementVNode as S, renderList as J, mergeProps as N, ref as R, watch as _e, withModifiers as Ae, createSlots as Ee } from "vue";
import { useI18n as ie } from "vue-i18n";
import { storeToRefs as Te } from "pinia";
import { c as de } from "./index-fFOslvm5.mjs";
import { a as C, g as K, b as $, a8 as ke, l as fe, aK as ue, I as Ce, ad as Ue, f as ve, h as $e, i as oe, E as te, aL as he, aM as xe, aN as Me, Z as Se, j as Fe } from "./start-BYfL32Oe.mjs";
import "vue-router";
import "./header-Droxy2Kd.mjs";
import "./moment-h96o7c8I.mjs";
import { u as De } from "./pimDataType-HqY1K_h2.mjs";
import { p as Be, g as Le, c as Re, a as ce, b as Oe, d as Ne, s as pe } from "./utils-DmzbWX5j.mjs";
import { E as X, M as ee, S as Qe, a as Ie, b as He } from "./constants-3JiawOc1.mjs";
import { b as I } from "./price-field-value.json_vue_type_i18n_index_0_src_true_lang-BMR9WVZU.mjs";
const Ve = /* @__PURE__ */ q({
  __name: "PriceInput",
  props: /* @__PURE__ */ Z({
    label: { default: void 0 },
    precision: { default: 2 },
    priceSize: { default: 8 },
    readonly: { type: Boolean }
  }, {
    modelValue: {},
    modelModifiers: {}
  }),
  emits: ["update:modelValue"],
  setup(T) {
    const A = T, i = ne(T, "modelValue"), { t: V } = ie(), b = k(() => {
      if (!A.readonly)
        return X;
      const s = Be(i.value.price, A.precision);
      return s === X ? X : `${s} ${i.value.isGross ? V("pim-plugin.price-field.gross") : V("pim-plugin.price-field.net")}`;
    });
    return (s, n) => (_(), Q(e(C), null, {
      default: t(() => [
        a(e(K), { dense: "" }, {
          default: t(() => [
            s.readonly ? (_(), Q(e(C), { key: 0 }, {
              default: t(() => [
                se(F(b.value), 1)
              ]),
              _: 1
            })) : (_(), U(j, { key: 1 }, [
              a(e(C), { cols: s.priceSize }, {
                default: t(() => [
                  a(e($), {
                    modelValue: i.value.price,
                    "onUpdate:modelValue": n[0] || (n[0] = (y) => i.value.price = y),
                    modelModifiers: { number: !0 },
                    label: s.label,
                    min: 0,
                    error: i.value.price < 0,
                    readonly: s.readonly,
                    type: "number"
                  }, null, 8, ["modelValue", "label", "error", "readonly"])
                ]),
                _: 1
              }, 8, ["cols"]),
              a(e(C), {
                cols: 12 - Number(s.priceSize)
              }, {
                default: t(() => [
                  a(e(ke), {
                    modelValue: i.value.isGross,
                    "onUpdate:modelValue": n[1] || (n[1] = (y) => i.value.isGross = y),
                    label: e(V)("pim-plugin.price-field.gross"),
                    readonly: s.readonly,
                    density: "compact",
                    "hide-details": "auto",
                    class: "gross-switch"
                  }, {
                    prepend: t(() => [
                      se(F(e(V)("pim-plugin.price-field.net")), 1)
                    ]),
                    _: 1
                  }, 8, ["modelValue", "label", "readonly"])
                ]),
                _: 1
              }, 8, ["cols"])
            ], 64))
          ]),
          _: 1
        })
      ]),
      _: 1
    }));
  }
});
typeof I == "function" && I(Ve);
const O = /* @__PURE__ */ fe(Ve, [["__scopeId", "data-v-7729edb6"]]), ze = { key: 0 }, Ge = ["viewBox"], We = { style: { "text-anchor": "end", "dominant-baseline": "text-before-edge", fill: "currentcolor" } }, Ye = { style: { "text-anchor": "end", "dominant-baseline": "mathematical", fill: "currentcolor" } }, je = ["d"], Ze = ["d"], Ke = ["points"], me = 6, qe = 7, Y = 7, ye = 16, G = 6, le = 300, ae = 100, we = /* @__PURE__ */ q({
  __name: "PriceChart",
  props: {
    price: {},
    currency: {},
    date: { default: ue }
  },
  setup(T) {
    const A = T, i = k(() => {
      var g;
      const b = Le(
        A.price,
        Re(`${A.date} 00:00:00`)
      ).map(({ price: { price: o }, startQuantity: u }) => ({
        price: o,
        startQuantity: u
      })).sort((o, u) => o.startQuantity - u.startQuantity), s = b.map(({ price: o }) => Math.ceil(o)), n = [
        ...b.map(({ startQuantity: o }) => o),
        ((g = b.at(-1)) == null ? void 0 : g.startQuantity) * 2
      ], y = Math.max(...s), E = y.toFixed(0).length * Y, P = (le - E - me - qe) / (n.length - 1), c = ae - Y, B = E + me, h = (ae - ye) / G, x = n.map((o, u) => ({
        label: o,
        labelProps: {
          x: B + u * P,
          y: c,
          "font-size": Y
        }
      })), L = Array.from({ length: G + 1 }, (o, u) => ({
        label: Math.round(y / G * (G - u)),
        labelProps: {
          x: E,
          y: u * h,
          "font-size": Y
        }
      })), M = B - 2, D = c - 4, r = ye / 3, f = le, l = D - r, m = `M${M} 0 V${D} H${f}`, W = `M${M} ${r} ${Array.from(
        { length: G },
        (o, u) => `H${f} M${M} ${r + (u + 1) * h}`
      )}`, H = (o, u) => ({
        x: o * P + M,
        y: D - u * l / y
      }), p = (o, u) => {
        const { x: z, y: w } = H(o, u);
        return `${z} ${w}`;
      }, v = b.flatMap(({ price: o }, u) => [
        p(u, o),
        p(u + 1, o)
      ]).join(" "), d = b.slice(1).map(({ price: o, startQuantity: u }, z) => {
        const { x: w, y: ge } = H(z + 1, o);
        return {
          label: `${u} => ${o} ${A.currency}`,
          tooltipProps: {
            cx: w,
            cy: ge,
            r: 3
          }
        };
      });
      return {
        viewBox: `0 0 ${le} ${ae}`,
        xAxes: x,
        yAxes: L,
        points: v,
        mainAxes: m,
        yAxesGrid: W,
        modelValue: b,
        tooltipPoints: d
      };
    });
    return (V, b) => i.value.xAxes.length ? (_(), U("div", ze, [
      (_(), U("svg", {
        viewBox: i.value.viewBox,
        xmlns: "http://www.w3.org/2000/svg",
        display: "block"
      }, [
        S("g", We, [
          (_(!0), U(j, null, J(i.value.yAxes, ({ label: s, labelProps: n }, y) => (_(), U("text", N({
            key: y,
            ref_for: !0
          }, n), F(s), 17))), 128))
        ]),
        S("g", Ye, [
          (_(!0), U(j, null, J(i.value.xAxes, ({ label: s, labelProps: n }, y) => (_(), U("text", N({
            key: y,
            ref_for: !0
          }, n), F(s), 17))), 128))
        ]),
        S("path", {
          d: i.value.yAxesGrid,
          fill: "none",
          stroke: "#EDEDED"
        }, null, 8, je),
        S("path", {
          d: i.value.mainAxes,
          fill: "none",
          stroke: "black"
        }, null, 8, Ze),
        S("polyline", {
          points: i.value.points,
          fill: "none",
          stroke: "#00EFBF"
        }, null, 8, Ke),
        (_(!0), U(j, null, J(i.value.tooltipPoints, ({ tooltipProps: s, label: n }, y) => (_(), U("circle", N({
          key: y,
          stroke: "#00EFBF",
          fill: "#00EFBF",
          ref_for: !0
        }, s), [
          S("title", null, F(n), 1)
        ], 16))), 128))
      ], 8, Ge))
    ])) : re("", !0);
  }
}), be = /* @__PURE__ */ q({
  __name: "EditPriceModal",
  props: /* @__PURE__ */ Z({
    readonly: { type: Boolean },
    isEdit: { type: Boolean },
    price: {},
    currencies: {}
  }, {
    modelValue: { type: Boolean },
    modelModifiers: {}
  }),
  emits: /* @__PURE__ */ Z(["save"], ["update:modelValue"]),
  setup(T, { emit: A }) {
    const i = T, V = A, b = ne(T, "modelValue"), { t: s } = ie(), n = R({}), y = k(
      () => s(
        i.isEdit ? "pim-plugin.price-field.editCurrency" : "pim-plugin.price-field.newCurrency"
      )
    ), E = k(() => n.value.currency && n.value.basePrice.price > 0 && !(n.value.msrp.price < 0) && n.value.bulkAndPromotionPrices.every(
      ({ price: r, startQuantity: f, validFrom: l, validTo: m }) => r.price > 0 && f >= ee && (!l && !m || l && m && l < m)
    )), P = k(
      () => n.value.bulkAndPromotionPrices.filter(({ validFrom: r }) => !r) ?? []
    ), c = k(
      () => n.value.bulkAndPromotionPrices.filter(({ validFrom: r }) => r) ?? []
    ), B = k(
      () => ce({
        tableOptions: Qe,
        data: P.value,
        readonly: i.readonly,
        createTitle: "pim-plugin.price-field.newScalePrice",
        t: s
      })
    ), h = k(
      () => ce({
        tableOptions: Ie,
        data: c.value,
        readonly: i.readonly,
        createTitle: "pim-plugin.price-field.newPromotion",
        t: s
      })
    );
    function x() {
      n.value.bulkAndPromotionPrices.push({
        description: void 0,
        startQuantity: null,
        price: {
          isGross: null,
          price: 0
        }
      });
    }
    function L({ row: r }) {
      n.value.bulkAndPromotionPrices = n.value.bulkAndPromotionPrices.filter(
        (f) => f !== r
      );
    }
    function M() {
      n.value.bulkAndPromotionPrices.push({
        description: void 0,
        startQuantity: null,
        validFrom: ue(),
        validTo: null,
        price: {
          isGross: null,
          price: 0
        }
      });
    }
    function D() {
      V("save", Ne(n.value));
    }
    return _e(
      () => i.price,
      (r) => {
        n.value = Oe(r);
      },
      { immediate: !0 }
    ), (r, f) => (_(), Q(e(Ce), {
      modelValue: b.value,
      "onUpdate:modelValue": f[4] || (f[4] = (l) => b.value = l),
      title: y.value,
      "max-widht": "1500px",
      scrollable: ""
    }, {
      actions: t(() => [
        r.readonly ? re("", !0) : (_(), Q(e(te), {
          key: 0,
          variant: "elevated",
          disabled: !E.value,
          text: r.$t("common.applyChanges"),
          onClick: D
        }, null, 8, ["disabled", "text"]))
      ]),
      default: t(() => [
        a(e(Ue), {
          onSubmit: f[3] || (f[3] = Ae(() => {
          }, ["prevent"]))
        }, {
          default: t(() => [
            a(e(ve), {
              class: "px-0",
              fluid: ""
            }, {
              default: t(() => [
                a(e(K), null, {
                  default: t(() => [
                    a(e(C), { md: "2" }, {
                      default: t(() => [
                        a(e($e), {
                          modelValue: n.value.currency,
                          "onUpdate:modelValue": f[0] || (f[0] = (l) => n.value.currency = l),
                          readonly: r.readonly || r.isEdit || r.currencies.length === 1,
                          items: r.currencies,
                          "item-value": "currency",
                          "item-title": "currency",
                          label: e(s)("pim-plugin.price-field.currency")
                        }, null, 8, ["modelValue", "readonly", "items", "label"])
                      ]),
                      _: 1
                    }),
                    a(O, {
                      modelValue: n.value.basePrice,
                      "onUpdate:modelValue": f[1] || (f[1] = (l) => n.value.basePrice = l),
                      label: e(s)("pim-plugin.price-field.basePrice"),
                      readonly: r.readonly,
                      md: "5"
                    }, null, 8, ["modelValue", "label", "readonly"]),
                    a(O, {
                      modelValue: n.value.msrp,
                      "onUpdate:modelValue": f[2] || (f[2] = (l) => n.value.msrp = l),
                      label: e(s)("pim-plugin.price-field.msrp"),
                      readonly: r.readonly,
                      md: "5"
                    }, null, 8, ["modelValue", "label", "readonly"]),
                    a(e(oe), N(B.value, {
                      onCreate: x,
                      onRemove: L
                    }), {
                      "cell-price": t(({ rowIndex: l }) => [
                        a(O, {
                          modelValue: P.value[l].price,
                          "onUpdate:modelValue": (m) => P.value[l].price = m,
                          readonly: r.readonly,
                          "price-size": "6"
                        }, null, 8, ["modelValue", "onUpdate:modelValue", "readonly"])
                      ]),
                      "cell-description": t(({ rowIndex: l }) => [
                        a(e($), {
                          modelValue: P.value[l].description,
                          "onUpdate:modelValue": (m) => P.value[l].description = m,
                          readonly: r.readonly
                        }, null, 8, ["modelValue", "onUpdate:modelValue", "readonly"])
                      ]),
                      "cell-fromQuantity": t(({ rowIndex: l }) => [
                        a(e($), {
                          modelValue: P.value[l].startQuantity,
                          "onUpdate:modelValue": (m) => P.value[l].startQuantity = m,
                          modelModifiers: { number: !0 },
                          readonly: r.readonly,
                          error: P.value[l].startQuantity < e(ee),
                          type: "number"
                        }, null, 8, ["modelValue", "onUpdate:modelValue", "readonly", "error"])
                      ]),
                      _: 1
                    }, 16),
                    a(e(oe), N(h.value, {
                      onCreate: M,
                      onRemove: L
                    }), {
                      "cell-price": t(({ rowIndex: l }) => [
                        a(O, {
                          modelValue: c.value[l].price,
                          "onUpdate:modelValue": (m) => c.value[l].price = m,
                          readonly: r.readonly,
                          "price-size": "6"
                        }, null, 8, ["modelValue", "onUpdate:modelValue", "readonly"])
                      ]),
                      "cell-description": t(({ rowIndex: l }) => [
                        a(e($), {
                          modelValue: c.value[l].description,
                          "onUpdate:modelValue": (m) => c.value[l].description = m,
                          readonly: r.readonly
                        }, null, 8, ["modelValue", "onUpdate:modelValue", "readonly"])
                      ]),
                      "cell-fromQuantity": t(({ rowIndex: l }) => [
                        a(e($), {
                          modelValue: c.value[l].startQuantity,
                          "onUpdate:modelValue": (m) => c.value[l].startQuantity = m,
                          modelModifiers: { number: !0 },
                          readonly: r.readonly,
                          error: c.value[l].startQuantity < e(ee),
                          type: "number"
                        }, null, 8, ["modelValue", "onUpdate:modelValue", "readonly", "error"])
                      ]),
                      "cell-from": t(({ rowIndex: l }) => [
                        a(e($), {
                          modelValue: c.value[l].validFrom,
                          "onUpdate:modelValue": (m) => c.value[l].validFrom = m,
                          readonly: r.readonly,
                          error: !c.value[l].validFrom || c.value[l].validFrom > c.value[l].validTo,
                          type: "date"
                        }, null, 8, ["modelValue", "onUpdate:modelValue", "readonly", "error"])
                      ]),
                      "cell-to": t(({ rowIndex: l }) => [
                        a(e($), {
                          modelValue: c.value[l].validTo,
                          "onUpdate:modelValue": (m) => c.value[l].validTo = m,
                          readonly: r.readonly,
                          error: !c.value[l].validTo,
                          type: "date"
                        }, null, 8, ["modelValue", "onUpdate:modelValue", "readonly", "error"])
                      ]),
                      _: 1
                    }, 16)
                  ]),
                  _: 1
                })
              ]),
              _: 1
            })
          ]),
          _: 1
        })
      ]),
      _: 1
    }, 8, ["modelValue", "title"]));
  }
});
typeof I == "function" && I(be);
const Je = { class: "ml-4" }, Pe = /* @__PURE__ */ q({
  __name: "PIMDataTypePriceFieldValueEditor",
  props: /* @__PURE__ */ Z({
    modelValue: {},
    readOnly: { type: Boolean },
    attribute: {},
    massEditing: { type: Boolean },
    label: {},
    fieldName: {},
    dataTypeInstance: {},
    loading: { type: Boolean }
  }, {
    modelValue: {},
    modelModifiers: {}
  }),
  emits: ["update:modelValue"],
  setup(T) {
    var W, H;
    const A = T, i = ne(T, "modelValue"), { t: V } = ie(), b = De(), { isTaxClassesLoading: s, taxClasses: n } = Te(b);
    b.ensureTaxClasses();
    const y = R(!1), E = R(!1), P = R(), c = R(-1), B = ue(), h = R(
      Array(((H = (W = i.value) == null ? void 0 : W.currencies) == null ? void 0 : H.length) || 0).fill(B)
    ), x = k(() => {
      var d, g, o;
      const p = ((g = (d = A.attribute) == null ? void 0 : d.configuration) == null ? void 0 : g.currencies) ?? [], v = ((o = i.value) == null ? void 0 : o.currencies) ?? [];
      return p.filter(
        (u) => v.every(({ currency: z }) => z !== u.currency)
      );
    }), L = k(() => {
      var p, v, d;
      return {
        ...He,
        data: ((p = i.value) == null ? void 0 : p.currencies) ?? [],
        tableName: `${(v = A.attribute) == null ? void 0 : v.name}: ${((d = n.value.find(({ id: g }) => {
          var o;
          return g === ((o = i.value) == null ? void 0 : o.taxClassId);
        })) == null ? void 0 : d.name) ?? ""}`,
        readonly: A.readOnly
      };
    });
    function M(p) {
      i.value = { ...i.value, ...p };
    }
    function D() {
      const v = {
        currency: x.value.length === 1 ? x.value[0].currency : void 0,
        basePrice: {},
        msrp: {},
        bulkAndPromotionPrices: []
      };
      r(v);
    }
    function r(p, v = -1) {
      P.value = de(p), c.value = v, E.value = !0, y.value = !0;
    }
    function f({ rowIndex: p }) {
      i.value.currencies.splice(p, 1);
    }
    function l(p) {
      var d;
      const v = ((d = i.value) == null ? void 0 : d.currencies) ?? [];
      c.value < 0 ? v.push(p) : v[c.value] = p, i.value = {
        ...i.value,
        currencies: v
      }, E.value = !1;
    }
    function m(p) {
      E.value = !0, P.value = de(p), y.value = !1;
    }
    return (p, v) => (_(), Q(e(he), {
      variant: "accordion",
      color: "transparent",
      flat: ""
    }, {
      default: t(() => [
        a(e(oe), N(L.value, { onRemove: f }), Ee({
          cellActions: t(({ row: d, rowIndex: g }) => [
            a(e(te), {
              icon: "edit",
              variant: "text",
              class: "mt-2",
              onClick: (o) => r(d, g)
            }, null, 8, ["onClick"])
          ]),
          "cell-item": t(({ row: d, rowIndex: g }) => [
            a(e(xe), {
              elevation: "0",
              ripple: !1,
              "bg-color": "background",
              class: "my-2 bugfix-expansion"
            }, {
              title: t(() => {
                var o, u;
                return [
                  S("b", null, F(d.currency), 1),
                  S("span", Je, F(e(V)("pim-plugin.price-field.currentPrice")) + ": " + F(e(pe)(d, (u = (o = p.attribute) == null ? void 0 : o.configuration) == null ? void 0 : u.precision)), 1)
                ];
              }),
              default: t(() => [
                a(e(Me), null, {
                  default: t(() => [
                    a(e(ve), {
                      fluid: "",
                      class: "pl-0"
                    }, {
                      default: t(() => [
                        a(e(K), null, {
                          default: t(() => [
                            a(e(C), {
                              lg: "3",
                              md: "4",
                              class: "pointer",
                              onClick: (o) => m(d)
                            }, {
                              default: t(() => [
                                a(O, {
                                  modelValue: d.basePrice,
                                  "onUpdate:modelValue": (o) => d.basePrice = o,
                                  label: e(V)("pim-plugin.price-field.basePrice"),
                                  "price-size": "5",
                                  readonly: ""
                                }, null, 8, ["modelValue", "onUpdate:modelValue", "label"]),
                                a(O, {
                                  modelValue: d.msrp,
                                  "onUpdate:modelValue": (o) => d.msrp = o,
                                  label: e(V)("pim-plugin.price-field.msrp"),
                                  "price-size": "5",
                                  readonly: ""
                                }, null, 8, ["modelValue", "onUpdate:modelValue", "label"]),
                                a(e(Se), {
                                  color: "secondary_1-3",
                                  class: "mb-3"
                                }),
                                a(e(C), null, {
                                  default: t(() => {
                                    var o, u;
                                    return [
                                      a(e($), {
                                        "model-value": e(pe)(
                                          d,
                                          (u = (o = p.attribute) == null ? void 0 : o.configuration) == null ? void 0 : u.precision
                                        ),
                                        label: e(V)("pim-plugin.price-field.currentPrice"),
                                        readonly: ""
                                      }, null, 8, ["model-value", "label"])
                                    ];
                                  }),
                                  _: 2
                                }, 1024)
                              ]),
                              _: 2
                            }, 1032, ["onClick"]),
                            a(e(C), {
                              lg: "7",
                              md: "8",
                              "offset-lg": "2"
                            }, {
                              default: t(() => [
                                a(e(K), null, {
                                  default: t(() => [
                                    a(e(C), {
                                      lg: "3",
                                      md: "4",
                                      sm: "5",
                                      cols: "7"
                                    }, {
                                      default: t(() => [
                                        a(e($), {
                                          modelValue: h.value[g],
                                          "onUpdate:modelValue": (o) => h.value[g] = o,
                                          label: e(V)("pim-plugin.price-field.date"),
                                          type: "date"
                                        }, null, 8, ["modelValue", "onUpdate:modelValue", "label"])
                                      ]),
                                      _: 2
                                    }, 1024),
                                    a(e(C), {
                                      lg: "9",
                                      md: "8"
                                    }, {
                                      default: t(() => [
                                        a(we, {
                                          price: d,
                                          date: h.value[g],
                                          currency: d.currency
                                        }, null, 8, ["price", "date", "currency"])
                                      ]),
                                      _: 2
                                    }, 1024)
                                  ]),
                                  _: 2
                                }, 1024)
                              ]),
                              _: 2
                            }, 1024)
                          ]),
                          _: 2
                        }, 1024)
                      ]),
                      _: 2
                    }, 1024)
                  ]),
                  _: 2
                }, 1024)
              ]),
              _: 2
            }, 1024)
          ]),
          modals: t(() => [
            E.value ? (_(), Q(be, {
              key: 0,
              modelValue: E.value,
              "onUpdate:modelValue": v[1] || (v[1] = (d) => E.value = d),
              "is-edit": c.value >= 0,
              price: P.value,
              currencies: x.value,
              readonly: p.readOnly || !y.value,
              onSave: l
            }, null, 8, ["modelValue", "is-edit", "price", "currencies", "readonly"])) : re("", !0)
          ]),
          _: 2
        }, [
          p.readOnly ? void 0 : {
            name: "actions",
            fn: t(() => [
              a(e(Fe), {
                data: e(n),
                text: e(V)("pim-plugin.price-field.taxClass"),
                loading: e(s),
                color: "primary",
                "item-value": "id",
                "item-title": "name",
                onEvent: v[0] || (v[0] = (d, { id: g }) => M({ taxClassId: g, currencies: [] }))
              }, null, 8, ["data", "text", "loading"]),
              a(e(te), {
                text: e(V)("pim-plugin.price-field.newCurrency"),
                disabled: !x.value.length,
                "prepend-icon": "add_circle",
                color: "primary",
                variant: "text",
                onClick: D
              }, null, 8, ["text", "disabled"])
            ]),
            key: "0"
          }
        ]), 1040)
      ]),
      _: 1
    }));
  }
});
typeof I == "function" && I(Pe);
const cl = /* @__PURE__ */ fe(Pe, [["__scopeId", "data-v-15c127a6"]]);
export {
  cl as default
};
