//
//  KLTLaunchConfiguration.m
//  KaiLiTe
//
//  Created by yuwell on 2024/8/13.
//  Copyright © 2024 boosal. All rights reserved.
//

#import "KLTLaunchConfiguration.h"
#import "Device+CoreDataClass.h"
#import "Advertise+CoreDataProperties.h"
#import "CGMAlgo.h"
#import "KLTCommonDefine.h"

@interface KLTLaunchConfiguration ()

// 发射器初始化周期 默认未绑定为0
@property(assign, nonatomic) NSInteger initialPeriod;

@end

@implementation KLTLaunchConfiguration

+ (instancetype)sharedManager {
    static dispatch_once_t onceToken;
    static KLTLaunchConfiguration *manager = nil;
    dispatch_once(&onceToken, ^{
        manager = [[KLTLaunchConfiguration alloc] init];
    });
    
    return manager;
}

- (void)startupRootViewController {
    self.initialPeriod = 0;
    /*KLTNavgationHomeViewType viewType = KLTNavgationHomeViewTypeBeforeUse;
    if (KLTLocalSettingManager.shareInstance.canConnectOtherDevice) {
        // 未连接任何发射器
        viewType = KLTNavgationHomeViewTypeBeforeUse;
    } else {
        KLTBluetoothManager *manager = KLTBluetoothManager.sharedManager;
        Device *currentDevice = manager.currentDevice;
        if (currentDevice) {
            EDevice *eDevice = [EDevice getEnumDevice:currentDevice.advertise.localName];
            [self updateInitialPeriod:eDevice.initNumber * 3 * 60];
            NSTimeInterval time = [[NSDate date] timeIntervalSinceDate:[NSString getDateFromWholeString:currentDevice.initialBeginDate]];
            if (time > self.initialPeriod) {
                // 初始化结束 正常使用
                viewType = KLTNavgationHomeViewTypeNormalUsed;
            } else {
                // 初始化期间通知初始化页面重新倒计时
                viewType = KLTNavgationHomeViewTypeInitializing;
            }

        } else {
            // 未连接任何发射器
            viewType = KLTNavgationHomeViewTypeBeforeUse;
        }
    }

    [self resetRootViewController:viewType];*/
}

- (void)bindSuccessRootViewController {
    /*KLTNavgationHomeViewType viewType = KLTNavgationHomeViewTypeBeforeUse;
    KLTBluetoothManager *manager = KLTBluetoothManager.sharedManager;
    Device *currentDevice = manager.currentDevice;
    NSTimeInterval time = [[NSDate date] timeIntervalSinceDate:[NSString getDateFromWholeString:currentDevice.initialBeginDate]];
    if (time > self.initialPeriod) {
        // 初始化结束 正常使用
        viewType = KLTNavgationHomeViewTypeNormalUsed;
    } else {
        // 初始化期间通知初始化页面重新倒计时
        viewType = KLTNavgationHomeViewTypeInitializing;
    }
    [self resetRootViewController:viewType];*/
}

- (void)resetRootViewController:(KLTNavgationHomeViewType)viewType {
    /*KLTViewController *viewController = nil;
    if (KLTNavgationHomeViewTypeBeforeUse == viewType) {
        viewController = [[KLTBeforeUseViewController alloc] init];
    } else if (KLTNavgationHomeViewTypeInitializing == viewType) {
        viewController = [[KLTCountDownViewController alloc] init];
    } else if (KLTNavgationHomeViewTypeNormalUsed == viewType) {
        viewController = [[KLTHomeViewController alloc] init];
    }
    KLTNavigationController *naviController = [[KLTNavigationController alloc] initWithRootViewController:viewController];
    klt_key_window().rootViewController = naviController;*/
}

- (void)updateInitialPeriod:(NSInteger)initialPeriod {
    self.initialPeriod = initialPeriod;
}

@end
