'use strict';

var chunkOLISEQHS_cjs = require('./chunk-OLISEQHS.cjs');
var react = require('react');

var animationCache = /* @__PURE__ */ new Map();
function useLottie(options) {
  const { src, cache = true } = options;
  const [animationData, setAnimationData] = react.useState(null);
  const [isLoading, setIsLoading] = react.useState(false);
  const [error, setError] = react.useState(null);
  const [retryCount, setRetryCount] = react.useState(0);
  const isMountedRef = react.useRef(true);
  react.useEffect(() => {
    isMountedRef.current = true;
    return () => {
      isMountedRef.current = false;
    };
  }, []);
  react.useEffect(() => {
    if (typeof src === "object" && src !== null) {
      setAnimationData(src);
      setIsLoading(false);
      setError(null);
      return;
    }
    if (typeof src === "string") {
      const loadAnimation = /* @__PURE__ */ chunkOLISEQHS_cjs.__name(async () => {
        if (cache && animationCache.has(src)) {
          if (isMountedRef.current) {
            setAnimationData(animationCache.get(src));
            setIsLoading(false);
            setError(null);
          }
          return;
        }
        if (isMountedRef.current) {
          setIsLoading(true);
          setError(null);
        }
        try {
          const response = await fetch(src);
          if (!response.ok) {
            throw new Error(`Failed to load animation: ${response.status} ${response.statusText}`);
          }
          const data = await response.json();
          if (!data || typeof data !== "object" || !data.v || !data.layers) {
            throw new Error("Invalid Lottie animation data");
          }
          if (cache) {
            animationCache.set(src, data);
          }
          if (isMountedRef.current) {
            setAnimationData(data);
            setIsLoading(false);
          }
        } catch (err) {
          if (isMountedRef.current) {
            setError(err instanceof Error ? err : new Error("Failed to load animation"));
            setIsLoading(false);
          }
        }
      }, "loadAnimation");
      loadAnimation();
    }
  }, [src, cache, retryCount]);
  const retry = /* @__PURE__ */ chunkOLISEQHS_cjs.__name(() => {
    setRetryCount((prev) => prev + 1);
  }, "retry");
  return {
    animationData,
    isLoading,
    error,
    retry
  };
}
chunkOLISEQHS_cjs.__name(useLottie, "useLottie");

exports.useLottie = useLottie;
//# sourceMappingURL=chunk-QJ6GTUCO.cjs.map
//# sourceMappingURL=chunk-QJ6GTUCO.cjs.map