/**
 * 开发工具模块
 * 提供开发模式下的调试工具
 */ "use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get DevTools () {
        return DevTools;
    },
    get DevToolsTrigger () {
        return DevToolsTrigger;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _react = require("react");
const _antd = require("antd");
const _app = require("../app");
const { Title, Text, Paragraph } = _antd.Typography;
const { Panel } = _antd.Collapse;
function DevTools({ appInstance, visible, onClose }) {
    const [performanceMetrics, setPerformanceMetrics] = (0, _react.useState)({});
    const [activeTab, setActiveTab] = (0, _react.useState)('overview');
    const stateManager = (0, _app.useStateManager)();
    (0, _react.useEffect)(()=>{
        if (!visible) {
            return;
        }
        const tracker = appInstance.getPerformanceTracker();
        if (tracker) {
            const metrics = tracker.getMetrics();
            setPerformanceMetrics({
                '服务初始化': metrics.serviceInitDuration || 0,
                '初始化': metrics.initializationDuration || 0,
                '首次渲染': metrics.firstRenderDuration || 0,
                '总启动时间': metrics.totalStartupDuration || 0,
                'FCP': metrics.fcp || 0,
                'LCP': metrics.lcp || 0,
                'FID': metrics.fid || 0,
                'CLS': metrics.cls || 0
            });
        }
    }, [
        visible,
        appInstance
    ]);
    const options = appInstance.getOptions();
    // const routerManager = getRouterManager();
    // const isRouterEnabled = routerManager.isRouterEnabled();
    // 获取状态管理器信息
    const stateManagerInfo = (0, _react.useMemo)(()=>{
        if (!stateManager) {
            return null;
        }
        try {
            // 尝试获取所有状态（如果支持）
            const allStates = stateManager.getAllStates?.() || [];
            return {
                stateCount: allStates.length,
                states: allStates.slice(0, 10)
            };
        } catch  {
            return {
                stateCount: 0,
                states: []
            };
        }
    }, [
        stateManager
    ]);
    // 获取路由信息
    // const routerInfo = useMemo(() => {
    //   if (!isRouterEnabled) {
    //     return null;
    //   }
    //   try {
    //     const routes = (routerManager as any).getRoutes?.() || [];
    //     return {
    //       routeCount: routes.length,
    //       mode: (routerManager as any).getRouterMode?.() || 'unknown',
    //       routes: routes.slice(0, 10), // 只显示前10个
    //     };
    //   } catch {
    //     return {
    //       routeCount: 0,
    //       mode: 'unknown',
    //       routes: [],
    //     };
    //   }
    // }, [routerManager, isRouterEnabled]);
    const tabItems = [
        {
            key: 'overview',
            label: '概览',
            children: /*#__PURE__*/ (0, _jsxruntime.jsxs)(_antd.Space, {
                direction: "vertical",
                style: {
                    width: '100%'
                },
                size: "large",
                children: [
                    /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
                        children: [
                            /*#__PURE__*/ (0, _jsxruntime.jsx)(Title, {
                                level: 5,
                                children: "应用实例"
                            }),
                            /*#__PURE__*/ (0, _jsxruntime.jsxs)(_antd.Space, {
                                direction: "vertical",
                                size: "small",
                                children: [
                                    /*#__PURE__*/ (0, _jsxruntime.jsxs)(Text, {
                                        children: [
                                            "实例ID: ",
                                            /*#__PURE__*/ (0, _jsxruntime.jsx)(_antd.Tag, {
                                                children: appInstance.id
                                            })
                                        ]
                                    }),
                                    /*#__PURE__*/ (0, _jsxruntime.jsxs)(Text, {
                                        children: [
                                            "状态: ",
                                            /*#__PURE__*/ (0, _jsxruntime.jsx)(_antd.Tag, {
                                                color: appInstance.isInitialized() ? 'green' : 'orange',
                                                children: appInstance.isInitialized() ? '已初始化' : '未初始化'
                                            })
                                        ]
                                    })
                                ]
                            })
                        ]
                    }),
                    /*#__PURE__*/ (0, _jsxruntime.jsx)(_antd.Divider, {}),
                    /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
                        children: [
                            /*#__PURE__*/ (0, _jsxruntime.jsx)(Title, {
                                level: 5,
                                children: "服务状态"
                            }),
                            /*#__PURE__*/ (0, _jsxruntime.jsxs)(_antd.Space, {
                                direction: "vertical",
                                size: "small",
                                children: [
                                    /*#__PURE__*/ (0, _jsxruntime.jsxs)(Text, {
                                        children: [
                                            "监控服务: ",
                                            /*#__PURE__*/ (0, _jsxruntime.jsx)(_antd.Tag, {
                                                color: "green",
                                                children: "已启用"
                                            })
                                        ]
                                    }),
                                    /*#__PURE__*/ (0, _jsxruntime.jsxs)(Text, {
                                        children: [
                                            "性能监控: ",
                                            /*#__PURE__*/ (0, _jsxruntime.jsx)(_antd.Tag, {
                                                color: "green",
                                                children: "已启用"
                                            })
                                        ]
                                    }),
                                    /*#__PURE__*/ (0, _jsxruntime.jsxs)(Text, {
                                        children: [
                                            "状态管理器: ",
                                            /*#__PURE__*/ (0, _jsxruntime.jsx)(_antd.Tag, {
                                                color: "green",
                                                children: "已启用"
                                            })
                                        ]
                                    })
                                ]
                            })
                        ]
                    })
                ]
            })
        },
        {
            key: 'performance',
            label: '性能',
            children: /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
                children: [
                    /*#__PURE__*/ (0, _jsxruntime.jsx)(Title, {
                        level: 5,
                        children: "性能指标"
                    }),
                    /*#__PURE__*/ (0, _jsxruntime.jsx)(_antd.Space, {
                        direction: "vertical",
                        size: "small",
                        style: {
                            width: '100%'
                        },
                        children: Object.entries(performanceMetrics).map(([key, value])=>/*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
                                style: {
                                    display: 'flex',
                                    justifyContent: 'space-between'
                                },
                                children: [
                                    /*#__PURE__*/ (0, _jsxruntime.jsxs)(Text, {
                                        children: [
                                            key,
                                            ":"
                                        ]
                                    }),
                                    /*#__PURE__*/ (0, _jsxruntime.jsx)(Text, {
                                        strong: true,
                                        children: value > 0 ? `${value.toFixed(2)}ms` : '-'
                                    })
                                ]
                            }, key))
                    })
                ]
            })
        },
        {
            key: 'state',
            label: /*#__PURE__*/ (0, _jsxruntime.jsxs)("span", {
                children: [
                    "状态管理",
                    stateManagerInfo && stateManagerInfo.stateCount > 0 && /*#__PURE__*/ (0, _jsxruntime.jsx)(_antd.Badge, {
                        count: stateManagerInfo.stateCount,
                        style: {
                            marginLeft: 8
                        }
                    })
                ]
            }),
            children: stateManagerInfo ? /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
                children: [
                    /*#__PURE__*/ (0, _jsxruntime.jsx)(Title, {
                        level: 5,
                        children: "状态管理器"
                    }),
                    /*#__PURE__*/ (0, _jsxruntime.jsxs)(_antd.Space, {
                        direction: "vertical",
                        size: "small",
                        style: {
                            width: '100%'
                        },
                        children: [
                            /*#__PURE__*/ (0, _jsxruntime.jsxs)(Text, {
                                children: [
                                    "状态总数: ",
                                    /*#__PURE__*/ (0, _jsxruntime.jsx)(_antd.Tag, {
                                        children: stateManagerInfo.stateCount
                                    })
                                ]
                            }),
                            stateManagerInfo.states.length > 0 && /*#__PURE__*/ (0, _jsxruntime.jsx)(_antd.Collapse, {
                                children: /*#__PURE__*/ (0, _jsxruntime.jsx)(Panel, {
                                    header: "状态列表",
                                    children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_antd.Space, {
                                        direction: "vertical",
                                        size: "small",
                                        style: {
                                            width: '100%'
                                        },
                                        children: stateManagerInfo.states.map((state, index)=>/*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
                                                style: {
                                                    fontSize: '12px'
                                                },
                                                children: /*#__PURE__*/ (0, _jsxruntime.jsx)(Text, {
                                                    code: true,
                                                    children: state.id || `State ${index + 1}`
                                                })
                                            }, index))
                                    })
                                }, "states")
                            })
                        ]
                    })
                ]
            }) : /*#__PURE__*/ (0, _jsxruntime.jsx)(Text, {
                type: "secondary",
                children: "状态管理器未初始化"
            })
        },
        {
            key: 'config',
            label: '配置',
            children: /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
                children: [
                    /*#__PURE__*/ (0, _jsxruntime.jsx)(Title, {
                        level: 5,
                        children: "配置信息"
                    }),
                    /*#__PURE__*/ (0, _jsxruntime.jsx)(Paragraph, {
                        children: /*#__PURE__*/ (0, _jsxruntime.jsx)(Text, {
                            code: true,
                            style: {
                                fontSize: '12px',
                                whiteSpace: 'pre-wrap'
                            },
                            children: JSON.stringify(options, null, 2)
                        })
                    })
                ]
            })
        }
    ];
    return /*#__PURE__*/ (0, _jsxruntime.jsx)(_antd.Drawer, {
        title: /*#__PURE__*/ (0, _jsxruntime.jsx)(_antd.Space, {
            children: /*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
                children: "🐛 开发工具"
            })
        }),
        placement: "right",
        width: 500,
        open: visible,
        onClose: onClose,
        extra: /*#__PURE__*/ (0, _jsxruntime.jsx)(_antd.Button, {
            type: "text",
            onClick: onClose,
            children: "✕"
        }),
        children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_antd.Tabs, {
            activeKey: activeTab,
            onChange: setActiveTab,
            items: tabItems
        })
    });
}
function DevToolsTrigger({ appInstance, position = 'bottom-right' }) {
    const [visible, setVisible] = (0, _react.useState)(false);
    const positionStyle = {
        position: 'fixed',
        zIndex: 9999,
        ...position === 'bottom-right' && {
            bottom: 20,
            right: 20
        },
        ...position === 'bottom-left' && {
            bottom: 20,
            left: 20
        },
        ...position === 'top-right' && {
            top: 20,
            right: 20
        },
        ...position === 'top-left' && {
            top: 20,
            left: 20
        }
    };
    // 只在开发环境显示
    if (process.env.NODE_ENV !== 'development') {
        return null;
    }
    return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
        children: [
            /*#__PURE__*/ (0, _jsxruntime.jsx)(_antd.Button, {
                type: "primary",
                shape: "circle",
                style: positionStyle,
                onClick: ()=>setVisible(true),
                children: "🐛"
            }),
            /*#__PURE__*/ (0, _jsxruntime.jsx)(DevTools, {
                appInstance: appInstance,
                visible: visible,
                onClose: ()=>setVisible(false)
            })
        ]
    });
}

//# sourceMappingURL=DevTools.js.map