//
//  XVCustomBarView.m
//  fastservice
//
//  Created by xuning on 2/4/24.
//  Copyright © 2024 FastService. All rights reserved.
//

#import "XVCustomBarView.h"
@interface XVCustomBarView()

@property (nonatomic, strong) UIView *jobStatusView;

@property (nonatomic, strong) UIImageView *arrowImageView;


@end

@implementation XVCustomBarView

- (instancetype)initWithFrame:(CGRect)frame {
    if(self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        [self setupUI];
    }
    return self;
}


- (void)setupUI {
 
    [self addSubview:self.centerButton];
    [self.centerButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self).mas_offset(11);
        make.size.mas_equalTo(CGSizeMake(30, 30));
        make.bottom.mas_equalTo(self).mas_offset(-8);
    }];
    
    [self addSubview:self.remindButton];
    [self.remindButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self).mas_offset(-11);
        make.size.mas_equalTo(CGSizeMake(30, 30));
        make.bottom.mas_equalTo(self.centerButton);
    }];
    
    
    [self addSubview:self.locationButton];
    [self.locationButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.remindButton.mas_left).mas_offset(-11);
        make.size.mas_equalTo(CGSizeMake(30, 30));
        make.bottom.mas_equalTo(self.centerButton);
    }];

    kViewBorderRadius(self.centerButton, 15, 0, [UIColor clearColor]);
    kViewBorderRadius(self.remindButton, 15, 0, [UIColor clearColor]);
    kViewBorderRadius(self.locationButton, 15, 0, [UIColor clearColor]);

    
    [self addSubview:self.jobStatusView];
    [self.jobStatusView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(80, 34));
        make.left.mas_equalTo(self.centerButton.mas_right).mas_equalTo(11);
        make.centerY.mas_equalTo(self.centerButton);
    }];
    
    kViewBorderRadius(self.jobStatusView, 12, 0, [UIColor clearColor]);
    
    [self.jobStatusView addSubview:self.statusLabel];
    [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.jobStatusView);
        make.left.mas_equalTo(self.jobStatusView).mas_offset(6);
    }];
    
    [self.jobStatusView addSubview:self.arrowImageView];
    [self.arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.jobStatusView);
        make.right.mas_equalTo(self.jobStatusView).mas_offset(-5);
    }];

    
}

- (UIButton *)centerButton {
    if(_centerButton == nil) {
        _centerButton = [[UIButton alloc]init];
        [_centerButton setImage:IMG(@"YTSBAz7") forState:UIControlStateNormal];
        _centerButton.backgroundColor = F7_3_COLOR;
    }
    return _centerButton;
}

- (UIButton *)remindButton {
    if(_remindButton == nil) {
        _remindButton = [[UIButton alloc]init];
        [_remindButton setImage:IMG(@"DvTTSAI") forState:UIControlStateNormal];
        _remindButton.backgroundColor = F7_3_COLOR;
    }
    return _remindButton;
}

- (UIButton *)locationButton {
    if(_locationButton == nil) {
        _locationButton = [[UIButton alloc]init];
        [_locationButton setImage:IMG(@"wrHblyX") forState:UIControlStateNormal];
        _locationButton.backgroundColor = F7_3_COLOR;
    }
    return _locationButton;
}

- (UIView *)jobStatusView {
    if(_jobStatusView == nil) {
        _jobStatusView = [[UIView alloc]init];
        _jobStatusView.backgroundColor = F7_3_COLOR;
    }
    return _jobStatusView;
}
- (YYLabel *)statusLabel {
    if(_statusLabel == nil) {
        _statusLabel = [[YYLabel alloc]init];
        _statusLabel.attributedText = [self setStatus:@" 已停工" imageName:@"antFill-stop yTPnBNx"];
    }
    return _statusLabel;
}

- (UIImageView *)arrowImageView {
    if(_arrowImageView == nil) {
        _arrowImageView = [[UIImageView alloc]initWithImageName:@"if-caret-down"];
    }
    return _arrowImageView;
}

- (NSMutableAttributedString *)setStatus:(NSString *)status imageName:(NSString *)imageName {
    
    NSMutableAttributedString *text = [NSMutableAttributedString new];


    UIImageView *imageView = [[UIImageView alloc]initWithImageName:@"antFill-stop"];
    imageView.frame = CGRectMake(0, 0, 8, 8);
    NSMutableAttributedString *attachment = [NSMutableAttributedString attachmentStringWithContent:imageView contentMode:UIViewContentModeBottom attachmentSize:CGSizeMake(8, 8) alignToFont:[UIFont systemFontOfSize:14] alignment:YYTextVerticalAlignmentCenter];

    [text appendAttributedString: attachment];

    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:status];
    str.font = [UIFont systemFontOfSize:14];
    str.color = F_415058_COLOR;
    
    [text appendAttributedString:str];

    return text;
    
    
}
@end
