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

#import "GMTitleView.h"
#import "GMFaceV3Model.h"

@interface GMTitleView ()

@property (nonatomic, assign)GMFaceCommonSubtitleModel *tempModel;
@property (nonatomic, strong) GMLabel *titleLabel;
@property (nonatomic, strong) GMLabel *bestLabel;
@property (nonatomic, strong) GMLabel *contentLabel;

@end

@implementation GMTitleView

- (instancetype)initWithModel:(GMFaceCommonSubtitleModel *)model; {
    if (self = [super init]) {
        self.tempModel = model;
        [self setup];
    }
    return self;
}

- (void)setup {
    [super setup];
    self.titleLabel = [GMLabel new];
    self.titleLabel.numberOfLines = 2;
    self.titleLabel.textColor = UIColor.whiteColor;
    self.titleLabel.font = [UIFont gmBoldFont:15];
    _titleLabel.text = self.tempModel.title;
    _titleLabel.shadowColor = [UIColor colorWithHexString:@"000000" alpha:0.3];
    _titleLabel.shadowOffset = CGSizeMake(0, 1);
    _titleLabel.layer.shadowRadius = 0.5;
    [self addSubview:_titleLabel];
    
    if ([self.tempModel.best isNonEmpty]) {
        // 最佳比例
        self.bestLabel = [GMLabel labelWithTextColor:[UIColor colorWithHexString:@"00EFFF"] fontSize:9];
        _bestLabel.text = self.tempModel.best;
        _bestLabel.shadowColor = [UIColor colorWithHexString:@"000000" alpha:0.3];
        _bestLabel.shadowOffset = CGSizeMake(0, 1);
        _bestLabel.layer.shadowRadius = 0.5;
        [self addSubview:_bestLabel];
    }
    if ([self.tempModel.content isNonEmpty]) {
        // 描述
        self.contentLabel = [GMLabel labelWithTextColor:UIColor.whiteColor fontSize:9];
        _contentLabel.text = self.tempModel.content;
        _contentLabel.shadowColor = [UIColor colorWithHexString:@"000000" alpha:0.3];
        _contentLabel.shadowOffset = CGSizeMake(0, 1);
        _contentLabel.layer.shadowRadius = 0.5;
        [self addSubview:_contentLabel];
    }
    [self addConstraints];
}

- (void)addConstraints {
    CGFloat titleLabelHight = 15;
    if (self.tempModel.title.length > 6) {
        titleLabelHight = 42;
    }
    [self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(self.top);
        make.width.mas_equalTo(90);
        make.height.mas_equalTo(titleLabelHight);
    }];
    if ([self.tempModel.best isNonEmpty]) {
        [self.bestLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.left);
            make.top.mas_equalTo(self.top).offset(12 + titleLabelHight);
            make.width.mas_equalTo(120);
            make.height.mas_equalTo(9);
        }];
    }
    if ([self.tempModel.content isNonEmpty]) {
        if ([self.tempModel.best isNonEmpty]) {
            [self.contentLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(self.left);
                make.top.mas_equalTo(self.top).offset(25 + titleLabelHight);
                make.width.mas_equalTo(120);
                make.height.mas_equalTo(9);
            }];
        }else{
            [self.contentLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(self.left);
                make.top.mas_equalTo(self.top).offset(8 + titleLabelHight);
                make.width.mas_equalTo(120);
                make.height.mas_equalTo(9);
            }];
        }
    }
}
@end
