function _array_like_to_array(arr, len) {
    if (len == null || len > arr.length) len = arr.length;
    for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
    return arr2;
}
function _array_with_holes(arr) {
    if (Array.isArray(arr)) return arr;
}
function _iterable_to_array_limit(arr, i) {
    var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
    if (_i == null) return;
    var _arr = [];
    var _n = true;
    var _d = false;
    var _s, _e;
    try {
        for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
            _arr.push(_s.value);
            if (i && _arr.length === i) break;
        }
    } catch (err) {
        _d = true;
        _e = err;
    } finally{
        try {
            if (!_n && _i["return"] != null) _i["return"]();
        } finally{
            if (_d) throw _e;
        }
    }
    return _arr;
}
function _non_iterable_rest() {
    throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _sliced_to_array(arr, i) {
    return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
}
function _unsupported_iterable_to_array(o, minLen) {
    if (!o) return;
    if (typeof o === "string") return _array_like_to_array(o, minLen);
    var n = Object.prototype.toString.call(o).slice(8, -1);
    if (n === "Object" && o.constructor) n = o.constructor.name;
    if (n === "Map" || n === "Set") return Array.from(n);
    if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
}
import { AnimatePresence, motion } from "framer-motion";
import React, { useEffect, useRef, useState } from "react";
/**
 * BorderBeamAnimation 组件 - 边框光束动画
 *
 * 该组件提供一个沿边框移动的彩色光束动画效果，通常用于输入框获得焦点时的视觉反馈。
 *
 * @component
 * @description 边框光束动画组件，使用 SVG 和 Framer Motion 实现
 * @param {BorderBeamAnimationProps} props - 组件属性
 * @param {boolean} props.isVisible - 是否显示动画
 * @param {number} props.borderRadius - 圆角半径
 * @param {() => void} [props.onAnimationComplete] - 动画完成回调
 * @param {string} [props.gradientId] - 渐变 ID，用于避免多个实例冲突
 * @param {number} [props.offsetX] - 水平偏移量，默认为 6
 * @param {number} [props.offsetY] - 垂直偏移量，默认为 16
 *
 * @example
 * ```tsx
 * <BorderBeamAnimation
 *   isVisible={isFocused}
 *   borderRadius={16}
 *   onAnimationComplete={() => setAnimationComplete(true)}
 * />
 * ```
 *
 * @returns {React.ReactElement | null} 渲染的动画组件或 null
 *
 * @remarks
 * - 使用 Framer Motion 实现路径动画
 * - 包含两条路径：模糊的尾部路径和明亮的核心路径
 * - 动画持续时间为 1 秒
 * - 使用线性渐变实现彩色光束效果
 * - 路径计算在组件内部完成
 * - 使用 ResizeObserver 自动获取容器尺寸
 */ export var BorderBeamAnimation = function BorderBeamAnimation(param) {
    var isVisible = param.isVisible, borderRadius = param.borderRadius, onAnimationComplete = param.onAnimationComplete, gradientIdProp = param.gradientId, _param_offsetX = param.offsetX, offsetX = _param_offsetX === void 0 ? 1 : _param_offsetX, _param_offsetY = param.offsetY, offsetY = _param_offsetY === void 0 ? 1 : _param_offsetY;
    var containerRef = useRef(null);
    var _useState = _sliced_to_array(useState({
        width: 0,
        height: 0
    }), 2), dimensions = _useState[0], setDimensions = _useState[1];
    // 使用 React.useId 生成唯一渐变 ID，避免多实例冲突
    var generatedId = React.useId();
    var gradientId = gradientIdProp !== null && gradientIdProp !== void 0 ? gradientIdProp : "beam-gradient-".concat(generatedId);
    // 使用 ResizeObserver 监听容器尺寸变化
    useEffect(function() {
        var _containerRef_current, _containerRef_current1;
        if (!containerRef.current) return;
        if (process.env.NODE_ENV === 'test') return;
        var resizeObserver = new ResizeObserver(function(entries) {
            var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
            try {
                for(var _iterator = entries[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
                    var entry = _step.value;
                    setDimensions({
                        width: entry.contentRect.width,
                        height: entry.contentRect.height
                    });
                }
            } catch (err) {
                _didIteratorError = true;
                _iteratorError = err;
            } finally{
                try {
                    if (!_iteratorNormalCompletion && _iterator.return != null) {
                        _iterator.return();
                    }
                } finally{
                    if (_didIteratorError) {
                        throw _iteratorError;
                    }
                }
            }
        });
        resizeObserver.observe(containerRef.current);
        setDimensions({
            width: ((_containerRef_current = containerRef.current) === null || _containerRef_current === void 0 ? void 0 : _containerRef_current.clientWidth) || 0,
            height: ((_containerRef_current1 = containerRef.current) === null || _containerRef_current1 === void 0 ? void 0 : _containerRef_current1.clientHeight) || 0
        });
        return function() {
            resizeObserver.disconnect();
        };
    }, []);
    var width = dimensions.width, height = dimensions.height;
    // 使用 props 传入的 borderRadius，而非硬编码
    var radius = borderRadius;
    var w = width;
    var h = height;
    // Outer path dimensions
    var outerRadiusX = radius + offsetX;
    var outerRadiusY = radius + offsetY;
    // Ensure we have valid dimensions before generating path
    // Path starts from bottom-right corner to guide attention to top-left
    var pathData = w > 0 && h > 0 ? "\n    M ".concat(w + offsetX - outerRadiusX, " ").concat(h + offsetY, "\n    H ").concat(-offsetX + outerRadiusX, "\n    A ").concat(outerRadiusX, " ").concat(outerRadiusY, " 0 0 1 ").concat(-offsetX, " ").concat(h + offsetY - outerRadiusY, "\n    V ").concat(-offsetY + outerRadiusY, "\n    A ").concat(outerRadiusX, " ").concat(outerRadiusY, " 0 0 1 ").concat(-offsetX + outerRadiusX, " ").concat(-offsetY, "\n    H ").concat(w + offsetX - outerRadiusX, "\n    A ").concat(outerRadiusX, " ").concat(outerRadiusY, " 0 0 1 ").concat(w + offsetX, " ").concat(-offsetY + outerRadiusY, "\n    V ").concat(h + offsetY - outerRadiusY, "\n    A ").concat(outerRadiusX, " ").concat(outerRadiusY, " 0 0 1 ").concat(w + offsetX - outerRadiusX, " ").concat(h + offsetY, "\n    Z\n  ").replace(/\s+/g, ' ').trim() : '';
    return /*#__PURE__*/ React.createElement("div", {
        ref: containerRef,
        style: {
            position: 'absolute',
            inset: 0,
            pointerEvents: 'none',
            zIndex: 99,
            borderRadius: borderRadius,
            overflow: 'hidden'
        }
    }, /*#__PURE__*/ React.createElement(AnimatePresence, null, isVisible && pathData ? /*#__PURE__*/ React.createElement("div", {
        style: {
            position: 'absolute',
            inset: 0,
            pointerEvents: 'none',
            zIndex: 0,
            borderRadius: borderRadius,
            overflow: 'visible'
        }
    }, /*#__PURE__*/ React.createElement("svg", {
        style: {
            width: '100%',
            height: '100%',
            overflow: 'visible'
        },
        viewBox: "".concat(-offsetX, " ").concat(-offsetY, " ").concat(w + offsetX * 2, " ").concat(h + offsetY * 2),
        fill: "none"
    }, /*#__PURE__*/ React.createElement("defs", null, /*#__PURE__*/ React.createElement("linearGradient", {
        id: gradientId,
        gradientUnits: "userSpaceOnUse",
        x1: "0%",
        y1: "0%",
        x2: "100%",
        y2: "0%"
    }, /*#__PURE__*/ React.createElement("stop", {
        offset: "0%",
        stopColor: "#5760FF",
        stopOpacity: "1"
    }), /*#__PURE__*/ React.createElement("stop", {
        offset: "15%",
        stopColor: "#33CCFF",
        stopOpacity: "1"
    }), /*#__PURE__*/ React.createElement("stop", {
        offset: "30%",
        stopColor: "#33CCFF",
        stopOpacity: "1"
    }), /*#__PURE__*/ React.createElement("stop", {
        offset: "50%",
        stopColor: "#E2CCFF",
        stopOpacity: "1"
    }), /*#__PURE__*/ React.createElement("stop", {
        offset: "65%",
        stopColor: "#33CCFF",
        stopOpacity: "1"
    }), /*#__PURE__*/ React.createElement("stop", {
        offset: "100%",
        stopColor: "#5760FF",
        stopOpacity: "1"
    }))), /*#__PURE__*/ React.createElement(motion.path, {
        d: pathData,
        fill: "none",
        stroke: "url(#".concat(gradientId, ")"),
        strokeWidth: "4",
        strokeLinecap: "round",
        filter: "blur(8px)",
        initial: {
            pathLength: 0,
            pathOffset: 0,
            opacity: 0
        },
        animate: {
            pathLength: [
                0,
                0.45,
                0
            ],
            pathOffset: [
                0,
                0.4
            ],
            opacity: [
                0,
                0.4,
                0
            ]
        },
        transition: {
            duration: 1,
            ease: 'easeInOut',
            times: [
                0,
                0.5,
                1
            ]
        }
    }), /*#__PURE__*/ React.createElement(motion.path, {
        d: pathData,
        fill: "none",
        stroke: "url(#".concat(gradientId, ")"),
        strokeWidth: "2",
        strokeLinecap: "round",
        filter: "blur(4px)",
        initial: {
            pathLength: 0,
            pathOffset: 0,
            opacity: 0
        },
        animate: {
            pathLength: [
                0,
                0.25,
                0
            ],
            pathOffset: [
                0,
                0.65
            ],
            opacity: [
                0,
                1,
                0
            ]
        },
        transition: {
            duration: 0.8,
            ease: 'easeInOut',
            times: [
                0,
                0.6,
                1
            ]
        },
        onAnimationComplete: onAnimationComplete
    }))) : null));
};
