function _define_property(obj, key, value) {
    if (key in obj) {
        Object.defineProperty(obj, key, {
            value: value,
            enumerable: true,
            configurable: true,
            writable: true
        });
    } else {
        obj[key] = value;
    }
    return obj;
}
function _object_spread(target) {
    for(var i = 1; i < arguments.length; i++){
        var source = arguments[i] != null ? arguments[i] : {};
        var ownKeys = Object.keys(source);
        if (typeof Object.getOwnPropertySymbols === "function") {
            ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
                return Object.getOwnPropertyDescriptor(source, sym).enumerable;
            }));
        }
        ownKeys.forEach(function(key) {
            _define_property(target, key, source[key]);
        });
    }
    return target;
}
function ownKeys(object, enumerableOnly) {
    var keys = Object.keys(object);
    if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);
        if (enumerableOnly) {
            symbols = symbols.filter(function(sym) {
                return Object.getOwnPropertyDescriptor(object, sym).enumerable;
            });
        }
        keys.push.apply(keys, symbols);
    }
    return keys;
}
function _object_spread_props(target, source) {
    source = source != null ? source : {};
    if (Object.getOwnPropertyDescriptors) {
        Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
    } else {
        ownKeys(Object(source)).forEach(function(key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
        });
    }
    return target;
}
function _object_without_properties(source, excluded) {
    if (source == null) return {};
    var target = {}, sourceKeys, key, i;
    if (typeof Reflect !== "undefined" && Reflect.ownKeys) {
        sourceKeys = Reflect.ownKeys(source);
        for(i = 0; i < sourceKeys.length; i++){
            key = sourceKeys[i];
            if (excluded.indexOf(key) >= 0) continue;
            if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
            target[key] = source[key];
        }
        return target;
    }
    target = _object_without_properties_loose(source, excluded);
    if (Object.getOwnPropertySymbols) {
        sourceKeys = Object.getOwnPropertySymbols(source);
        for(i = 0; i < sourceKeys.length; i++){
            key = sourceKeys[i];
            if (excluded.indexOf(key) >= 0) continue;
            if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
            target[key] = source[key];
        }
    }
    return target;
}
function _object_without_properties_loose(source, excluded) {
    if (source == null) return {};
    var target = {}, sourceKeys = Object.getOwnPropertyNames(source), key, i;
    for(i = 0; i < sourceKeys.length; i++){
        key = sourceKeys[i];
        if (excluded.indexOf(key) >= 0) continue;
        if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
        target[key] = source[key];
    }
    return target;
}
import React, { forwardRef, memo } from "react";
import { useRefFunction } from "../Hooks/useRefFunction";
import { getScrollRailHeight } from "../Utils/getScroll";
import scrollTo from "../Utils/scrollTo";
import { BottomIcon } from "./icons/BottomIcon";
import { ScrollVisibleButton } from "./ScrollVisibleButton";
// 常量定义
var DEFAULT_DURATION = 450;
var DEFAULT_VISIBLE_THRESHOLD = 400;
/**
 * BackBottom 组件 - 返回底部按钮组件
 *
 * 该组件提供一个返回底部的浮动按钮，点击后平滑滚动到页面底部。
 * 当距离底部超过指定阈值时自动显示，支持自定义滚动持续时间和显示条件。
 *
 * @component
 * @description 返回底部按钮，点击后平滑滚动到页面底部
 * @param {BackBottomProps} props - 组件属性
 * @param {number} [props.duration=450] - 滚动到底部的持续时间（毫秒）
 * @param {number | ((scrollTop: number, container: HTMLElement | Window) => boolean)} [props.shouldVisible=400] - 显示条件阈值或自定义函数
 * @param {(e: React.MouseEvent, container: HTMLElement | Window) => void} [props.onClick] - 点击回调函数
 * @param {string} [props.className] - 自定义CSS类名
 * @param {React.CSSProperties} [props.style] - 自定义样式
 * @param {HTMLElement | Window} [props.target] - 滚动容器，默认为 window
 *
 * @example
 * ```tsx
 * // 基本用法
 * <BackBottom />
 *
 * // 自定义滚动持续时间
 * <BackBottom duration={300} />
 *
 * // 自定义显示阈值
 * <BackBottom shouldVisible={600} />
 *
 * // 自定义显示条件
 * <BackBottom
 *   shouldVisible={(scrollTop, container) => {
 *     const scrollHeight = container instanceof Window
 *       ? document.documentElement.scrollHeight
 *       : container.scrollHeight;
 *     return scrollHeight - scrollTop >= 800;
 *   }}
 * />
 *
 * // 指定滚动容器
 * <BackBottom target={document.getElementById('container')} />
 * ```
 *
 * @returns {React.ReactElement} 渲染的返回底部按钮组件
 *
 * @remarks
 * - 默认在距离底部超过 400px 时显示
 * - 支持平滑滚动动画
 * - 可自定义滚动持续时间
 * - 支持自定义显示条件
 * - 支持指定滚动容器
 * - 使用 forwardRef 支持 ref 传递
 * - 提供完整的无障碍支持
 */ var BackBottomComponent = /*#__PURE__*/ forwardRef(function(props, ref) {
    var _props_duration = props.duration, duration = _props_duration === void 0 ? DEFAULT_DURATION : _props_duration, onClick = props.onClick, propsShouldVisible = props.shouldVisible, rest = _object_without_properties(props, [
        "duration",
        "onClick",
        "shouldVisible"
    ]);
    var shouldVisible = useRefFunction(function(scrollTop, container) {
        if (typeof propsShouldVisible === 'function') {
            return propsShouldVisible(scrollTop, container);
        }
        var scrollRailHeight = getScrollRailHeight(container);
        return scrollRailHeight - scrollTop >= (propsShouldVisible !== null && propsShouldVisible !== void 0 ? propsShouldVisible : DEFAULT_VISIBLE_THRESHOLD);
    });
    // 使用 useRefFunction 优化滚动到底部处理函数，保持引用稳定
    var scrollToBottom = useRefFunction(function(e, container) {
        var scrollRailHeight = getScrollRailHeight(container);
        scrollTo(scrollRailHeight, {
            container: container,
            duration: duration
        });
        onClick === null || onClick === void 0 ? void 0 : onClick(e, container);
    });
    // shouldVisible 是 ScrollVisibleButton 的内部 prop，通过类型断言注入
    var scrollVisibleProps = _object_spread_props(_object_spread({}, rest), {
        shouldVisible: shouldVisible
    });
    return /*#__PURE__*/ React.createElement(ScrollVisibleButton, _object_spread_props(_object_spread({}, scrollVisibleProps), {
        ref: ref,
        onClick: scrollToBottom
    }), /*#__PURE__*/ React.createElement(BottomIcon, null));
});
BackBottomComponent.displayName = 'BackBottom';
// 使用 React.memo 优化性能，避免不必要的重新渲染
export var BackBottom = /*#__PURE__*/ memo(BackBottomComponent);
