import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { useState } from "react";
import { Result, Button, Collapse } from "antd";
const isDevelopment = process.env.NODE_ENV === 'development';
export const RouteErrorBoundary = ({ error, resetErrorBoundary })=>{
    const [showDetails, setShowDetails] = useState(false);
    // 可以在这里根据不同的业务逻辑处理错误或者上报给日志服务
    // const { token } = theme.useToken();
    // const themeColor = token.colorPrimary;
    const errorWithCause = error;
    const hasCause = 'cause' in error && errorWithCause.cause !== undefined;
    const errorDetails = isDevelopment ? /*#__PURE__*/ _jsx("div", {
        style: {
            marginTop: 16,
            textAlign: 'left'
        },
        children: /*#__PURE__*/ _jsx(Collapse, {
            activeKey: showDetails ? [
                'details'
            ] : [],
            onChange: (keys)=>setShowDetails(keys.includes('details')),
            items: [
                {
                    key: 'details',
                    label: /*#__PURE__*/ _jsxs("span", {
                        children: [
                            showDetails ? '▲' : '▼',
                            " 错误详情"
                        ]
                    }),
                    children: /*#__PURE__*/ _jsxs("div", {
                        style: {
                            fontFamily: 'monospace',
                            fontSize: '12px',
                            whiteSpace: 'pre-wrap',
                            wordBreak: 'break-all'
                        },
                        children: [
                            /*#__PURE__*/ _jsx("div", {
                                style: {
                                    marginBottom: 8,
                                    fontWeight: 'bold'
                                },
                                children: "错误信息："
                            }),
                            /*#__PURE__*/ _jsx("div", {
                                style: {
                                    marginBottom: 16,
                                    color: '#ff4d4f'
                                },
                                children: error.message
                            }),
                            error.stack && /*#__PURE__*/ _jsxs(_Fragment, {
                                children: [
                                    /*#__PURE__*/ _jsx("div", {
                                        style: {
                                            marginBottom: 8,
                                            fontWeight: 'bold'
                                        },
                                        children: "堆栈信息："
                                    }),
                                    /*#__PURE__*/ _jsx("div", {
                                        style: {
                                            marginBottom: 16,
                                            color: '#666'
                                        },
                                        children: error.stack
                                    })
                                ]
                            }),
                            hasCause && /*#__PURE__*/ _jsxs(_Fragment, {
                                children: [
                                    /*#__PURE__*/ _jsx("div", {
                                        style: {
                                            marginBottom: 8,
                                            fontWeight: 'bold'
                                        },
                                        children: "原因："
                                    }),
                                    /*#__PURE__*/ _jsx("div", {
                                        style: {
                                            marginBottom: 16,
                                            color: '#666'
                                        },
                                        children: errorWithCause.cause instanceof Error ? errorWithCause.cause.message : String(errorWithCause.cause)
                                    })
                                ]
                            })
                        ]
                    })
                }
            ]
        })
    }) : null;
    return /*#__PURE__*/ _jsx("div", {
        className: "size-full flex-col-center gap-16px overflow-y-scroll flex-col flex justify-center items-center gap-4",
        children: /*#__PURE__*/ _jsx("div", {
            className: "flex text-400px text-primary",
            children: /*#__PURE__*/ _jsx(Result, {
                status: "error",
                title: "出错了，请稍后再试",
                subTitle: isDevelopment ? error.message : '请稍后再试或联系技术支持',
                extra: /*#__PURE__*/ _jsxs("div", {
                    style: {
                        display: 'flex',
                        gap: 8,
                        flexDirection: 'column',
                        alignItems: 'center'
                    },
                    children: [
                        /*#__PURE__*/ _jsx(Button, {
                            type: "primary",
                            onClick: resetErrorBoundary,
                            children: "刷新重试"
                        }),
                        isDevelopment && /*#__PURE__*/ _jsx(Button, {
                            type: "link",
                            onClick: ()=>setShowDetails(!showDetails),
                            children: showDetails ? '▲ 收起详情' : '▼ 展开详情'
                        })
                    ]
                }),
                children: errorDetails
            })
        })
    });
};

//# sourceMappingURL=RouteErrorBoundary.js.map