import { jsxs as c, jsx as e } from "react/jsx-runtime";
import { useFormatNumberWithCurrency as le } from "./index-use-format-number-with-currency.js";
import { dFlexRow as ce, dFlex as de } from "./index-general.module.js";
import { classNames as s } from "./index-classNames.js";
import { Avatar as me } from "./index-Avatar.js";
import { ComponentContainer as he } from "./index-ComponentContainer.js";
import { Icon as fe } from "./index-Icon.js";
import { IconNames as p } from "./index-IconNames.js";
import { StatusBadge as ue } from "./index-StatusBadge.js";
import { TextTypes as g, FontWeights as l, Text as i } from "./index-Text.js";
import { useState as m, useEffect as B } from "react";
import { AnimatedConditional as pe } from "./index-AnimatedConditional.js";
import a from "./index-BigLegendItem.module.scss.js";
const Ie = (_) => {
  const {
    currentNumber: n,
    previousNumber: o,
    totalNumber: h,
    title: y,
    description: F,
    descriptionColor: D = "--n500",
    descriptionType: L = g.textCaption,
    descriptionFont: M = l.regular,
    iconName: N,
    iconSize: z,
    iconFillColor: A = "--n300",
    showBadge: j,
    showPercentage: E = !1,
    testId: C = "BigLegendItem",
    previousNumberText: H = "previously",
    showPreviousNumber: K = !0,
    showPreviousNumberText: R = !0,
    showPercentageFromTotal: U = !1,
    topTitle: x,
    roundNumbers: W = !1,
    formatWithCurrency: V = !1,
    maxWidth: k = "300px",
    showOutOfSeries: $,
    totalNumberSeries: T = [],
    style: q,
    replacements: w,
    isDateTime: G = !1,
    isPercentageFormat: J = !1,
    isTime: Q = !1,
    className: X,
    showTotalNumberSeries: Y = !0,
    showAvatar: Z = !1,
    avatar: ee,
    totalNumberType: S,
    locale: te,
    currencyISO: re
  } = _, [oe, f] = m("0%"), [ne, I] = m("0%"), [ae, b] = m(p.remove), [ie, v] = m("neutral"), [P, u] = m("no change"), se = le(te, re);
  B(() => {
    if (o) {
      let t = "", d = "", r = "";
      b(p.remove), v("neutral"), u("no change"), f("0%"), n > o && (b(p.arrowUp), v("success"), t = ((n - o) / o * 100).toFixed(1), r = `${t}%`, u(t === "0" ? r : `+${r}`), f(r), o === 0 && (t = ((n - o) * 100).toFixed(1), r = `${t}%`, u(t === "0" ? r : `+${r}`), f(r))), n < o && (b(p.arrowDown), v("danger"), d = ((o - n) / o * 100).toFixed(1), r = `${d}%`, u(d === "0" ? r : `-${r}`), f(r));
    }
  }, [n, o]), B(() => {
    n === 0 || h === 0 ? I("0%") : h && I(`${Math.round(n / h * 100)}%`);
  }, [n, h]);
  function O(t, d) {
    if (G) {
      const r = new Date(n);
      return `${r.getMinutes()}m ${r.getSeconds()}s`;
    }
    return J ? `${t % 1 === 0 ? t : t.toFixed(2)}%` : Q ? `${Math.floor(t / 60)}m ${Math.floor(t % 60)}s` : V ? se(t, {
      numberOfDecimals: 2
    }) : d ? t < 1e3 ? t.toString() : `${parseFloat((t / 1e3).toFixed(2))}K` : t.toLocaleString();
  }
  return c(he, {
    testId: C,
    style: {
      maxWidth: k,
      ...q
    },
    className: X,
    children: [c("div", {
      className: s(a.container),
      children: [N && e("div", {
        className: a.iconContainer,
        children: e(fe, {
          hasCircle: !0,
          color: "--n000",
          fillColor: A,
          type: z,
          circleSize: 32,
          className: s(a.icon),
          children: N
        })
      }), c("div", {
        children: [typeof x == "string" ? e(i, {
          fontWeight: l.bold,
          testId: `${C}_topTitle`,
          replacements: w,
          children: x
        }) : x, c("div", {
          className: s($ ? a.dataOutOfSeries : a.data),
          children: [Z && e("span", {
            className: s(a.avatar),
            children: e(me, {
              icon: ee,
              size: "small"
            })
          }), Y && e("span", {
            children: e(i, {
              type: S || g.heading2,
              fontWeight: l.bold,
              color: "--n700",
              testId: "BigLegendItem_FormattedNumber_TestId",
              translate: !1,
              children: T.length ? T[1] : O(n, W)
            })
          }), U && e("span", {
            className: s(a.percentageContainer),
            children: e(i, {
              textTight: !0,
              fontWeight: l.bold,
              color: "--n500",
              translate: !1,
              children: ne
            })
          }), E && e("span", {
            className: s(a.percentageContainer),
            children: e(i, {
              textTight: !0,
              fontWeight: l.bold,
              color: "--n500",
              translate: !1,
              children: oe
            })
          }), $ && c("span", {
            className: s(de, ce),
            children: [e(i, {
              textTight: !0,
              fontWeight: l.regular,
              color: "--n700",
              translate: !1,
              children: "/"
            }), e(i, {
              textTight: !0,
              fontWeight: l.regular,
              color: "--n700",
              replacements: {
                total_number: T[0]
              },
              children: "Out of %total_number%"
            })]
          }), e(pe, {
            condition: o !== void 0,
            children: c("span", {
              className: s(a.data),
              children: [j && e("span", {
                className: a.badge,
                children: e(ue, {
                  status: ie,
                  text: P,
                  icon: ae,
                  iconVariant: "reverse"
                })
              }, P), K && e("span", {
                children: e(i, {
                  textTight: !0,
                  fontWeight: l.bold,
                  color: "--n400",
                  translate: !1,
                  children: O(o ?? 0, W)
                })
              }), R && e("span", {
                children: e(i, {
                  type: g.textCaption,
                  color: "--n400",
                  children: H
                })
              })]
            })
          })]
        })]
      })]
    }), c("div", {
      className: s(N ? a.bottomContainerPadding : null),
      children: [y && e(i, {
        type: g.textHelp,
        textTight: !0,
        fontWeight: l.medium,
        color: "--n700",
        replacements: w,
        children: y
      }), F && e(i, {
        type: L,
        color: D,
        fontWeight: M,
        children: F
      })]
    })]
  });
};
export {
  Ie as BigLegendItem
};
