/**
 * React Router 适配器实现
 */ 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;
}
import { createBrowserRouter, createHashRouter, createMemoryRouter } from "react-router-dom";
import { transformRoutesToReactRoutes } from "../../utils/adapters/react-router/transform";
import { transformRoutes } from "../../utils/transform";
import { logger } from "../../../../utils";
/**
 * React Router 适配器
 */ export class ReactRouterAdapter {
    /**
   * 初始化适配器
   */ async initialize(config) {
        // 转换路由配置
        const transformResult = await transformRoutes(config.routes);
        const reactRoutes = await transformRoutesToReactRoutes(transformResult.routes, transformResult, config.defaultRouteErrorComponent, config.defaultRouteLoadingComponent);
        // 创建路由实例
        const mode = config.mode || 'browser';
        if (mode === 'browser') {
            this.router = createBrowserRouter(reactRoutes, config.options);
        } else if (mode === 'hash') {
            this.router = createHashRouter(reactRoutes, config.options);
        } else if (mode === 'memory') {
            this.router = createMemoryRouter(reactRoutes, config.options);
        } else {
            throw new Error(`不支持的路由模式: ${mode}`);
        }
        logger.debug('React Router 适配器初始化完成');
    }
    /**
   * 挂载到应用实例
   */ mount(_app) {
        if (!this.router) {
            throw new Error('适配器未初始化');
        }
        // React Router 适配器通过 RouterProvider 挂载
        // 实际的挂载逻辑在 renderApp 中处理
        logger.debug('React Router 适配器已挂载');
    }
    /**
   * 导航到指定路径
   */ navigate(to, options) {
        if (!this.router) {
            throw new Error('适配器未初始化');
        }
        if (options?.replace) {
            this.router.navigate(to, {
                replace: true,
                state: options.state
            });
        } else {
            this.router.navigate(to, {
                state: options?.state
            });
        }
    }
    /**
   * 获取当前路由信息
   */ getCurrentRoute() {
        if (!this.router) {
            throw new Error('适配器未初始化');
        }
        const state = this.router.state;
        const location = state.location;
        // 解析查询参数
        const query = {};
        if (location.search) {
            const params = new URLSearchParams(location.search);
            params.forEach((value, key)=>{
                query[key] = value;
            });
        }
        return {
            path: location.pathname + location.hash,
            query,
            params: location.state
        };
    }
    /**
   * 获取路由实例（用于 RouterProvider）
   */ getRouter() {
        return this.router;
    }
    /**
   * 销毁适配器
   */ destroy() {
        this.router = null;
        logger.debug('React Router 适配器已销毁');
    }
    constructor(){
        _define_property(this, "name", 'react-router');
        _define_property(this, "version", '6.0.0');
        _define_property(this, "router", null);
    }
}
/**
 * 创建 React Router 适配器工厂函数
 */ export function createReactRouterAdapter() {
    return (_config)=>{
        return new ReactRouterAdapter();
    };
}

//# sourceMappingURL=ReactRouterAdapter.js.map