"use strict";
var import_Progress = require("../Progress.css");
const jsxRuntime = require("react/jsx-runtime");
const kit_Theme_UI = require("./Theme/UI.cjs");
const kit_Theme_themeUtils = require("./Theme/themeUtils.cjs");
const kit_Theme_themes = require("./Theme/themes.cjs");
const kit_Tooltip = require("./Tooltip.cjs");
const base = "Progress_base_2f644";
const parts = "Progress_parts_2f644";
const bar = "Progress_bar_2f644";
const flat = "Progress_flat_2f644";
const legendContainer = "Progress_legendContainer_2f644";
const legendItem = "Progress_legendItem_2f644";
const colorButton = "Progress_colorButton_2f644";
const title = "Progress_title_2f644";
const css = {
  base,
  parts,
  bar,
  flat,
  legendContainer,
  legendItem,
  colorButton,
  title
};
const floatToPercent = (num, precision = 2) => {
  if (isNaN(num))
    return "NaN";
  if (num === Infinity)
    return "Infinity";
  if (num === -Infinity)
    return "-Infinity";
  return (num * 100).toFixed(precision) + "%";
};
const partStyle = (part) => ({
  backgroundColor: part.color,
  width: floatToPercent(part.percent, 0)
});
const sizeMap = {
  [kit_Theme_themes.ShirtSize.Small]: kit_Theme_themeUtils.Spacing.Xs,
  [kit_Theme_themes.ShirtSize.Medium]: kit_Theme_themeUtils.Spacing.Lg,
  [kit_Theme_themes.ShirtSize.Large]: kit_Theme_themeUtils.Spacing.Xl3
};
const Progress = ({
  flat: flat2,
  parts: parts2,
  showLegend,
  showTooltips,
  size = kit_Theme_themes.ShirtSize.Small,
  title: title2
}) => {
  const {
    themeSettings: { className: themeClass }
  } = kit_Theme_UI.useTheme();
  const classes = [css.base, themeClass];
  if (flat2)
    classes.push(css.flat);
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
    title2 && /* @__PURE__ */ jsxRuntime.jsx("h5", { className: css.title, children: title2 }),
    /* @__PURE__ */ jsxRuntime.jsx("div", { className: classes.join(" "), children: /* @__PURE__ */ jsxRuntime.jsx(
      "div",
      {
        className: css.bar,
        style: { height: `calc((${sizeMap[size]} + var(--theme-density)) * 1px)` },
        children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: css.parts, children: parts2.filter((part) => part.percent !== 0 && !isNaN(part.percent)).map((part, idx) => /* @__PURE__ */ jsxRuntime.jsx(kit_Tooltip, { content: showTooltips && part.label, children: /* @__PURE__ */ jsxRuntime.jsx(
          "li",
          {
            "aria-label": `${part.label} ${part.percent * 100} percent`,
            role: "progressbar",
            style: {
              ...partStyle(part),
              cursor: showTooltips && part.label ? "pointer" : ""
            }
          }
        ) }, idx)) })
      }
    ) }),
    showLegend && /* @__PURE__ */ jsxRuntime.jsx("div", { className: css.legendContainer, children: parts2.filter((part) => part.percent !== 0 && !isNaN(part.percent)).map((part, idx) => /* @__PURE__ */ jsxRuntime.jsxs("li", { className: css.legendItem, children: [
      /* @__PURE__ */ jsxRuntime.jsx("span", { className: css.colorButton, style: partStyle(part), children: "-" }),
      part.label
    ] }, idx)) })
  ] });
};
module.exports = Progress;
