// src/components/Alternative/Alternative.tsx
import { CheckCircle, XCircle } from "phosphor-react";

// src/components/Badge/Badge.tsx
import { Bell } from "phosphor-react";

// src/utils/utils.ts
import { clsx } from "clsx";
import { twMerge } from "tailwind-merge";
function cn(...inputs) {
  return twMerge(clsx(inputs));
}

// src/components/Badge/Badge.tsx
import { jsx, jsxs } from "react/jsx-runtime";
var VARIANT_ACTION_CLASSES = {
  solid: {
    error: "bg-error-background text-error-700 focus-visible:outline-none",
    warning: "bg-warning text-warning-800 focus-visible:outline-none",
    success: "bg-success text-success-800 focus-visible:outline-none",
    info: "bg-info text-info-800 focus-visible:outline-none",
    muted: "bg-background-muted text-background-800 focus-visible:outline-none"
  },
  outlined: {
    error: "bg-error text-error-700 border border-error-300 focus-visible:outline-none",
    warning: "bg-warning text-warning-800 border border-warning-300 focus-visible:outline-none",
    success: "bg-success text-success-800 border border-success-300 focus-visible:outline-none",
    info: "bg-info text-info-800 border border-info-300 focus-visible:outline-none",
    muted: "bg-background-muted text-background-800 border border-border-300 focus-visible:outline-none"
  },
  exams: {
    exam1: "bg-exam-1 text-info-700 focus-visible:outline-none",
    exam2: "bg-exam-2 text-typography-1 focus-visible:outline-none",
    exam3: "bg-exam-3 text-typography-2 focus-visible:outline-none",
    exam4: "bg-exam-4 text-success-700 focus-visible:outline-none"
  },
  examsOutlined: {
    exam1: "bg-exam-1 text-info-700 border border-info-700 focus-visible:outline-none",
    exam2: "bg-exam-2 text-typography-1 border border-typography-1 focus-visible:outline-none",
    exam3: "bg-exam-3 text-typography-2 border border-typography-2 focus-visible:outline-none",
    exam4: "bg-exam-4 text-success-700 border border-success-700 focus-visible:outline-none"
  },
  resultStatus: {
    negative: "bg-error text-error-800 focus-visible:outline-none",
    positive: "bg-success text-success-800 focus-visible:outline-none"
  },
  notification: "text-primary"
};
var SIZE_CLASSES = {
  small: "text-2xs px-2 py-1",
  medium: "text-xs px-2 py-1",
  large: "text-sm px-2 py-1"
};
var SIZE_CLASSES_ICON = {
  small: "size-3",
  medium: "size-3.5",
  large: "size-4"
};
var Badge = ({
  children,
  iconLeft,
  iconRight,
  size = "medium",
  variant = "solid",
  action = "error",
  className = "",
  notificationActive = false,
  ...props
}) => {
  const sizeClasses = SIZE_CLASSES[size];
  const sizeClassesIcon = SIZE_CLASSES_ICON[size];
  const variantActionMap = VARIANT_ACTION_CLASSES[variant] || {};
  const variantClasses = typeof variantActionMap === "string" ? variantActionMap : variantActionMap[action] ?? variantActionMap.muted ?? "";
  const baseClasses = "inline-flex items-center justify-center rounded-xs font-normal gap-1 relative";
  const baseClassesIcon = "flex items-center";
  if (variant === "notification") {
    return /* @__PURE__ */ jsxs(
      "div",
      {
        className: cn(baseClasses, variantClasses, sizeClasses, className),
        ...props,
        children: [
          /* @__PURE__ */ jsx(Bell, { size: 24, className: "text-current", "aria-hidden": "true" }),
          notificationActive && /* @__PURE__ */ jsx(
            "span",
            {
              "data-testid": "notification-dot",
              className: "absolute top-[5px] right-[10px] block h-2 w-2 rounded-full bg-indicator-error ring-2 ring-white"
            }
          )
        ]
      }
    );
  }
  return /* @__PURE__ */ jsxs(
    "div",
    {
      className: cn(baseClasses, variantClasses, sizeClasses, className),
      ...props,
      children: [
        iconLeft && /* @__PURE__ */ jsx("span", { className: cn(baseClassesIcon, sizeClassesIcon), children: iconLeft }),
        children,
        iconRight && /* @__PURE__ */ jsx("span", { className: cn(baseClassesIcon, sizeClassesIcon), children: iconRight })
      ]
    }
  );
};
var Badge_default = Badge;

// src/components/Radio/Radio.tsx
import {
  forwardRef,
  useState,
  useId,
  useEffect,
  useRef,
  Children,
  cloneElement,
  isValidElement
} from "react";
import { create, useStore } from "zustand";

// src/components/Text/Text.tsx
import { jsx as jsx2 } from "react/jsx-runtime";
var Text = ({
  children,
  size = "md",
  weight = "normal",
  color = "text-text-950",
  as,
  className = "",
  ...props
}) => {
  let sizeClasses;
  let weightClasses;
  const sizeClassMap = {
    "2xs": "text-2xs",
    xs: "text-xs",
    sm: "text-sm",
    md: "text-md",
    lg: "text-lg",
    xl: "text-xl",
    "2xl": "text-2xl",
    "3xl": "text-3xl",
    "4xl": "text-4xl",
    "5xl": "text-5xl",
    "6xl": "text-6xl"
  };
  sizeClasses = sizeClassMap[size] ?? sizeClassMap.md;
  const weightClassMap = {
    hairline: "font-hairline",
    light: "font-light",
    normal: "font-normal",
    medium: "font-medium",
    semibold: "font-semibold",
    bold: "font-bold",
    extrabold: "font-extrabold",
    black: "font-black"
  };
  weightClasses = weightClassMap[weight] ?? weightClassMap.normal;
  const baseClasses = "font-primary";
  const Component = as ?? "p";
  return /* @__PURE__ */ jsx2(
    Component,
    {
      className: cn(baseClasses, sizeClasses, weightClasses, color, className),
      ...props,
      children
    }
  );
};
var Text_default = Text;

// src/components/Radio/Radio.tsx
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
var SIZE_CLASSES2 = {
  small: {
    radio: "w-5 h-5",
    textSize: "sm",
    spacing: "gap-1.5",
    borderWidth: "border-2",
    dotSize: "w-2.5 h-2.5",
    labelHeight: "h-5"
  },
  medium: {
    radio: "w-6 h-6",
    textSize: "md",
    spacing: "gap-2",
    borderWidth: "border-2",
    dotSize: "w-3 h-3",
    labelHeight: "h-6"
  },
  large: {
    radio: "w-7 h-7",
    textSize: "lg",
    spacing: "gap-2",
    borderWidth: "border-2",
    dotSize: "w-3.5 h-3.5",
    labelHeight: "h-7"
  },
  extraLarge: {
    radio: "w-8 h-8",
    textSize: "xl",
    spacing: "gap-3",
    borderWidth: "border-2",
    dotSize: "w-4 h-4",
    labelHeight: "h-8"
  }
};
var BASE_RADIO_CLASSES = "rounded-full border cursor-pointer transition-all duration-200 flex items-center justify-center focus:outline-none";
var STATE_CLASSES = {
  default: {
    unchecked: "border-border-400 bg-background hover:border-border-500",
    checked: "border-primary-950 bg-background hover:border-primary-800"
  },
  hovered: {
    unchecked: "border-border-500 bg-background",
    checked: "border-info-700 bg-background"
  },
  focused: {
    unchecked: "border-border-400 bg-background",
    checked: "border-primary-950 bg-background"
  },
  invalid: {
    unchecked: "border-border-400 bg-background",
    checked: "border-primary-950 bg-background"
  },
  disabled: {
    unchecked: "border-border-400 bg-background cursor-not-allowed",
    checked: "border-primary-950 bg-background cursor-not-allowed"
  }
};
var DOT_CLASSES = {
  default: "bg-primary-950",
  hovered: "bg-info-700",
  focused: "bg-primary-950",
  invalid: "bg-primary-950",
  disabled: "bg-primary-950"
};
var Radio = forwardRef(
  ({
    label,
    size = "medium",
    state = "default",
    errorMessage,
    helperText,
    className = "",
    labelClassName = "",
    checked: checkedProp,
    defaultChecked = false,
    disabled,
    id,
    name,
    value,
    onChange,
    ...props
  }, ref) => {
    const generatedId = useId();
    const inputId = id ?? `radio-${generatedId}`;
    const inputRef = useRef(null);
    const [internalChecked, setInternalChecked] = useState(defaultChecked);
    const isControlled = checkedProp !== void 0;
    const checked = isControlled ? checkedProp : internalChecked;
    const handleChange = (event) => {
      const newChecked = event.target.checked;
      if (!isControlled) {
        setInternalChecked(newChecked);
      }
      if (event.target) {
        event.target.blur();
      }
      onChange?.(event);
    };
    const currentState = disabled ? "disabled" : state;
    const sizeClasses = SIZE_CLASSES2[size];
    const actualRadioSize = sizeClasses.radio;
    const actualDotSize = sizeClasses.dotSize;
    const radioVariant = checked ? "checked" : "unchecked";
    const stylingClasses = STATE_CLASSES[currentState][radioVariant];
    const getBorderWidth = () => {
      if (currentState === "focused") {
        return "border-2";
      }
      return sizeClasses.borderWidth;
    };
    const borderWidthClass = getBorderWidth();
    const radioClasses = cn(
      BASE_RADIO_CLASSES,
      actualRadioSize,
      borderWidthClass,
      stylingClasses,
      className
    );
    const dotClasses = cn(
      actualDotSize,
      "rounded-full",
      DOT_CLASSES[currentState],
      "transition-all duration-200"
    );
    const isWrapperNeeded = currentState === "focused" || currentState === "invalid";
    const wrapperBorderColor = currentState === "focused" ? "border-indicator-info" : "border-indicator-error";
    const getTextColor = () => {
      if (currentState === "disabled") {
        return checked ? "text-text-900" : "text-text-600";
      }
      if (currentState === "focused") {
        return "text-text-900";
      }
      return checked ? "text-text-900" : "text-text-600";
    };
    const getCursorClass = () => {
      return currentState === "disabled" ? "cursor-not-allowed" : "cursor-pointer";
    };
    return /* @__PURE__ */ jsxs2("div", { className: "flex flex-col", children: [
      /* @__PURE__ */ jsxs2(
        "div",
        {
          className: cn(
            "flex flex-row items-center",
            isWrapperNeeded ? cn("p-1 border-2", wrapperBorderColor, "rounded-lg gap-1.5") : sizeClasses.spacing,
            disabled ? "opacity-40" : ""
          ),
          children: [
            /* @__PURE__ */ jsx3(
              "input",
              {
                ref: (node) => {
                  inputRef.current = node;
                  if (typeof ref === "function") ref(node);
                  else if (ref) ref.current = node;
                },
                type: "radio",
                id: inputId,
                checked,
                disabled,
                name,
                value,
                onChange: handleChange,
                className: "sr-only",
                style: {
                  position: "absolute",
                  left: "-9999px",
                  visibility: "hidden"
                },
                ...props
              }
            ),
            /* @__PURE__ */ jsx3(
              "button",
              {
                type: "button",
                className: radioClasses,
                disabled,
                "aria-pressed": checked,
                onClick: (e) => {
                  e.preventDefault();
                  if (!disabled) {
                    if (inputRef.current) {
                      inputRef.current.click();
                      inputRef.current.blur();
                    }
                  }
                },
                onKeyDown: (e) => {
                  if ((e.key === "Enter" || e.key === " ") && !disabled) {
                    e.preventDefault();
                    if (inputRef.current) {
                      inputRef.current.click();
                      inputRef.current.blur();
                    }
                  }
                },
                children: checked && /* @__PURE__ */ jsx3("div", { className: dotClasses })
              }
            ),
            label && /* @__PURE__ */ jsx3(
              "div",
              {
                className: cn(
                  "flex flex-row items-center",
                  sizeClasses.labelHeight,
                  "flex-1 min-w-0"
                ),
                children: /* @__PURE__ */ jsx3(
                  Text_default,
                  {
                    as: "label",
                    htmlFor: inputId,
                    size: sizeClasses.textSize,
                    weight: "normal",
                    className: cn(
                      getCursorClass(),
                      "select-none leading-normal flex items-center font-roboto truncate",
                      labelClassName
                    ),
                    color: getTextColor(),
                    children: label
                  }
                )
              }
            )
          ]
        }
      ),
      errorMessage && /* @__PURE__ */ jsx3(
        Text_default,
        {
          size: "sm",
          weight: "normal",
          className: "mt-1.5 truncate",
          color: "text-error-600",
          children: errorMessage
        }
      ),
      helperText && !errorMessage && /* @__PURE__ */ jsx3(
        Text_default,
        {
          size: "sm",
          weight: "normal",
          className: "mt-1.5 truncate",
          color: "text-text-500",
          children: helperText
        }
      )
    ] });
  }
);
Radio.displayName = "Radio";
var createRadioGroupStore = (name, defaultValue, disabled, onValueChange) => create((set, get) => ({
  value: defaultValue,
  setValue: (value) => {
    if (!get().disabled) {
      set({ value });
      get().onValueChange?.(value);
    }
  },
  onValueChange,
  disabled,
  name
}));
var useRadioGroupStore = (externalStore) => {
  if (!externalStore) {
    throw new Error("RadioGroupItem must be used within a RadioGroup");
  }
  return externalStore;
};
var injectStore = (children, store) => Children.map(children, (child) => {
  if (!isValidElement(child)) return child;
  const typedChild = child;
  const shouldInject = typedChild.type === RadioGroupItem;
  return cloneElement(typedChild, {
    ...shouldInject ? { store } : {},
    ...typedChild.props.children ? { children: injectStore(typedChild.props.children, store) } : {}
  });
});
var RadioGroup = forwardRef(
  ({
    value: propValue,
    defaultValue = "",
    onValueChange,
    name: propName,
    disabled = false,
    className = "",
    children,
    ...props
  }, ref) => {
    const generatedId = useId();
    const name = propName || `radio-group-${generatedId}`;
    const storeRef = useRef(null);
    storeRef.current ??= createRadioGroupStore(
      name,
      defaultValue,
      disabled,
      onValueChange
    );
    const store = storeRef.current;
    const { setValue } = useStore(store, (s) => s);
    useEffect(() => {
      const currentValue = store.getState().value;
      if (currentValue && onValueChange) {
        onValueChange(currentValue);
      }
    }, []);
    useEffect(() => {
      if (propValue !== void 0) {
        setValue(propValue);
      }
    }, [propValue, setValue]);
    useEffect(() => {
      store.setState({ disabled });
    }, [disabled, store]);
    return /* @__PURE__ */ jsx3(
      "div",
      {
        ref,
        className,
        role: "radiogroup",
        "aria-label": name,
        ...props,
        children: injectStore(children, store)
      }
    );
  }
);
RadioGroup.displayName = "RadioGroup";
var RadioGroupItem = forwardRef(
  ({
    value,
    label,
    labelClassName,
    store: externalStore,
    disabled: itemDisabled,
    size = "medium",
    state = "default",
    className = "",
    id,
    ...props
  }, ref) => {
    const store = useRadioGroupStore(externalStore);
    const {
      value: groupValue,
      setValue,
      disabled: groupDisabled,
      name
    } = useStore(store);
    const generatedId = useId();
    const inputId = id ?? `radio-item-${generatedId}`;
    const isChecked = groupValue === value;
    const isDisabled = groupDisabled || itemDisabled;
    const currentState = isDisabled ? "disabled" : state;
    return /* @__PURE__ */ jsx3(
      Radio,
      {
        ref,
        id: inputId,
        name,
        value,
        checked: isChecked,
        disabled: isDisabled,
        size,
        state: currentState,
        className,
        label,
        labelClassName,
        onChange: (e) => {
          if (e.target.checked && !isDisabled) {
            setValue(value);
          }
        },
        ...props
      }
    );
  }
);
RadioGroupItem.displayName = "RadioGroupItem";

// src/components/Alternative/Alternative.tsx
import { forwardRef as forwardRef4, useId as useId2, useState as useState2 } from "react";

// src/components/HtmlMathRenderer/HtmlMathRenderer.tsx
import { forwardRef as forwardRef3, memo as memo2 } from "react";
import "katex/dist/katex.min.css";

// src/components/HtmlMathRenderer/KatexMath.tsx
import katex from "katex";
import { Fragment, jsx as jsx4 } from "react/jsx-runtime";
var KatexMath = ({
  math,
  displayMode = false,
  renderError
}) => {
  let html;
  try {
    html = katex.renderToString(math, {
      displayMode,
      throwOnError: true
    });
  } catch (error_) {
    return /* @__PURE__ */ jsx4(Fragment, { children: renderError ? renderError(error_) : null });
  }
  const Tag = displayMode ? "div" : "span";
  return /* @__PURE__ */ jsx4(
    Tag,
    {
      "data-testid": "react-katex",
      dangerouslySetInnerHTML: { __html: html }
    }
  );
};

// src/components/MarkdownMathRenderer/MarkdownMathRenderer.tsx
import { forwardRef as forwardRef2, memo } from "react";
import "katex/dist/katex.min.css";
import ReactMarkdown from "react-markdown";
import remarkGfm from "remark-gfm";
import remarkMath from "remark-math";
import rehypeKatex from "rehype-katex";

// src/components/HtmlMathRenderer/utils.ts
var generateSecureRandomId = () => {
  return crypto.randomUUID();
};
var cleanLatex = (str) => {
  return str.replaceAll(/[\u200B-\u200D\uFEFF]/g, "").replaceAll(/&amp;lt;|&lt;/gi, String.raw`\lt `).replaceAll(/&amp;gt;|&gt;/gi, String.raw`\gt `).replaceAll(/&amp;amp;|&amp;/gi, "&").trim();
};
var looksLikeLatex = (str) => {
  if (/[\\^_{}]/.test(str)) return true;
  const words = str.match(/[a-zA-Z]{3,}/g);
  if (words && words.length >= 2) return false;
  return true;
};
var HTML_TAG_NAMES = /* @__PURE__ */ new Set([
  "p",
  "div",
  "span",
  "br",
  "b",
  "strong",
  "i",
  "em",
  "u",
  "s",
  "ul",
  "ol",
  "li",
  "h1",
  "h2",
  "h3",
  "h4",
  "h5",
  "h6",
  "a",
  "img",
  "table",
  "thead",
  "tbody",
  "tfoot",
  "tr",
  "td",
  "th",
  "blockquote",
  "pre",
  "code",
  "sub",
  "sup",
  "font",
  "latex"
]);
var containsHtmlTag = (content) => {
  for (const match of content.matchAll(/<\/?([a-z][a-z0-9]*)/gi)) {
    if (HTML_TAG_NAMES.has(match[1].toLowerCase())) return true;
  }
  return false;
};
var isLikelyMarkdown = (content) => {
  if (!content) return false;
  if (containsHtmlTag(content)) return false;
  const MARKDOWN_SIGNALS = [
    /^#{1,6}[ \t]+\S/m,
    // ATX heading (#, ##, ... ######)
    /\*\*[^*\n]+\*\*/,
    // bold
    /__[^_\n]+__/,
    // bold (underscore)
    /^[ \t]*[-*+][ \t]+\S/m,
    // bullet list
    /^[ \t]*\d+\.[ \t]+\S/m,
    // ordered list
    /\|[ \t]*:?-+:?[ \t]*\|/,
    // GFM table delimiter row (|---|---|)
    /\n\n/
    // paragraph break (only reached when no HTML tag is present)
  ];
  return MARKDOWN_SIGNALS.some((pattern) => pattern.test(content));
};
var recoverFromKatexErrorSpans = (htmlContent) => {
  if (typeof document === "undefined" || !/class="[^"]*katex-error/i.test(htmlContent)) {
    return htmlContent;
  }
  const tempContainer = document.createElement("div");
  tempContainer.innerHTML = htmlContent;
  const sanitizeRecoveredLatex = (raw) => raw.replaceAll(/[\u0300-\u036F]/g, "").replaceAll(/<\/?[a-zA-Z][a-zA-Z0-9]*\s*>?$/g, "").replaceAll(/&amp;lt;|&lt;|</gi, String.raw`\lt `).replaceAll(/&amp;gt;|&gt;|>/gi, String.raw`\gt `).replaceAll(/&amp;amp;|&amp;/gi, "&").trim();
  Array.from(tempContainer.querySelectorAll(".katex-error")).forEach(
    (errorNode) => {
      if (!tempContainer.contains(errorNode)) return;
      const title = errorNode.getAttribute("title") || "";
      const positionMatch = /at position\s+\d+:(.+)$/.exec(title);
      let recovered = positionMatch ? positionMatch[1] : "";
      if (!recovered) {
        const parts = [];
        const walk = (n) => {
          if (n.nodeType === Node.TEXT_NODE) {
            parts.push(n.textContent || "");
            return;
          }
          if (n.nodeType !== Node.ELEMENT_NODE) return;
          const el = n;
          if (el.tagName.toLowerCase() === "annotation") {
            parts.push(el.textContent || "");
            return;
          }
          if (el.classList.contains("katex-html")) return;
          Array.from(el.childNodes).forEach(walk);
        };
        Array.from(errorNode.childNodes).forEach(walk);
        recovered = parts.join(" ");
      }
      recovered = sanitizeRecoveredLatex(recovered);
      if (recovered) {
        errorNode.replaceWith(document.createTextNode(`$${recovered}$`));
      } else {
        errorNode.remove();
      }
    }
  );
  return tempContainer.innerHTML;
};
var decodeDollarEscapes = (text) => text.replaceAll(String.raw`\$`, "$");
var DANGEROUS_ATTRIBUTES = /* @__PURE__ */ new Set([
  "contenteditable",
  "srcdoc",
  "formaction",
  "xlink:href"
]);
var DANGEROUS_URI_PATTERN = /^\s*(javascript|vbscript|data):/i;
var sanitizeHtmlForDisplay = (htmlContent) => {
  if (!htmlContent) return htmlContent;
  if (typeof document === "undefined") {
    let sanitized = htmlContent;
    sanitized = sanitized.replaceAll(
      /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
      ""
    );
    sanitized = sanitized.replaceAll(
      /<style\b[^<]*(?:(?!<\/style>)<[^<]*)*<\/style>/gi,
      ""
    );
    sanitized = sanitized.replaceAll(/ on[a-z]+="[^"]*"/gi, "");
    sanitized = sanitized.replaceAll(/ on[a-z]+='[^']*'/gi, "");
    sanitized = sanitized.replaceAll(/ on[a-z]+=[^\s>"']+/gi, "");
    sanitized = sanitized.replaceAll(
      / href="(?:javascript|vbscript|data):[^"]*"/gi,
      ""
    );
    sanitized = sanitized.replaceAll(
      / href='(?:javascript|vbscript|data):[^']*'/gi,
      ""
    );
    sanitized = sanitized.replaceAll(
      / src="(?:javascript|vbscript|data):[^"]*"/gi,
      ""
    );
    sanitized = sanitized.replaceAll(
      / src='(?:javascript|vbscript|data):[^']*'/gi,
      ""
    );
    sanitized = sanitized.replaceAll(
      / action="(?:javascript|vbscript|data):[^"]*"/gi,
      ""
    );
    sanitized = sanitized.replaceAll(
      / action='(?:javascript|vbscript|data):[^']*'/gi,
      ""
    );
    return sanitized;
  }
  const tempDiv = document.createElement("div");
  tempDiv.innerHTML = htmlContent;
  const dangerousTags = tempDiv.querySelectorAll(
    "script, style, iframe, object, embed"
  );
  dangerousTags.forEach((element) => element.remove());
  const allElements = tempDiv.querySelectorAll("*");
  allElements.forEach((element) => {
    const attributeNames = element.getAttributeNames();
    attributeNames.forEach((attrName) => {
      const lowerAttrName = attrName.toLowerCase();
      if (lowerAttrName.startsWith("on")) {
        element.removeAttribute(attrName);
        return;
      }
      if (DANGEROUS_ATTRIBUTES.has(lowerAttrName)) {
        element.removeAttribute(attrName);
        return;
      }
      if (lowerAttrName === "href" || lowerAttrName === "src" || lowerAttrName === "action") {
        const value = element.getAttribute(attrName);
        if (value && DANGEROUS_URI_PATTERN.test(value)) {
          element.removeAttribute(attrName);
        }
      }
    });
  });
  return tempDiv.innerHTML;
};
var processHtmlWithMath = (htmlContent) => {
  if (!htmlContent) return [];
  let processedContent = recoverFromKatexErrorSpans(htmlContent);
  const parts = [];
  const sentinel = `__MATH_${generateSecureRandomId()}_`;
  const mathFormulaPattern = /<span[^>]*class="math-formula"[^>]*data-latex="([^"]*)"[^>]*>[\s\S]*?<\/span>/g;
  processedContent = processedContent.replaceAll(
    mathFormulaPattern,
    (match2, latex) => {
      const isDisplayMode = match2.includes('data-display-mode="true"');
      const placeholder = `${sentinel}${parts.length}__`;
      parts.push({
        type: isDisplayMode ? "block-math" : "math",
        content: match2,
        latex: cleanLatex(latex)
      });
      return placeholder;
    }
  );
  const wrappedMathPattern = /<span[^>]*class="math-expression"[^>]*data-math="([^"]*)"[^>]*>.*?<\/span>/g;
  processedContent = processedContent.replaceAll(
    wrappedMathPattern,
    (match2, latex) => {
      const placeholder = `${sentinel}${parts.length}__`;
      parts.push({
        type: "math",
        content: match2,
        latex: cleanLatex(latex)
      });
      return placeholder;
    }
  );
  const doubleDollarPattern = /(?<!\\)\$\$([\s\S]+?)\$\$/g;
  processedContent = processedContent.replaceAll(
    doubleDollarPattern,
    (match2, latex) => {
      const placeholder = `${sentinel}${parts.length}__`;
      parts.push({
        type: "block-math",
        content: match2,
        latex: cleanLatex(latex)
      });
      return placeholder;
    }
  );
  const singleDollarPattern = /(?<!\\)\$([\s\S]+?)\$/g;
  processedContent = processedContent.replaceAll(
    singleDollarPattern,
    (match2, latex) => {
      if (!looksLikeLatex(latex)) return match2;
      const placeholder = `${sentinel}${parts.length}__`;
      parts.push({
        type: "math",
        content: match2,
        latex: cleanLatex(latex)
      });
      return placeholder;
    }
  );
  const latexTagPattern = /(?:<latex>|&lt;latex&gt;)([\s\S]*?)(?:<\/latex>|&lt;\/latex&gt;)/g;
  processedContent = processedContent.replaceAll(
    latexTagPattern,
    (match2, latex) => {
      const placeholder = `${sentinel}${parts.length}__`;
      parts.push({
        type: "math",
        content: match2,
        latex: cleanLatex(latex)
      });
      return placeholder;
    }
  );
  const latexEnvPattern = /\\begin\{([^}]+)\}([\s\S]*?)\\end\{\1\}/g;
  processedContent = processedContent.replaceAll(latexEnvPattern, (match2) => {
    const placeholder = `${sentinel}${parts.length}__`;
    parts.push({
      type: "block-math",
      content: match2,
      latex: cleanLatex(match2)
    });
    return placeholder;
  });
  const finalParts = [];
  let currentIndex = 0;
  const escapedSentinel = sentinel.replaceAll(
    /[.*+?^${}()|[\]\\]/g,
    String.raw`\$&`
  );
  const placeholderPattern = new RegExp(
    String.raw`${escapedSentinel}(\d+)__`,
    "g"
  );
  let match;
  while ((match = placeholderPattern.exec(processedContent)) !== null) {
    if (match.index > currentIndex) {
      finalParts.push({
        type: "text",
        content: decodeDollarEscapes(
          processedContent.slice(currentIndex, match.index)
        )
      });
    }
    const mathIndex = Number.parseInt(match[1], 10);
    if (parts[mathIndex]) {
      finalParts.push(parts[mathIndex]);
    }
    currentIndex = match.index + match[0].length;
  }
  if (currentIndex < processedContent.length) {
    finalParts.push({
      type: "text",
      content: decodeDollarEscapes(processedContent.slice(currentIndex))
    });
  }
  return finalParts;
};

// src/components/MarkdownMathRenderer/MarkdownMathRenderer.tsx
import { jsx as jsx5 } from "react/jsx-runtime";
var stripInvisibleChars = (str) => str.replaceAll(/[\u200B-\u200D\uFEFF]/g, "");
var protectCurrencyInlineMath = (markdown) => markdown.replaceAll(
  /(?<!\\)\$(?!\$)([^\n$]+?)(?<!\\)\$(?!\$)/g,
  (match, inner) => looksLikeLatex(inner) ? match : match.replaceAll("$", String.raw`\$`)
);
var reflowDisplayMath = (markdown) => markdown.replaceAll(
  /(?<!\$)\$\$(?!\$)([^\n]+?)\$\$(?!\$)/g,
  (_match, inner) => `

$$
${inner.trim()}
$$

`
);
var withProtectedCode = (markdown, transform) => {
  const stash = [];
  const tokenized = markdown.replaceAll(
    /```[\s\S]*?```|`[^`\n]*`/g,
    (segment) => {
      const token = `__CODE_SEG_${stash.length}__`;
      stash.push(segment);
      return token;
    }
  );
  return transform(tokenized).replaceAll(
    /__CODE_SEG_(\d+)__/g,
    (_match, index) => stash[Number(index)]
  );
};
var preprocessMarkdown = (content) => withProtectedCode(
  stripInvisibleChars(content),
  (safe) => reflowDisplayMath(protectCurrencyInlineMath(safe))
);
var MarkdownMathRenderer = forwardRef2(({ content, className, style, testId }, ref) => {
  const sharedClassName = cn(
    "leading-relaxed",
    // Paragraph spacing
    "[&_p]:my-2 [&_p:first-child]:mt-0 [&_p:last-child]:mb-0",
    // Headings
    "[&_h1]:text-xl [&_h1]:font-bold [&_h1]:mt-3 [&_h1]:mb-2",
    "[&_h2]:text-lg [&_h2]:font-bold [&_h2]:mt-3 [&_h2]:mb-2",
    "[&_h3]:text-base [&_h3]:font-semibold [&_h3]:mt-2.5 [&_h3]:mb-1.5",
    "[&_h4]:text-base [&_h4]:font-semibold [&_h4]:mt-2.5 [&_h4]:mb-1.5",
    "[&_h5]:font-semibold [&_h6]:font-semibold",
    // Lists
    "[&_ul]:list-disc [&_ul]:pl-5 [&_ul]:my-2",
    "[&_ol]:list-decimal [&_ol]:pl-5 [&_ol]:my-2",
    "[&_li]:my-1 [&_li>ul]:my-1 [&_li>ol]:my-1",
    // Text formatting
    "[&_b]:font-bold [&_strong]:font-bold",
    "[&_i]:italic [&_em]:italic",
    "[&_u]:underline",
    "[&_blockquote]:border-l-4 [&_blockquote]:border-border-200 [&_blockquote]:pl-3 [&_blockquote]:text-text-700",
    "[&_code]:rounded [&_code]:bg-background-100 [&_code]:px-1 [&_code]:py-0.5 [&_code]:text-sm",
    // Hide the KaTeX MathML accessibility layer visually (still readable to
    // screen readers). Tailwind preflight overrides KaTeX's default clip
    // rule, so without this the MathML layer duplicates every formula as
    // raw text next to the visual render.
    "[&_.katex-mathml]:sr-only",
    // Display math spacing
    "[&_.katex-display]:my-2.5",
    // Tables (GFM)
    "[&_table]:border-collapse [&_table]:w-full [&_table]:my-2.5 [&_table]:table-auto",
    "[&_table_td]:border [&_table_td]:border-border-200 [&_table_td]:p-2 [&_table_td]:min-w-[50px] [&_table_td]:align-top",
    "[&_table_th]:border [&_table_th]:border-border-200 [&_table_th]:p-2 [&_table_th]:min-w-[50px] [&_table_th]:align-top [&_table_th]:bg-background-50 [&_table_th]:font-semibold",
    // Images and links
    "[&_img]:max-w-full [&_img]:h-auto [&_img]:rounded-md [&_img]:my-2",
    "[&_a]:text-primary-500 [&_a]:underline [&_a:hover]:text-primary-600",
    className
  );
  return /* @__PURE__ */ jsx5(
    "div",
    {
      ref,
      className: sharedClassName,
      style,
      "data-testid": testId,
      children: /* @__PURE__ */ jsx5(
        ReactMarkdown,
        {
          remarkPlugins: [remarkGfm, remarkMath],
          rehypePlugins: [rehypeKatex],
          children: preprocessMarkdown(content)
        }
      )
    }
  );
});
MarkdownMathRenderer.displayName = "MarkdownMathRenderer";
var MarkdownMathRenderer_default = memo(MarkdownMathRenderer);

// src/components/HtmlMathRenderer/HtmlMathRenderer.tsx
import { Fragment as Fragment2, jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
var HtmlMathRenderer = forwardRef3(
  ({
    content,
    className,
    style,
    sanitize = true,
    renderMathError,
    testId,
    inline = false
  }, ref) => {
    if (!inline && content && isLikelyMarkdown(content)) {
      return /* @__PURE__ */ jsx6(
        MarkdownMathRenderer_default,
        {
          ref,
          content,
          className,
          style,
          testId
        }
      );
    }
    const defaultErrorRenderer = (latex) => /* @__PURE__ */ jsxs3("span", { className: "text-error-600 text-sm", children: [
      "Math Error: ",
      latex
    ] });
    const errorRenderer = renderMathError || defaultErrorRenderer;
    const renderContent = () => {
      if (!content) return null;
      const processedContent = sanitize ? sanitizeHtmlForDisplay(content) : content;
      const parts = processHtmlWithMath(processedContent);
      if (parts.every((part) => part.type === "text")) {
        const joinedHtml = parts.map((part) => part.content).join("");
        const Element = inline ? "span" : "div";
        return /* @__PURE__ */ jsx6(
          Element,
          {
            dangerouslySetInnerHTML: {
              __html: joinedHtml || processedContent
            }
          }
        );
      }
      const getPartKey = (part, idx) => {
        const contentHash = (part.latex || part.content).slice(0, 20);
        return `${part.type}-${idx}-${contentHash}`;
      };
      return /* @__PURE__ */ jsx6(Fragment2, { children: parts.map((part, index) => {
        const key = getPartKey(part, index);
        if (part.type === "math" && part.latex) {
          return /* @__PURE__ */ jsx6(
            KatexMath,
            {
              math: part.latex,
              renderError: () => errorRenderer(part.latex)
            },
            key
          );
        } else if (part.type === "block-math" && part.latex) {
          if (inline) {
            return /* @__PURE__ */ jsx6(
              KatexMath,
              {
                math: part.latex,
                renderError: () => errorRenderer(part.latex)
              },
              key
            );
          }
          return /* @__PURE__ */ jsx6("div", { className: "my-2.5 text-center", children: /* @__PURE__ */ jsx6(
            KatexMath,
            {
              math: part.latex,
              displayMode: true,
              renderError: () => errorRenderer(part.latex)
            }
          ) }, key);
        } else {
          return /* @__PURE__ */ jsx6(
            "span",
            {
              dangerouslySetInnerHTML: { __html: part.content }
            },
            key
          );
        }
      }) });
    };
    const sharedClassName = cn(
      // Base styles
      "leading-relaxed",
      // Paragraph styles
      "[&_p]:mb-0",
      // Hide the KaTeX MathML accessibility layer visually (still readable
      // to screen readers). Tailwind preflight overrides the KaTeX default
      // `position: absolute; clip:...` rule, so the MathML layer ends up
      // duplicating every formula as raw text next to the visual render.
      "[&_.katex-mathml]:sr-only",
      // Table styles (only relevant for block mode, but harmless for inline)
      "[&_table]:border-collapse [&_table]:w-full [&_table]:my-2.5 [&_table]:table-auto",
      "[&_table_td]:border [&_table_td]:border-border-200 [&_table_td]:p-2 [&_table_td]:min-w-[50px] [&_table_td]:align-top",
      "[&_table_th]:border [&_table_th]:border-border-200 [&_table_th]:p-2 [&_table_th]:min-w-[50px] [&_table_th]:align-top [&_table_th]:bg-background-50 [&_table_th]:font-semibold",
      "[&_table_tr:nth-child(even)]:bg-background-50/50",
      "[&_table_tr:hover]:bg-background-100/50",
      // Image styles
      "[&_img]:max-w-full [&_img]:h-auto [&_img]:rounded-md [&_img]:my-2",
      // Link styles
      "[&_a]:text-primary-500 [&_a]:underline [&_a:hover]:text-primary-600",
      // Text formatting styles
      "[&_b]:font-bold [&_strong]:font-bold",
      "[&_i]:italic [&_em]:italic",
      "[&_u]:underline",
      className
    );
    if (inline) {
      return /* @__PURE__ */ jsx6(
        "span",
        {
          ref,
          className: sharedClassName,
          style,
          "data-testid": testId,
          children: renderContent()
        }
      );
    }
    return /* @__PURE__ */ jsx6(
      "div",
      {
        ref,
        className: sharedClassName,
        style,
        "data-testid": testId,
        children: renderContent()
      }
    );
  }
);
HtmlMathRenderer.displayName = "HtmlMathRenderer";
var HtmlMathRenderer_default = memo2(HtmlMathRenderer);

// src/components/Alternative/Alternative.tsx
import { jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
var AlternativesList = ({
  alternatives,
  name,
  defaultValue,
  value,
  onValueChange,
  disabled = false,
  layout = "default",
  className = "",
  mode = "interactive" /* INTERACTIVE */,
  selectedValue
}) => {
  const uniqueId = useId2();
  const groupName = name || `alternatives-${uniqueId}`;
  const [actualValue, setActualValue] = useState2(value);
  const isReadonly = mode === "readonly";
  const getStatusStyles = (status, isReadonly2) => {
    const hoverClass = isReadonly2 ? "" : "hover:bg-background-50";
    switch (status) {
      case "correct" /* CORRECT */:
        return "bg-success-background border-success-300";
      case "incorrect" /* INCORRECT */:
        return "bg-error-background border-error-300";
      default:
        return `bg-background border-border-100 ${hoverClass}`;
    }
  };
  const getStatusBadge = (status) => {
    switch (status) {
      case "correct" /* CORRECT */:
        return /* @__PURE__ */ jsx7(Badge_default, { variant: "solid", action: "success", iconLeft: /* @__PURE__ */ jsx7(CheckCircle, {}), children: "Resposta correta" });
      case "incorrect" /* INCORRECT */:
        return /* @__PURE__ */ jsx7(Badge_default, { variant: "solid", action: "error", iconLeft: /* @__PURE__ */ jsx7(XCircle, {}), children: "Resposta incorreta" });
      default:
        return null;
    }
  };
  const getLayoutClasses = () => {
    switch (layout) {
      case "compact":
        return "gap-2";
      case "detailed":
        return "gap-4";
      default:
        return "gap-3.5";
    }
  };
  const renderReadonlyAlternative = (alternative) => {
    const alternativeId = alternative.value;
    const isUserSelected = selectedValue === alternative.value;
    const isCorrectAnswer = alternative.status === "correct" /* CORRECT */;
    let displayStatus = void 0;
    if (isUserSelected && !isCorrectAnswer) {
      displayStatus = "incorrect" /* INCORRECT */;
    } else if (isCorrectAnswer) {
      displayStatus = "correct" /* CORRECT */;
    }
    const statusStyles = getStatusStyles(displayStatus, true);
    const statusBadge = getStatusBadge(displayStatus);
    const renderRadio = () => {
      const radioClasses = `w-6 h-6 rounded-full border-2 cursor-default transition-all duration-200 flex items-center justify-center ${isUserSelected ? "border-primary-950 bg-background" : "border-border-400 bg-background"}`;
      const dotClasses = "w-3 h-3 rounded-full bg-primary-950 transition-all duration-200";
      return /* @__PURE__ */ jsx7("div", { className: radioClasses, children: isUserSelected && /* @__PURE__ */ jsx7("div", { className: dotClasses }) });
    };
    if (layout === "detailed") {
      return /* @__PURE__ */ jsx7(
        "div",
        {
          className: cn(
            "border-2 rounded-lg p-4 w-full",
            statusStyles,
            alternative.disabled ? "opacity-50" : ""
          ),
          children: /* @__PURE__ */ jsxs4("div", { className: "flex items-start justify-between gap-3", children: [
            /* @__PURE__ */ jsxs4("div", { className: "flex items-start gap-3 flex-1", children: [
              /* @__PURE__ */ jsx7("div", { className: "mt-1", children: renderRadio() }),
              /* @__PURE__ */ jsxs4("div", { className: "flex-1", children: [
                /* @__PURE__ */ jsx7(
                  HtmlMathRenderer_default,
                  {
                    content: alternative.label,
                    className: cn(
                      "block font-medium",
                      selectedValue === alternative.value || statusBadge ? "text-text-950" : "text-text-600"
                    )
                  }
                ),
                alternative.description && /* @__PURE__ */ jsx7("p", { className: "text-sm text-text-600 mt-1", children: alternative.description })
              ] })
            ] }),
            statusBadge && /* @__PURE__ */ jsx7("div", { className: "flex-shrink-0", children: statusBadge })
          ] })
        },
        alternativeId
      );
    }
    return /* @__PURE__ */ jsxs4(
      "div",
      {
        className: cn(
          "flex flex-row justify-between items-start gap-2 p-2 rounded-lg w-full",
          statusStyles,
          alternative.disabled ? "opacity-50" : ""
        ),
        children: [
          /* @__PURE__ */ jsxs4("div", { className: "flex items-center gap-2 flex-1", children: [
            renderRadio(),
            /* @__PURE__ */ jsx7(
              HtmlMathRenderer_default,
              {
                content: alternative.label,
                className: cn(
                  "flex-1",
                  selectedValue === alternative.value || statusBadge ? "text-text-950" : "text-text-600"
                )
              }
            )
          ] }),
          statusBadge && /* @__PURE__ */ jsx7("div", { className: "flex-shrink-0", children: statusBadge })
        ]
      },
      alternativeId
    );
  };
  if (isReadonly) {
    return /* @__PURE__ */ jsx7(
      "div",
      {
        className: cn("flex flex-col", getLayoutClasses(), "w-full", className),
        children: alternatives.map(
          (alternative) => renderReadonlyAlternative(alternative)
        )
      }
    );
  }
  return /* @__PURE__ */ jsx7(
    RadioGroup,
    {
      name: groupName,
      defaultValue,
      value,
      onValueChange: (value2) => {
        setActualValue(value2);
        onValueChange?.(value2);
      },
      disabled,
      className: cn("flex flex-col", getLayoutClasses(), className),
      children: alternatives.map((alternative, index) => {
        const alternativeId = alternative.value || `alt-${index}`;
        const statusStyles = getStatusStyles(alternative.status, false);
        const statusBadge = getStatusBadge(alternative.status);
        if (layout === "detailed") {
          return /* @__PURE__ */ jsx7(
            "div",
            {
              className: cn(
                "border-2 rounded-lg p-4 transition-all",
                statusStyles,
                alternative.disabled ? "opacity-50 cursor-not-allowed" : "cursor-pointer"
              ),
              children: /* @__PURE__ */ jsxs4("div", { className: "flex items-start justify-between gap-3", children: [
                /* @__PURE__ */ jsxs4("div", { className: "flex items-start gap-3 flex-1", children: [
                  /* @__PURE__ */ jsx7(
                    RadioGroupItem,
                    {
                      value: alternative.value,
                      id: alternativeId,
                      disabled: alternative.disabled,
                      className: "mt-1"
                    }
                  ),
                  /* @__PURE__ */ jsxs4("div", { className: "flex-1", children: [
                    /* @__PURE__ */ jsx7(
                      "label",
                      {
                        htmlFor: alternativeId,
                        className: cn(
                          "block font-medium",
                          actualValue === alternative.value ? "text-text-950" : "text-text-600",
                          alternative.disabled ? "cursor-not-allowed" : "cursor-pointer"
                        ),
                        children: /* @__PURE__ */ jsx7(HtmlMathRenderer_default, { content: alternative.label, inline: true })
                      }
                    ),
                    alternative.description && /* @__PURE__ */ jsx7("p", { className: "text-sm text-text-600 mt-1", children: alternative.description })
                  ] })
                ] }),
                statusBadge && /* @__PURE__ */ jsx7("div", { className: "flex-shrink-0", children: statusBadge })
              ] })
            },
            alternativeId
          );
        }
        return /* @__PURE__ */ jsxs4(
          "div",
          {
            className: cn(
              "flex flex-row justify-between gap-2 items-start p-2 rounded-lg transition-all",
              statusStyles,
              alternative.disabled ? "opacity-50 cursor-not-allowed" : ""
            ),
            children: [
              /* @__PURE__ */ jsxs4("div", { className: "flex items-center gap-2 flex-1", children: [
                /* @__PURE__ */ jsx7(
                  RadioGroupItem,
                  {
                    value: alternative.value,
                    id: alternativeId,
                    disabled: alternative.disabled
                  }
                ),
                /* @__PURE__ */ jsx7(
                  "label",
                  {
                    htmlFor: alternativeId,
                    className: cn(
                      "flex-1",
                      actualValue === alternative.value ? "text-text-950" : "text-text-600",
                      alternative.disabled ? "cursor-not-allowed" : "cursor-pointer"
                    ),
                    children: /* @__PURE__ */ jsx7(HtmlMathRenderer_default, { content: alternative.label, inline: true })
                  }
                )
              ] }),
              statusBadge && /* @__PURE__ */ jsx7("div", { className: "flex-shrink-0", children: statusBadge })
            ]
          },
          alternativeId
        );
      })
    }
  );
};
var HeaderAlternative = forwardRef4(
  ({ className, title, subTitle, content, ...props }, ref) => {
    return /* @__PURE__ */ jsxs4(
      "div",
      {
        ref,
        className: cn(
          "bg-background p-4 flex flex-col gap-4 rounded-xl",
          className
        ),
        ...props,
        children: [
          /* @__PURE__ */ jsxs4("span", { className: "flex flex-col", children: [
            /* @__PURE__ */ jsx7("p", { className: "text-text-950 font-bold text-lg", children: title }),
            /* @__PURE__ */ jsx7("p", { className: "text-text-700 text-sm ", children: subTitle })
          ] }),
          /* @__PURE__ */ jsx7(HtmlMathRenderer_default, { content, className: "text-text-950 text-md" })
        ]
      }
    );
  }
);
export {
  AlternativesList,
  HeaderAlternative
};
//# sourceMappingURL=index.mjs.map