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