import { jsx, jsxs } from 'react/jsx-runtime';
import { forwardRef, useRef, useState, useEffect } from 'react';
import { c as cx } from './index-SvGbrGuT.js';
import { u as useMergeRefs } from './useMergeRefs-Dfmtq9cI.js';

import './Spinner.css';const Spinner$1 = "_Spinner_u69oo_2";
const Inherit = "_Inherit_u69oo_26";
const Track = "_Track_u69oo_38";
const Arc = "_Arc_u69oo_41";
const styles = {
	Spinner: Spinner$1,
	Inherit: Inherit,
	"size-small": "_size-small_u69oo_29",
	"size-medium": "_size-medium_u69oo_32",
	"size-large": "_size-large_u69oo_35",
	Track: Track,
	Arc: Arc
};

const Spinner = forwardRef(
  (props, ref) => {
    const { className, inherit, size = "medium", ...rest } = props;
    const containerRef = useRef(null);
    const [containerWidth, setContainerWidth] = useState(0);
    const mergedRef = useMergeRefs([containerRef, ref]);
    useEffect(() => {
      let rafId;
      let lastWidth = 0;
      const updateWidth = () => {
        if (containerRef.current) {
          const width = containerRef.current.offsetWidth;
          if (width !== lastWidth) {
            setContainerWidth(width);
            lastWidth = width;
          }
        }
      };
      const continuousUpdate = () => {
        updateWidth();
        rafId = requestAnimationFrame(continuousUpdate);
      };
      updateWidth();
      const resizeObserver = new ResizeObserver(updateWidth);
      if (containerRef.current) {
        resizeObserver.observe(containerRef.current);
      }
      rafId = requestAnimationFrame(continuousUpdate);
      return () => {
        resizeObserver.disconnect();
        cancelAnimationFrame(rafId);
      };
    }, []);
    const classNames = cx(styles["Spinner"], className, {
      [styles["Inherit"]]: inherit,
      [styles["size-small"]]: size === "small",
      [styles["size-medium"]]: size === "medium",
      [styles["size-large"]]: size === "large"
    });
    const strokeWidth = containerWidth > 0 ? Math.sqrt((containerWidth - 8) / 2) : 2;
    const radius = 10;
    return /* @__PURE__ */ jsx(
      "span",
      {
        "data-anv": "spinner",
        className: classNames,
        ref: mergedRef,
        role: "status",
        ...rest,
        children: /* @__PURE__ */ jsxs(
          "svg",
          {
            className: styles["Svg"],
            width: "100%",
            height: "100%",
            viewBox: "0 0 24 24",
            "aria-hidden": "true",
            focusable: "false",
            children: [
              /* @__PURE__ */ jsx(
                "circle",
                {
                  className: styles["Track"],
                  cx: "12",
                  cy: "12",
                  r: radius,
                  fill: "none",
                  strokeWidth,
                  vectorEffect: "non-scaling-stroke",
                  stroke: "currentColor",
                  shapeRendering: "geometricPrecision"
                }
              ),
              /* @__PURE__ */ jsx(
                "path",
                {
                  className: styles["Arc"],
                  d: `M${12 + radius} 12a${radius} ${radius} 0 1 0-${radius * 2} 0`,
                  fill: "none",
                  strokeWidth,
                  strokeLinecap: "round",
                  vectorEffect: "non-scaling-stroke",
                  stroke: "currentColor",
                  shapeRendering: "geometricPrecision",
                  children: /* @__PURE__ */ jsx(
                    "animateTransform",
                    {
                      attributeName: "transform",
                      type: "rotate",
                      from: "0 12 12",
                      to: "360 12 12",
                      dur: "1s",
                      repeatCount: "indefinite"
                    }
                  )
                }
              )
            ]
          }
        )
      }
    );
  }
);
Spinner.displayName = "Spinner";

export { Spinner as S };
//# sourceMappingURL=Spinner-CpEm3Lud.js.map
