'use strict';

var chunkQJ6GTUCO_cjs = require('./chunk-QJ6GTUCO.cjs');
var chunkOLISEQHS_cjs = require('./chunk-OLISEQHS.cjs');
var React = require('react');
var Lottie = require('react-lottie-player');
var jsxRuntime = require('react/jsx-runtime');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var React__default = /*#__PURE__*/_interopDefault(React);
var Lottie__default = /*#__PURE__*/_interopDefault(Lottie);

var SIZE_PRESETS = {
  xs: { width: 64, height: 64 },
  sm: { width: 128, height: 128 },
  md: { width: 256, height: 256 },
  lg: { width: 384, height: 384 },
  xl: { width: 512, height: 512 },
  full: { width: "100%", height: "100%" }
};
function LottiePlayer({
  src,
  size = "md",
  width,
  height,
  autoplay = true,
  loop = true,
  speed = 1,
  direction = 1,
  controls = false,
  background,
  className,
  showLoading = true,
  onComplete,
  onLoad,
  onError
}) {
  const { animationData, isLoading, error, retry } = chunkQJ6GTUCO_cjs.useLottie({ src });
  React__default.default.useEffect(() => {
    if (animationData && onLoad) {
      onLoad();
    }
  }, [animationData, onLoad]);
  React__default.default.useEffect(() => {
    if (error && onError) {
      onError(error);
    }
  }, [error, onError]);
  const dimensions = React__default.default.useMemo(() => {
    if (width !== void 0 || height !== void 0) {
      return {
        width: width ?? SIZE_PRESETS[size].width,
        height: height ?? SIZE_PRESETS[size].height
      };
    }
    return SIZE_PRESETS[size];
  }, [size, width, height]);
  const handleComplete = React__default.default.useCallback(() => {
    if (onComplete) {
      onComplete();
    }
  }, [onComplete]);
  if (isLoading && showLoading) {
    return /* @__PURE__ */ jsxRuntime.jsx(
      "div",
      {
        className: `flex items-center justify-center ${className || ""}`,
        style: {
          width: dimensions.width,
          height: dimensions.height,
          background: background || "transparent"
        },
        children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-center gap-2", children: [
          /* @__PURE__ */ jsxRuntime.jsx("div", { className: "h-8 w-8 animate-spin rounded-full border-4 border-gray-300 border-t-gray-900" }),
          /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-gray-500", children: "Loading animation..." })
        ] })
      }
    );
  }
  if (error) {
    return /* @__PURE__ */ jsxRuntime.jsx(
      "div",
      {
        className: `flex items-center justify-center ${className || ""}`,
        style: {
          width: dimensions.width,
          height: dimensions.height,
          background: background || "transparent"
        },
        children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-center gap-2 p-4 text-center", children: [
          /* @__PURE__ */ jsxRuntime.jsx(
            "svg",
            {
              className: "h-8 w-8 text-red-500",
              fill: "none",
              stroke: "currentColor",
              viewBox: "0 0 24 24",
              children: /* @__PURE__ */ jsxRuntime.jsx(
                "path",
                {
                  strokeLinecap: "round",
                  strokeLinejoin: "round",
                  strokeWidth: 2,
                  d: "M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
                }
              )
            }
          ),
          /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-sm text-red-600", children: error.message }),
          /* @__PURE__ */ jsxRuntime.jsx(
            "button",
            {
              onClick: retry,
              className: "rounded bg-red-100 px-3 py-1 text-sm text-red-700 hover:bg-red-200",
              children: "Retry"
            }
          )
        ] })
      }
    );
  }
  if (!animationData) {
    return null;
  }
  return /* @__PURE__ */ jsxRuntime.jsxs(
    "div",
    {
      className,
      style: {
        width: dimensions.width,
        height: dimensions.height,
        background: background || "transparent"
      },
      children: [
        /* @__PURE__ */ jsxRuntime.jsx(
          Lottie__default.default,
          {
            animationData,
            play: autoplay,
            loop,
            speed,
            direction,
            style: {
              width: "100%",
              height: "100%"
            },
            onComplete: handleComplete,
            rendererSettings: {
              preserveAspectRatio: "xMidYMid meet"
            }
          }
        ),
        controls && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-2 flex items-center justify-center gap-2", children: /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-xs text-gray-500", children: [
          "Speed: ",
          speed,
          "x | Direction: ",
          direction === 1 ? "Forward" : "Reverse"
        ] }) })
      ]
    }
  );
}
chunkOLISEQHS_cjs.__name(LottiePlayer, "LottiePlayer");

exports.LottiePlayer = LottiePlayer;
//# sourceMappingURL=LottiePlayer.client-2S7ISJ2S.cjs.map
//# sourceMappingURL=LottiePlayer.client-2S7ISJ2S.cjs.map