//
//  KKInsuranceTabBarController.m
//  Open
//
//  Created by 雷俊博 on 2021/4/27.
//  Copyright © 2021 黄江涛 . All rights reserved.
//

#import "KKInsuranceTabBarController.h"

@interface KKInsuranceTabBarController ()
{
    CGFloat statusBarHeight;
    UIEdgeInsets gSafeAreaInsets;
    UIButton* lastSelectBtn;
}

@property (nonatomic, strong)UIView *kTabBarView;

@end

@implementation KKInsuranceTabBarController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
   [self.navigationController setNavigationBarHidden:YES animated:animated];
    self.tabBar.hidden = YES;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    if ([UIScreen mainScreen].bounds.size.height > 811) {
        statusBarHeight = 44;
        gSafeAreaInsets = UIEdgeInsetsMake(44, 0, 34, 0);
    }else{
        statusBarHeight = 20;
        gSafeAreaInsets = UIEdgeInsetsMake(20, 0, 0, 0);
    }
   
   
    
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
   
    
    if (!_kTabBarView) {
        [self.view addSubview:self.kTabBarView];
    }
    
}

#pragma mark - event response
- (void)btnClick:(UIButton *)sender {
    if (sender == lastSelectBtn) {
        return;
    }
    lastSelectBtn.selected = NO;
    sender.selected = YES;
    lastSelectBtn = sender;
    self.selectedIndex = sender.tag - 200;
    
   
}



#pragma mark - getters and setters
- (UIView *)kTabBarView {
    if (!_kTabBarView) {
        _kTabBarView = [[UIView alloc]initWithFrame:CGRectMake(0, self.view.bounds.size.height - gSafeAreaInsets.bottom - 49, ScreenWidth, gSafeAreaInsets.bottom + 49)];
        _kTabBarView.backgroundColor = [UIColor whiteColor];
        KKInsuranceModel* leftModel = self.dataArray[0];
        KKInsuranceModel* rightModel = self.dataArray[1];
        
        UIButton* leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        leftBtn.frame = CGRectMake(0, 0, ScreenWidth/2, 49);
        [leftBtn setTitle:leftModel.pageName forState:UIControlStateNormal];
        [leftBtn setTitleColor:K_MainColor forState:UIControlStateSelected];
        [leftBtn setTitleColor:[UIColor colorWithHex:0x808080] forState:UIControlStateNormal];
        leftBtn.titleLabel.font = [UIFont systemFontOfSize:17];
        leftBtn.tag = 200;
        [leftBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        [_kTabBarView addSubview:leftBtn];
        UIButton* rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        rightBtn.frame = CGRectMake(ScreenWidth/2, 0, ScreenWidth/2, 49);
        [rightBtn setTitle:rightModel.pageName forState:UIControlStateNormal];
        [rightBtn setTitleColor:K_MainColor forState:UIControlStateSelected];
        [rightBtn setTitleColor:[UIColor colorWithHex:0x808080] forState:UIControlStateNormal];
        rightBtn.titleLabel.font = [UIFont systemFontOfSize:17];
        rightBtn.tag = 201;
        [rightBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        [_kTabBarView addSubview:rightBtn];
        leftBtn.selected = YES;
        lastSelectBtn = leftBtn;
    }
    return _kTabBarView;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
