//
//  SMNavigationController.m
//  SkinMagnifier
//
//  Created by nana on 2020/11/4.
//

#import "SMNavigationController.h"

@interface SMNavigationController ()

@property(nonatomic, weak)UIButton *backBtn;

@end

@implementation SMNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationBar.hidden = YES;
    
 self.interactivePopGestureRecognizer.enabled = NO;

//    _backBtn = backBtn;

}


- (void)backClick:(UIButton *)btn {
    UIViewController *vc = self.childViewControllers.lastObject ;
    if ([NSStringFromClass([vc class]) isEqualToString:@"SMReportViewController"]) {
        NSArray *vcArray = self.childViewControllers;
        for (int i = 0; i < vcArray.count; i++) {
            UIViewController  *sVC = vcArray[i];
            if ([NSStringFromClass([sVC class]) isEqualToString:@"SMCreateClientViewController"] ) {
                [self popToViewController:vcArray[i-1] animated:YES];
                return;
            }else if ([NSStringFromClass([sVC class]) isEqualToString:@"SMTakeImageViewController"]) {
                [self popToViewController:vcArray[i-1] animated:YES];
                return;
            }
        }
    }
    
       
    [self popViewControllerAnimated:YES];
}
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    [super pushViewController:viewController animated:animated];
    if (self.childViewControllers.count>1) {
        UIViewController *vc = self.childViewControllers.lastObject;
        UIButton *backBtn = [[UIButton alloc] init];
        backBtn.frame =CGRectMake(10, safaTop(20) , 38, 45);
        if (![NSStringFromClass([vc class]) isEqualToString:@"SMTakeImageViewController"]) {
//            [backBtn wb_setImageName:@"nav_white_back"];
//        }else {
            [backBtn wb_setImageName:@"nav_black_back"];
        }

        [backBtn addTarget:self action:@selector(backClick:) forControlEvents:UIControlEventTouchUpInside];
        [vc.view addSubview:backBtn];
        [vc.view bringSubviewToFront:backBtn];
        
//        self.backBtn.hidden = NO;
    }else {
//        self.backBtn.hidden = YES;
    }
}
/*
#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
