#import "TQWebView.h"
#import "TQWebViewController.h"
#import "TQWebViewPrewarmer.h"
#import "TQL10n.h"

@implementation TQWebView

+ (NSString *)sdkVersion {
    // 返回当前 SDK 版本号。
    return @"1.2.0";
}

+ (void)openFromPresenter:(UIViewController *)presenter
                      url:(NSString *)url
                   config:(TQWebViewConfig *)config
                callbacks:(TQSignCallbacks *)callbacks
                 animated:(BOOL)animated
               completion:(void (^)(void))completion {
    // 预热环境错配检测（best-effort，仅告警，不阻断）
    [TQWebViewPrewarmer warnIfEnvironmentMismatch:url];
    TQWebViewConfig *cfg = config ?: [TQWebViewConfig defaultConfig];
    TQSignCallbacks *cb = callbacks ?: [TQSignCallbacks callbacks];
    TQWebViewController *vc = [[TQWebViewController alloc] initWithUrl:url
                                                                 config:cfg
                                                              callbacks:cb];
    [presenter presentViewController:vc animated:animated completion:completion];
}

+ (void)openCompatibilityTestFromPresenter:(UIViewController *)presenter
                                  customUrl:(NSString *)customUrl
                                     config:(TQWebViewConfig *)config
                                  callbacks:(TQSignCallbacks *)callbacks
                                   animated:(BOOL)animated {
    TQWebViewConfig *cfg = [(config ?: [TQWebViewConfig defaultConfig]) copy];
    NSString *finalUrl = customUrl
                     ?: cfg.compatibilityTestUrl
                     ?: [TQWebViewConfig defaultCompatibilityTestUrl];
    cfg.topBarTitle = [TQL10n compatibilityTestTitle];
    [self openFromPresenter:presenter
                        url:finalUrl
                     config:cfg
                  callbacks:callbacks
                   animated:animated
                 completion:nil];
}

+ (BOOL)canHandleURL:(NSURL *)url {
    return [[url.scheme lowercaseString] isEqualToString:@"qianapp"];
}

@end
