"use strict";
const jsxRuntime = require("react/jsx-runtime");
const React = require("react");
const styles_lib_components_Accordion_AccordionItem_cjs = require("../Accordion/AccordionItem.cjs");
const styles_lib_components_Stack_Stack_cjs = require("../Stack/Stack.cjs");
const styles_lib_components_Box_Box_cjs = require("../Box/Box.cjs");
const styles_lib_css_lineHeightContainer_css_cjs = require("../../css/lineHeightContainer.css.cjs");
const styles_lib_components_List_List_css_cjs = require("./List.css.cjs");
function numberToAlpha(inputNumber) {
  let returnValue = "";
  let counter = inputNumber;
  while (counter > 0) {
    const t = (counter - 1) % 26;
    returnValue = String.fromCharCode(97 + t) + returnValue;
    counter = (counter - t) / 26 | 0;
  }
  return returnValue;
}
const romanNumerals = {
  m: 1e3,
  cm: 900,
  d: 500,
  cd: 400,
  c: 100,
  xc: 90,
  l: 50,
  xl: 40,
  x: 10,
  ix: 9,
  v: 5,
  iv: 4,
  i: 1
};
function numberToRomanNumerals(inputNumber) {
  let returnValue = "";
  let counter = inputNumber;
  Object.keys(romanNumerals).forEach(
    (romanNumeral) => {
      const value = romanNumerals[romanNumeral];
      while (counter >= value) {
        returnValue += romanNumeral;
        counter -= value;
      }
    }
  );
  return returnValue;
}
const CharacterBullet = ({ length = 1, children }) => /* @__PURE__ */ jsxRuntime.jsxs(
  styles_lib_components_Box_Box_cjs.Box,
  {
    display: "inlineBlock",
    className: [
      styles_lib_components_List_List_css_cjs.minCharacterWidth[length - 1] ?? styles_lib_components_List_List_css_cjs.minCharacterWidth[styles_lib_components_List_List_css_cjs.minCharacterWidth.length - 1],
      styles_lib_components_List_List_css_cjs.trimGutter
    ],
    children: [
      children,
      "."
    ]
  }
);
const List = ({
  children,
  size: sizeProp,
  tone: toneProp,
  space = "medium",
  type = "bullet",
  start = 1,
  data,
  ...restProps
}) => {
  const { size, tone } = styles_lib_components_Accordion_AccordionItem_cjs.useDefaultTextProps({
    size: sizeProp,
    tone: toneProp
  });
  const listItems = styles_lib_components_Accordion_AccordionItem_cjs.flattenChildren(children);
  const lastNumberLength = type === "number" ? (listItems.length + (start - 1)).toString().length : -1;
  return /* @__PURE__ */ jsxRuntime.jsx(styles_lib_components_Accordion_AccordionItem_cjs.DefaultTextPropsProvider, { size, tone, children: /* @__PURE__ */ jsxRuntime.jsx(
    styles_lib_components_Stack_Stack_cjs.Stack,
    {
      component: /^(bullet|icon)$/.test(type) ? "ul" : "ol",
      space,
      data,
      children: React.Children.map(listItems, (listItem, index) => {
        const resolvedIndex = index + (start - 1);
        return /* @__PURE__ */ jsxRuntime.jsxs(styles_lib_components_Box_Box_cjs.Box, { display: "flex", children: [
          /* @__PURE__ */ jsxRuntime.jsx(styles_lib_components_Accordion_AccordionItem_cjs.Text, { component: "div", size, tone, children: /* @__PURE__ */ jsxRuntime.jsx(
            styles_lib_components_Box_Box_cjs.Box,
            {
              display: "flex",
              alignItems: /^(bullet|icon)$/.test(type) ? "center" : void 0,
              className: styles_lib_css_lineHeightContainer_css_cjs.lineHeightContainer[size],
              userSelect: "none",
              "aria-hidden": true,
              children: (() => {
                if (type === "number") {
                  return /* @__PURE__ */ jsxRuntime.jsx(CharacterBullet, { length: lastNumberLength, children: resolvedIndex + 1 });
                }
                if (type === "alpha") {
                  return /* @__PURE__ */ jsxRuntime.jsx(CharacterBullet, { children: numberToAlpha(resolvedIndex + 1) });
                }
                if (type === "roman") {
                  return /* @__PURE__ */ jsxRuntime.jsx(CharacterBullet, { length: 2, children: numberToRomanNumerals(resolvedIndex + 1) });
                }
                if (type === "icon" && "icon" in restProps) {
                  return restProps.icon;
                }
                return /* @__PURE__ */ jsxRuntime.jsx(
                  styles_lib_components_Box_Box_cjs.Box,
                  {
                    borderRadius: "full",
                    className: [styles_lib_components_List_List_css_cjs.currentColor, styles_lib_components_List_List_css_cjs.size[size]]
                  }
                );
              })()
            }
          ) }),
          /* @__PURE__ */ jsxRuntime.jsx(
            styles_lib_components_Box_Box_cjs.Box,
            {
              minWidth: 0,
              width: "full",
              paddingLeft: size === "xsmall" ? "xsmall" : "small",
              children: listItem
            }
          )
        ] });
      })
    }
  ) });
};
exports.List = List;
