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 _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 _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 { ConfigProvider } from "antd";
import classNames from "clsx";
import React, { isValidElement, memo, useCallback, useContext, useState } from "react";
import { CloseIcon } from "./components/CloseIcon";
import { ErrorIcon } from "./components/ErrorIcon";
import { InfoIcon } from "./components/InfoIcon";
import { LoaderIcon } from "./components/LoaderIcon";
import { SuccessIcon } from "./components/SuccessIcon";
import { WarningIcon } from "./components/WarningIcon";
import { useStyle } from "./style";
var iconMapFilled = {
    success: SuccessIcon,
    info: InfoIcon,
    error: ErrorIcon,
    warning: WarningIcon,
    gray: LoaderIcon
};
var IconNode = /*#__PURE__*/ memo(function(props) {
    var icon = props.icon, prefixCls = props.prefixCls, type = props.type, hashId = props.hashId;
    var iconType = type ? iconMapFilled[type] : null;
    // 使用提前返回优化
    if (icon) {
        if (!/*#__PURE__*/ isValidElement(icon)) {
            return /*#__PURE__*/ React.createElement("span", {
                className: classNames("".concat(prefixCls, "-icon"), hashId)
            }, icon);
        }
        return /*#__PURE__*/ React.cloneElement(icon, {
            className: classNames("".concat(prefixCls, "-icon"), hashId, icon.props.className)
        });
    }
    if (!iconType) {
        return null;
    }
    return /*#__PURE__*/ React.createElement(iconType, {
        className: classNames("".concat(prefixCls, "-icon"), hashId)
    });
});
IconNode.displayName = 'IconNode';
/**
 * AnswerAlert 组件 - 答案提示组件
 *
 * 该组件用于显示各种类型的提示信息，支持成功、错误、警告、信息等多种状态。
 * 提供图标显示、关闭功能、自定义操作等特性，适用于消息提示、状态反馈等场景。
 *
 * @component
 * @description 答案提示组件，用于显示各种类型的提示信息
 * @param {AnswerAlertProps} props - 组件属性
 * @param {string} [props.className] - 自定义CSS类名
 * @param {React.CSSProperties} [props.style] - 自定义样式
 * @param {React.ReactNode} [props.message] - 提示内容
 * @param {React.ReactNode} [props.description] - 辅助性文字介绍
 * @param {React.ReactNode} [props.icon] - 自定义图标
 * @param {boolean} [props.showIcon] - 是否显示辅助图标
 * @param {'success' | 'error' | 'warning' | 'info' | 'gray'} [props.type] - 提示类型
 * @param {React.ReactNode} [props.action] - 自定义操作项
 * @param {boolean} [props.closable] - 是否可关闭
 * @param {(e: React.MouseEvent<HTMLButtonElement>) => void} [props.onClose] - 关闭回调
 *
 * @example
 * ```tsx
 * <AnswerAlert
 *   type="success"
 *   message="操作成功"
 *   description="您的操作已经成功完成"
 *   showIcon={true}
 *   closable={true}
 *   onClose={() => console.log('关闭提示')}
 * />
 * ```
 *
 * @returns {React.ReactElement} 渲染的答案提示组件
 *
 * @remarks
 * - 支持多种提示类型（成功、错误、警告、信息、灰色）
 * - 提供图标显示功能
 * - 支持自定义操作项
 * - 支持关闭功能
 * - 提供描述文字显示
 * - 支持自定义样式和类名
 * - 响应式布局适配
 */ var AnswerAlertComponent = function AnswerAlertComponent(param) {
    var className = param.className, style = param.style, message = param.message, description = param.description, icon = param.icon, showIcon = param.showIcon, type = param.type, action = param.action, closable = param.closable, onClose = param.onClose;
    var getPrefixCls = useContext(ConfigProvider.ConfigContext).getPrefixCls;
    var prefixCls = getPrefixCls('answer-alert');
    var _useStyle = useStyle(prefixCls), wrapSSR = _useStyle.wrapSSR, hashId = _useStyle.hashId;
    var _useState = _sliced_to_array(useState(false), 2), closed = _useState[0], setClosed = _useState[1];
    // 使用 useCallback 优化关闭处理函数
    var handleClose = useCallback(function(e) {
        setClosed(true);
        onClose === null || onClose === void 0 ? void 0 : onClose(e);
    }, [
        onClose
    ]);
    // 使用提前返回优化
    if (closed) {
        return null;
    }
    var _obj;
    var alertCls = classNames(prefixCls, className, (_obj = {}, _define_property(_obj, "".concat(prefixCls, "-").concat(type), !!type), _define_property(_obj, "".concat(prefixCls, "-with-description"), !!description), _obj), hashId);
    return wrapSSR(/*#__PURE__*/ React.createElement("div", {
        className: alertCls,
        style: style
    }, /*#__PURE__*/ React.createElement("div", {
        className: classNames("".concat(prefixCls, "-content"), hashId)
    }, showIcon ? /*#__PURE__*/ React.createElement(IconNode, {
        icon: icon,
        prefixCls: prefixCls,
        type: type,
        hashId: hashId
    }) : null, /*#__PURE__*/ React.createElement("div", {
        className: classNames("".concat(prefixCls, "-message"), hashId)
    }, message), action ? /*#__PURE__*/ React.createElement("div", {
        className: classNames("".concat(prefixCls, "-action"), hashId)
    }, action) : null, closable && /*#__PURE__*/ React.createElement("button", {
        type: "button",
        className: classNames("".concat(prefixCls, "-close-icon"), hashId),
        tabIndex: 0,
        onClick: handleClose
    }, /*#__PURE__*/ React.createElement(CloseIcon, null))), /*#__PURE__*/ React.createElement("div", {
        className: classNames("".concat(prefixCls, "-description"), hashId)
    }, description)));
};
AnswerAlertComponent.displayName = 'AnswerAlert';
// 使用 React.memo 优化性能，避免不必要的重新渲染
export var AnswerAlert = /*#__PURE__*/ memo(AnswerAlertComponent);
