import { u as useRecordVisibilityChanges, j as jsxRuntimeExports } from "./doenetml-cB_aZGJ5.js";
import React__default, { useRef } from "react";
import { u as useDoenetRenderer } from "./useDoenetRenderer-DN3Z9CW3.js";
import { a as addCommasForCompositeRanges } from "./composites-DgtFnuE1.js";
import { c as calculateValidationState, a as createCheckWorkComponent } from "./checkWork-D9syAFsW.js";
const list = React__default.memo(function List(props) {
  let { id, SVs, children, actions, callAction } = useDoenetRenderer(props);
  const ref = useRef(null);
  useRecordVisibilityChanges(ref, callAction, actions);
  if (SVs.hidden) {
    return null;
  }
  let checkWorkComponent = null;
  if (actions.submitAllAnswers) {
    const submitAllAnswers = () => callAction({
      action: actions.submitAllAnswers
    });
    const validationState = calculateValidationState(SVs);
    checkWorkComponent = createCheckWorkComponent(
      SVs,
      id,
      validationState,
      submitAllAnswers,
      true
    );
  }
  if (SVs._compositeReplacementActiveRange) {
    children = addCommasForCompositeRanges({
      children,
      compositeReplacementActiveRange: SVs._compositeReplacementActiveRange,
      startInd: 0,
      endInd: children.length - 1
    });
  }
  if (SVs.item) {
    return /* @__PURE__ */ jsxRuntimeExports.jsxs("li", { id, ref, children: [
      children,
      checkWorkComponent
    ] });
  } else if (SVs.numbered) {
    let list_style;
    if (SVs.marker) {
      if (SVs.marker[0] === "1") {
        list_style = "decimal";
      } else if (SVs.marker[0] === "a") {
        list_style = "lower-alpha";
      } else if (SVs.marker[0] === "i") {
        list_style = "lower-roman";
      } else if (SVs.marker[0] === "A") {
        list_style = "upper-alpha";
      } else if (SVs.marker[0] === "I") {
        list_style = "upper-roman";
      }
    }
    if (!list_style) {
      list_style = styleTypeByLevel.numbered[(SVs.level - 1) % styleTypeByLevel.numbered.length];
    }
    return /* @__PURE__ */ jsxRuntimeExports.jsx("ol", { id, style: { listStyleType: list_style }, ref, children });
  } else {
    let list_style;
    if (SVs.marker) {
      list_style = SVs.marker.toLowerCase();
      if (!unnumberedStyles.includes(list_style)) {
        list_style = null;
      }
    }
    if (!list_style) {
      list_style = styleTypeByLevel.unnumbered[(SVs.level - 1) % styleTypeByLevel.unnumbered.length];
    }
    return /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { id, style: { listStyleType: list_style }, ref, children });
  }
});
const unnumberedStyles = ["disc", "circle", "square"];
const styleTypeByLevel = {
  numbered: [
    "decimal",
    "lower-alpha",
    "lower-roman",
    "upper-alpha",
    "upper-roman"
  ],
  unnumbered: unnumberedStyles
};
export {
  list as default
};
