import { jsxs as C, jsx as r } from "react/jsx-runtime";
/* empty css                     */
import { InfoIcon as A } from "./index-InfoIcon.js";
import { CHART_COLORS as G } from "./index-colors.js";
import { classNames as S } from "./index-classNames.js";
import { translationService as K } from "./index-translation.service.js";
import { BigLegend as U } from "./index-BigLegend.js";
import { BigLegendItem as q } from "./index-BigLegendItem.js";
import { ChartsPlaceholder as J } from "./index-ChartsPlaceholder.js";
import { useGetTotalSeriesValues as M } from "./index-use-get-total-series-values.js";
import { useLineChartOptions as Q } from "./index-use-line-chart-options.js";
import { IconSize as X } from "./index-Icon.js";
import { Render as v } from "./index-Render.js";
import { Text as Y, TextTypes as Z } from "./index-Text.js";
import { useEffect as ee, useCallback as te } from "react";
import re from "./index-react-apexcharts.min.js";
const oe = (d) => {
  const {
    series: t,
    previousSeries: a,
    height: p,
    width: g,
    colors: N = G,
    showBigLegend: L,
    showChartHeader: I = !0,
    bigLegendData: n,
    chartTitle: B,
    testId: c = "LineChartTestId",
    showPreviousNumber: x = !1,
    showPreviousNumberText: y = !1,
    showPercentage: O = !1,
    showBadge: T = !1,
    bigLegendProps: m,
    showOutOfSeries: P = !1,
    totalBudgetFormatted: b,
    totalBudgetUsedFormatted: D,
    replacements: E,
    isLoading: R,
    provideCustomTotals: h = !1,
    seriesTotal: j,
    previousSeriesTotal: F,
    showInfoIcon: H,
    infoIconData: l,
    showTotalNumberSeries: _ = !0
  } = d, {
    lineChartOptions: k,
    renderKey: z
  } = Q(d), V = (s) => {
    s.forEach((e, o) => {
      e && typeof e == "object" && (e.name = K.get(e.name, e.replacements ?? E).value);
    });
  };
  ee(() => {
    try {
      V(t);
    } catch {
    }
  }, [t]);
  const u = M(t, a), w = (s) => {
    let e = 0;
    return s.forEach((o, i) => {
      e += o;
    }), e;
  }, f = () => h ? j ?? 0 : w(u(t)), W = () => h ? F ?? 0 : w(u(a)), $ = te(() => {
    const s = u(t), e = u(a);
    return n && n.forEach((o, i) => {
      t[i] && (o.title = t[i].name), h || (o.currentNumber = s[i], a && (o.previousNumber = e[i])), N && (o.iconFillColor = N[i]);
    }), n;
  }, [n, t, a]);
  return C("div", {
    "data-testid": c,
    className: S("lineChart-container"),
    children: [r(v, {
      if: R,
      children: r(J, {})
    }), r(v, {
      if: I,
      children: r("div", {
        className: S("lineChart-header"),
        children: r(q, {
          roundNumbers: !0,
          showPreviousNumber: x,
          showPreviousNumberText: y,
          showPercentage: O,
          showBadge: T,
          currentNumber: f(),
          previousNumber: W(),
          totalNumber: f(),
          totalNumberType: m == null ? void 0 : m.totalNumberType,
          showOutOfSeries: P,
          showTotalNumberSeries: _,
          totalNumberSeries: b ? [b, D] : [],
          topTitle: B,
          testId: `${c}_Title`,
          maxWidth: "60%"
        })
      })
    }), r(re, {
      options: k,
      series: t,
      type: "line",
      width: g || "100%",
      height: p || "300px"
    }, z), H && l && C("div", {
      className: "lineChart-infoIcon",
      children: [r(A, {
        message: l.message,
        theme: "dark",
        size: X.small,
        maxWidth: "fit-content",
        replacements: l.messageReplacements
      }), r(Y, {
        type: Z.textHelp,
        color: "--n700",
        children: l.title
      })]
    }), L && n && r(U, {
      testId: `${c}_BigLegend`,
      roundNumbers: !0,
      showBadge: T,
      ...m,
      totalNumber: f(),
      bigLegendData: $()
    })]
  });
}, we = oe;
export {
  we as LineChartBase
};
