//
//  ExEMASWXSDKEngine.m
//  <%= appName %>
//
//  Created by daoche.jb on 2018/6/28.
//  Copyright © 2018年 EMAS. All rights reserved.
//

#import "EMASWXSubSDKEngine.h"
#import "EMASService.h"
#import "EMASWXNavigationImpl.h"
#import "WXNavigationBarDefaultImpl.h"
#import "EMASWXScreenModule.h"
#if __has_include(<WeexSDK/WeexSDK.h>)
#import <WeexSDK/WeexSDK.h>

#if __has_include(<EmasWeexComponents/EmasWeexComponents.h>)
#import <EmasWeexComponents/EmasWeexComponents.h>
#import <EmasWeexComponents/WXNavigationBarModule.h>
#import <EmasWeexComponents/WXScreenModule.h>
#import <EmasWeexComponents/WXSysShareModule.h>
#import <EMasXBase/XCOScreenshotDetector.h>
#else
#endif

#if __has_include(<EmasSocial/XCOSocial.h>)
#import <EmasSocial/XCOSocial.h>
#else
#endif

#if __has_include(<WeexPluginLoader/WeexPluginLoader.h>)
#import <WeexPluginLoader/WPLRegister.h>
#else
#endif

#else
#endif

@implementation EMASWXSubSDKEngine

#if __has_include(<WeexSDK/WeexSDK.h>)

+ (void)setup {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        [self initWXSDKEnviroment];
    });
}

+ (void)initWXSDKEnviroment {
    [super initWXSDKEnviroment];
    
#ifdef DEBUG
    [WXDebugTool setDebug:YES];
    [WXLog setLogLevel:WXLogLevelLog];
    
#else
    [WXDebugTool setDebug:NO];
    [WXLog setLogLevel:WXLogLevelError];
#endif

#if __has_include(<EmasWeexComponents/EmasWeexComponents.h>)
    [EmasWeexComponents setup];
    [WXSDKEngine registerHandler:[WXNavigationBarDefaultImpl new] withProtocol:@protocol(WXNavigationBarModuleProtocol)];
#else
#endif
    
    

#if __has_include(<EmasSocial/XCOSocial.h>)
    [WXSDKEngine registerHandler:[XCOSocial sharedInstance] withProtocol:@protocol(XSocialProtocol)];
#else
#endif
    
#if __has_include(<WeexPluginLoader/WeexPluginLoader.h>)
    [WPRegister registerPlugins];
#else
#endif
    
}

+ (void)appConfig {
    [super appConfig];
    
    [WXAppConfiguration setAppGroup:@"EMASApp"];
    [WXAppConfiguration setAppName:@"<%= appName %>"];
    [WXAppConfiguration setAppVersion:[[EMASService shareInstance] getAppVersion]];

}

+ (void)registerHandler {
    [super registerHandler];
    [self registerHandler:[EMASWXNavigationImpl new] withProtocol:@protocol(WXNavigationProtocol)];
}

+ (void)registerModule {
    [super registerModule];
#if __has_include(<EmasWeexComponents/EmasWeexComponents.h>)
    [self registerModule:@"navigationBar" withClass:WXNavigationBarModule.class];
    [self registerModule:@"system-share" withClass:[WXSysShareModule class]];
#else
#endif
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        //或者用另外的名称覆盖
        [self registerModule:@"screen" withClass:[EMASWXScreenModule class]];
    });
}
#else
#endif
@end
