//
//  GMSkinUpLoadHeadPicPopView.m
//  Gengmei
//
//  Created by 刘鹿杰 on 2019/8/29.
//  Copyright © 2019 更美互动信息科技有限公司. All rights reserved.
//

#import "GMSkinUpLoadHeadPicPopView.h"


#define containerHeight ((MAINSCREEN_WIDTH - 105) * 322 / 270)

@implementation GMSkinUpLoadHeadPicPopView

-(void)setup{
    [super setup];
    self.animationType = GMPopupAnimationTypeFade;
    self.disableCancelTouch = YES;
    self.container.backgroundColor = [UIColor clearColor];
    [self.container mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(MAINSCREEN_WIDTH - 105, containerHeight));
        make.centerX.equalTo(self.mas_centerX);
        make.centerY.equalTo(self.mas_centerY);
    }];
    
    // 添加View
    GMView *contentView = [[GMView alloc] init];
    contentView.backgroundColor = [UIColor whiteColor];
    contentView.layer.cornerRadius = 10;
    contentView.clipsToBounds = YES;
    [self.container addSubview:contentView];
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.container.mas_top).offset(40);
        make.width.equalTo(self.container.mas_width);
        make.centerX.equalTo(self.mas_centerX);
        make.height.mas_equalTo(containerHeight - 95);
    }];
    
    // imageView
    GMImageView *imageView = [[GMImageView alloc] initWithImage:[UIImage imageNamed:@"face_skin_headIcon"]];
    [self.container addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.container.mas_top);
        make.centerX.equalTo(self.mas_centerX);
    }];

    // 添加描述label
    GMLabel *textlabel = [[GMLabel alloc] init];
    textlabel.numberOfLines = 2;
    NSString *tipString = @"上传头像，炫耀肌龄\n 请上传你美美的照片作为头像";
    NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
    paragraphStyle.lineSpacing = 8;
    NSDictionary *attriDict = @{NSParagraphStyleAttributeName:paragraphStyle,NSFontAttributeName:[UIFont gmFont:15],NSForegroundColorAttributeName:UIColor.headlineText};
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:tipString attributes:attriDict];
    textlabel.attributedText = attributedString;
    textlabel.textAlignment = NSTextAlignmentCenter;
    [contentView addSubview:textlabel];
    [textlabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(contentView.mas_centerX);
        make.centerY.equalTo(contentView.mas_centerY);
    }];
    
    // 添加btn
    GMButton *btn = [[GMButton alloc] init];
    [contentView addSubview:btn];
    [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
    UIImage *btnImage = [[UIImage imageNamed:@"face_startActicn_btn"] resizableImageWithCapInsets:UIEdgeInsetsMake(20, 100, 20, 100) resizingMode:UIImageResizingModeStretch];
    [btn setBackgroundImage:btnImage forState:UIControlStateNormal];
    [btn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    [btn.titleLabel setFont:[UIFont gmLightFont:16]];
    [btn setTitle:@"上传" forState:UIControlStateNormal];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(contentView.mas_bottom).offset(-23);
        make.centerX.equalTo(contentView.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(200, 40));
    }];
    
    // 添加底部关闭按钮
    UIImageView *closeIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sign_rule_close"]];
    closeIcon.userInteractionEnabled = YES;
    [self.container addSubview:closeIcon];
    // 添加点击效果
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideView)];
    [closeIcon addGestureRecognizer:tap];
    [closeIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(contentView.mas_centerX);
        make.top.equalTo(contentView.mas_bottom).offset(20);
        make.size.mas_equalTo(CGSizeMake(35, 35));
    }];
}

-(void)hideView{
    [self hide];
}
- (void)btnClick {
    [self hide];
    if (self.popViewBlock) {
        self.popViewBlock();
    }
}
@end
