//
//  ZJShowLogView.m
//  RealEstateManagement
//
//  Created by Javen on 2017/7/25.
//  Copyright © 2017年 上海勾芒信息科技. All rights reserved.
//

#import "ZJShowLogView.h"

@interface ZJShowLogView ()
@property (strong, nonatomic) UIView *shadow;
@property (copy, nonatomic) void (^blockCallBack)(void);
@end
@implementation ZJShowLogView

- (void)awakeFromNib {
    [super awakeFromNib];
    self.shadow = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWidth, kHeight)];
    self.shadow.backgroundColor = [UIColor colorWithWhite:0.3 alpha:0.0];
    
    self.cornerRadius = 7;
    self.clipsToBounds = YES;
}

+ (void)showWithLog:(NSString *)log closeLog:(void (^)(void))callBack{
    ZJShowLogView *logView = [ZJShowLogView viewFromNib];
    logView.textView.text = log;
    logView.frame = CGRectMake(0, 0, kWidth, kHeight - 100);
    logView.center = kWindow.center;
    logView.transform = CGAffineTransformMakeScale(0.01, 0.01);
    logView.blockCallBack = callBack;
    [logView alert];
}


- (void)alert {
    [kWindow addSubview:self.shadow];
    [kWindow addSubview:self];
    [UIView animateWithDuration:0.5
                          delay:0
         usingSpringWithDamping:0.7
          initialSpringVelocity:1.0
                        options:UIViewAnimationOptionCurveEaseOut
                     animations:^{
                         self.shadow.backgroundColor = [UIColor colorWithWhite:0.3 alpha:0.3];
                         self.transform = CGAffineTransformMakeScale(1, 1);
                     }
                     completion:nil];
}

- (void)cancel {
    [UIView animateWithDuration:0.5
                          delay:0
         usingSpringWithDamping:0.9
          initialSpringVelocity:1.0
                        options:UIViewAnimationOptionCurveEaseOut
                     animations:^{
                         self.transform = CGAffineTransformMakeScale(0.01, 0.01);
                         self.shadow.backgroundColor = [UIColor colorWithWhite:0.3 alpha:0.0];
                     }
                     completion:^(BOOL finished) {
                         [self.shadow removeFromSuperview];
                         [self removeFromSuperview];
                     }];
}
- (IBAction)actionCloseLog:(id)sender {
//    kUser.isHasNetWorkDebug = NO;
    if (self.blockCallBack) {
        self.blockCallBack();
    }
    [MBProgressHUD j_textOnly:@"网络请求日志输出已关闭！"];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (IBAction)actionConfirm:(id)sender {
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    [pasteboard setString:self.textView.text];
    [self cancel];
    
    
}

@end
