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

#import "GMMarkView.h"

@interface GMMarkView()

@property (nonatomic, strong) GMFaceReplayModel *replayModel;

@end

@implementation GMMarkView

- (instancetype)initWithType:(GMFaceReplayModel *)replayModel {
    if (self = [super init]) {
        self.replayModel = replayModel;
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    // 画底线
    NSArray *vLineArray = [NSArray arrayWithObjects:@140, @181, @354, @395, @568, @609, nil];
    NSArray *hLineArray = [NSArray arrayWithObjects:@120, @161, @460, @501, @818, @859, @1178, @1219, nil];
    for (int i = 0; i < 6; i++) {
        GMView *vLineView = [[GMView alloc] init];
        vLineView.backgroundColor = [UIColor colorWithWhite:1 alpha:0.16];
        // 设置frame
        CGFloat x = ([vLineArray[i] floatValue] / 750) * MAINSCREEN_WIDTH;
        vLineView.frame = CGRectMake(x, 0, 0.5, MAINSCREEN_HEIGHT);
        [self addSubview:vLineView];
    }
    for (int i = 0; i < 8; i++) {
        GMView *hLineView = [[GMView alloc] init];
        hLineView.backgroundColor = [UIColor colorWithWhite:1 alpha:0.16];
        // 设置frame
        CGFloat y = ([hLineArray[i] floatValue] / 1334) * MAINSCREEN_HEIGHT;
        hLineView.frame = CGRectMake(0, y, MAINSCREEN_WIDTH, 0.5);
        [self addSubview:hLineView];
    }
    
    // 设置圆圈背景图
    UIImageView *leftImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"facev3_left_bgimage"]];
    [self addSubview:leftImageView];
    [leftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.bottom);
        make.left.mas_equalTo(self.left);
    }];
    
    UIImageView *rightImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"facev3_right_bgimage"]];
    [self addSubview:rightImageView];
    [rightImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.top);
        make.right.mas_equalTo(self.right);
    }];
    
    UIImageView *iconImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"facev3_lookface"]];
    [self addSubview:iconImageView];
    [iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.bottom).offset(-(30 + GMView.safeAreaInsetsBottom));
        make.right.mas_equalTo(self.right).offset(-15);
    }];
    
    if (self.replayModel.tapType == GMReplayViewTapPreview) {return;}
    // 抖音视频录制 log 添加
    UIImageView *logImageView = [[UIImageView alloc] init];
    logImageView.backgroundColor = [UIColor clearColor];
    [self addSubview:logImageView];
    // 文字
    GMLabel *logLabel = [[GMLabel alloc] init];
    logLabel.numberOfLines = 2;
    logLabel.layer.shadowColor = [UIColor blackColor].CGColor;
    logLabel.layer.shadowOpacity = 0.1;
    logLabel.layer.shadowRadius = 5;
    NSString *tipString = @"下载更美APP\n获取脸型报告";
    NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
    paragraphStyle.lineSpacing = self.replayModel.tapType == GMReplayViewTapWechat ? 8 : 0;
    NSDictionary *attriDict = @{NSParagraphStyleAttributeName:paragraphStyle,NSFontAttributeName:[UIFont gmFont:14],NSForegroundColorAttributeName:UIColor.whiteColor};
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:tipString attributes:attriDict];
    logLabel.attributedText = attributedString;
    logLabel.textAlignment = NSTextAlignmentLeft;
    [self addSubview:logLabel];
    
    if (self.replayModel.tapType == GMReplayViewTapWechat) { // 分析到微信
        [logImageView setImage:[UIImage imageNamed:@"icon"]];
        [logImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.mas_equalTo(54);
            make.bottom.mas_equalTo(self.mas_bottom).offset(-(30 + GMView.safeAreaInsetsBottom));
            make.left.mas_equalTo(self.mas_left).offset(20);
        }];
        [logLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(logImageView.mas_centerY);
            make.left.mas_equalTo(self.mas_left).offset(84);
            make.width.mas_equalTo(84);
        }];
    }else{  // 抖音约束
        logLabel.textAlignment = NSTextAlignmentCenter;
        [logLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(self.mas_bottom).offset(-(30 + GMView.safeAreaInsetsBottom));
            make.left.mas_equalTo(self.mas_left).offset(20);
            make.width.mas_equalTo(84);
        }];
        [logImageView sd_setImageWithURL:[NSURL URLWithString:self.replayModel.dataEwm]];
        [logImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.mas_equalTo(85);
            make.bottom.mas_equalTo(logLabel.mas_top).offset(-10);
            make.centerX.mas_equalTo(logLabel.mas_centerX);
        }];
    }
}

@end
