"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "RouteErrorBoundary", {
    enumerable: true,
    get: function() {
        return RouteErrorBoundary;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _react = require("react");
const _antd = require("antd");
const isDevelopment = process.env.NODE_ENV === 'development';
const RouteErrorBoundary = ({ error, resetErrorBoundary })=>{
    const [showDetails, setShowDetails] = (0, _react.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__*/ (0, _jsxruntime.jsx)("div", {
        style: {
            marginTop: 16,
            textAlign: 'left'
        },
        children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_antd.Collapse, {
            activeKey: showDetails ? [
                'details'
            ] : [],
            onChange: (keys)=>setShowDetails(keys.includes('details')),
            items: [
                {
                    key: 'details',
                    label: /*#__PURE__*/ (0, _jsxruntime.jsxs)("span", {
                        children: [
                            showDetails ? '▲' : '▼',
                            " 错误详情"
                        ]
                    }),
                    children: /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
                        style: {
                            fontFamily: 'monospace',
                            fontSize: '12px',
                            whiteSpace: 'pre-wrap',
                            wordBreak: 'break-all'
                        },
                        children: [
                            /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
                                style: {
                                    marginBottom: 8,
                                    fontWeight: 'bold'
                                },
                                children: "错误信息："
                            }),
                            /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
                                style: {
                                    marginBottom: 16,
                                    color: '#ff4d4f'
                                },
                                children: error.message
                            }),
                            error.stack && /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
                                children: [
                                    /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
                                        style: {
                                            marginBottom: 8,
                                            fontWeight: 'bold'
                                        },
                                        children: "堆栈信息："
                                    }),
                                    /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
                                        style: {
                                            marginBottom: 16,
                                            color: '#666'
                                        },
                                        children: error.stack
                                    })
                                ]
                            }),
                            hasCause && /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
                                children: [
                                    /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
                                        style: {
                                            marginBottom: 8,
                                            fontWeight: 'bold'
                                        },
                                        children: "原因："
                                    }),
                                    /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
                                        style: {
                                            marginBottom: 16,
                                            color: '#666'
                                        },
                                        children: errorWithCause.cause instanceof Error ? errorWithCause.cause.message : String(errorWithCause.cause)
                                    })
                                ]
                            })
                        ]
                    })
                }
            ]
        })
    }) : null;
    return /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
        className: "size-full flex-col-center gap-16px overflow-y-scroll flex-col flex justify-center items-center gap-4",
        children: /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
            className: "flex text-400px text-primary",
            children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_antd.Result, {
                status: "error",
                title: "出错了，请稍后再试",
                subTitle: isDevelopment ? error.message : '请稍后再试或联系技术支持',
                extra: /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
                    style: {
                        display: 'flex',
                        gap: 8,
                        flexDirection: 'column',
                        alignItems: 'center'
                    },
                    children: [
                        /*#__PURE__*/ (0, _jsxruntime.jsx)(_antd.Button, {
                            type: "primary",
                            onClick: resetErrorBoundary,
                            children: "刷新重试"
                        }),
                        isDevelopment && /*#__PURE__*/ (0, _jsxruntime.jsx)(_antd.Button, {
                            type: "link",
                            onClick: ()=>setShowDetails(!showDetails),
                            children: showDetails ? '▲ 收起详情' : '▼ 展开详情'
                        })
                    ]
                }),
                children: errorDetails
            })
        })
    });
};

//# sourceMappingURL=RouteErrorBoundary.js.map