//
//  XVUploadHealthCardViewController.m
//  fastservice
//
//  Created by xuning on 5/4/25.
//  Copyright © 2025 FastService. All rights reserved.
//

#import "XVUploadHealthCardViewController.h"
#import "XVHealthCardTipView.h"

@interface XVUploadHealthCardViewController ()

@property (nonatomic, strong) UIScrollView *scrollView;

@property (nonatomic, strong) UILabel *titleLabel;

@property (nonatomic, strong) UIImageView *uploadImageView;

@property (nonatomic, strong) UILabel *subTitleLabel;

@property (nonatomic, strong) UILabel *descLabel;

@property (nonatomic, strong) UIButton *uploadButton;

@property (nonatomic, strong) XVHealthCardTipView *tip1View;

@property (nonatomic, strong) XVHealthCardTipView *tip2View;

@property (nonatomic, strong) XVHealthCardTipView *tip3View;

@property (nonatomic, strong) XVHealthCardTipView *tip4View;


@end

@implementation XVUploadHealthCardViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"上传健康证";
    [self setupUI];
}

- (void)setupUI {
    
    
    [self.view addSubview:self.uploadButton];
    [self.uploadButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view).mas_offset(15);
        make.right.mas_equalTo(self.view).mas_offset(-15);
        make.height.mas_equalTo(47);
        if (@available(iOS 11.0, *)) {
            make.bottom.mas_equalTo(self.view.mas_safeAreaLayoutGuideBottom).mas_offset(-7);
        } else {
            make.bottom.mas_equalTo(self.view).mas_offset(-7);
        }
    }];
    
    kViewBorderRadius(self.uploadButton, 4, 0, COLOR_THEMEGRENN);
    
    [self.view addSubview:self.scrollView];
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.mas_equalTo(self.view);
        make.bottom.mas_equalTo(self.uploadButton.mas_top);
    }];
    
    [self.scrollView addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view).mas_offset(17);
        make.top.mas_equalTo(self.scrollView).mas_offset(18);
    }];
    
    [self.scrollView addSubview:self.uploadImageView];
    [self.uploadImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view).mas_offset(16);
        make.right.mas_equalTo(self.view).mas_offset(-16);
        make.top.mas_equalTo(self.titleLabel.mas_bottom).mas_offset(15);
        make.height.mas_equalTo(186*widthScale);
    }];
    
    [self.scrollView addSubview:self.subTitleLabel];
    [self.subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view).mas_offset(13);
        make.top.mas_equalTo(self.uploadImageView.mas_bottom).mas_offset(14);
    }];
    
    [self.scrollView addSubview:self.descLabel];
    [self.descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view).mas_offset(16);
        make.top.mas_equalTo(self.subTitleLabel.mas_bottom).mas_offset(14);
    }];

    
    CGFloat w = (SCREEN_WIDTH - 15*5) / 4;
    
    [self.scrollView addSubview:self.tip1View];
    [self.tip1View mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.descLabel.mas_bottom).mas_offset(24);
        make.width.mas_equalTo(w);
        make.left.mas_equalTo(self.view).mas_offset(15);
    }];
    
    [self.scrollView addSubview:self.tip2View];
    [self.tip2View mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.descLabel.mas_bottom).mas_offset(24);
        make.width.mas_equalTo(w);
        make.left.mas_equalTo(self.tip1View.mas_right).mas_offset(15);
    }];
    
    [self.scrollView addSubview:self.tip3View];
    [self.tip3View mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.descLabel.mas_bottom).mas_offset(24);
        make.width.mas_equalTo(w);
        make.left.mas_equalTo(self.tip2View.mas_right).mas_offset(15);
    }];
    [self.scrollView addSubview:self.tip4View];
    [self.tip4View mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.descLabel.mas_bottom).mas_offset(24);
        make.width.mas_equalTo(w);
        make.left.mas_equalTo(self.tip3View.mas_right).mas_offset(15);
        make.right.mas_equalTo(self.view).mas_offset(-15);
    }];


}


- (UIScrollView *)scrollView {
    if (_scrollView == nil) {
        _scrollView = [[UIScrollView alloc]initWithFrame:self.view.bounds];
        _scrollView.backgroundColor = DEFAULT_BACKGROUND_COLOR;
        _scrollView.alwaysBounceVertical = YES;
    }
    return _scrollView;
}

- (UILabel *)titleLabel {
    if (_titleLabel == nil) {
        _titleLabel = [[UILabel alloc]initWithText:@"请拍摄您的健康证" textColor:F_101010_COLOR textAlignment:(NSTextAlignmentLeft) fontSize:18];
    }
    return _titleLabel;
}

- (UIImageView *)uploadImageView {
    if (_uploadImageView == nil) {
        _uploadImageView = [[UIImageView alloc]initWithImageName:@"jk群组 1"];
        UIImageView *icon = [[UIImageView alloc]initWithImageName:@"riFill-camera-fill 1"];
        [_uploadImageView addSubview:icon];
        [icon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.mas_equalTo(_uploadImageView);
            make.size.mas_equalTo(CGSizeMake(38, 38));
        }];
    }
    return _uploadImageView;
}

- (UILabel *)subTitleLabel {
    if (_subTitleLabel == nil) {
        _subTitleLabel = [[UILabel alloc]initWithText:@"拍摄要求" textColor:F_101010_COLOR textAlignment:(NSTextAlignmentLeft) fontSize:18];
    }
    return _subTitleLabel;
}

- (UILabel *)descLabel {
    if (_descLabel == nil) {
        _descLabel = [[UILabel alloc]init];
        
        UIFont *font = [UIFont systemFontOfSize:12];
        
        NSMutableAttributedString *text = [NSMutableAttributedString new];
        NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
         paragraphStyle.lineSpacing = 10;
        [text appendAttributedString:[[NSAttributedString alloc] initWithString:@"请拍摄本人证件原件，不得使用复印件或他人证件" attributes:@{NSFontAttributeName : font,NSForegroundColorAttributeName:F_101010_COLOR,NSParagraphStyleAttributeName:paragraphStyle}]];
        [text appendAttributedString:[[NSAttributedString alloc] initWithString:@"\n" attributes:nil]];
        [text appendAttributedString:[[NSAttributedString alloc] initWithString:@"拍摄时确保证件边框完整、字体清晰" attributes:@{NSFontAttributeName : font,NSForegroundColorAttributeName:F_101010_COLOR}]];
        _descLabel.numberOfLines = 2;
        _descLabel.attributedText = text;
    }
    return _descLabel;
}

- (UIButton *)uploadButton {
    if (_uploadButton == nil) {
        _uploadButton = [[UIButton alloc]initWithTitle:@"上传健康证" fontSize:14 titleColor:[UIColor whiteColor] bgColor:COLOR_THEMEGRENN];
        [_uploadButton addBlockForControlEvents:(UIControlEventTouchUpInside) block:^(id  _Nonnull sender) {
 
        }];
    }
    return _uploadButton;
}

- (XVHealthCardTipView *)tip1View {
    if (_tip1View == nil) {
        _tip1View  = [[XVHealthCardTipView alloc]init];
        [_tip1View title:@" 边框缺失" imageName:nil];
    }
    return _tip1View;
}

- (XVHealthCardTipView *)tip2View {
    if (_tip2View == nil) {
        _tip2View  = [[XVHealthCardTipView alloc]init];
        [_tip2View title:@" 照片模糊" imageName:nil];
    }
    return _tip2View;
}
- (XVHealthCardTipView *)tip3View {
    if (_tip3View == nil) {
        _tip3View  = [[XVHealthCardTipView alloc]init];
        [_tip3View title:@" 信息遮挡" imageName:nil];
    }
    return _tip3View;
}
- (XVHealthCardTipView *)tip4View {
    if (_tip4View == nil) {
        _tip4View  = [[XVHealthCardTipView alloc]init];
        [_tip4View title:@" 拍复印件" imageName:nil];
    }
    return _tip4View;
}


@end
