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

#import "XVHealthCardTipView.h"

@interface XVHealthCardTipView()

@property (nonatomic, strong) UIImageView *imageView;

@property (nonatomic, strong) YYLabel *label;


@end

@implementation XVHealthCardTipView

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

- (void)title:(NSString *)title imageName:(NSString *)imageName {
    
    NSMutableAttributedString *text = [NSMutableAttributedString new];
    UIFont *font = [UIFont systemFontOfSize:12];
    UIColor *color = [UIColor colorWithHexString:@"#737272"];

    // UIView attachment
    UIImageView *imageView = [[UIImageView alloc]initWithImageName:@"if-close-circled 1"];
    imageView.size = CGSizeMake(17, 17);
    
    NSMutableAttributedString *attachment = [NSMutableAttributedString attachmentStringWithContent:imageView contentMode:UIViewContentModeBottom attachmentSize:imageView.size alignToFont:font alignment:YYTextVerticalAlignmentCenter];

    [text appendAttributedString: attachment];
    

    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:title];
    str.font = font;
    str.color = color;
    
    [text appendAttributedString:str];
    
    
    _label.attributedText = text;
    _label.textAlignment = NSTextAlignmentCenter;
    
}
- (void)setupUI {
    
    [self addSubview:self.imageView];
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(self);
        make.height.mas_equalTo(53);
    }];
    kViewBorderRadius(self.imageView, 6, 0, [UIColor whiteColor]);
    
    [self addSubview:self.label];
    [self.label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(self);
        make.top.mas_equalTo(self.imageView.mas_bottom).mas_offset(5);
    }];
    
}

- (UIImageView *)imageView {
    if (_imageView == nil) {
        _imageView = [[UIImageView alloc]init];
        _imageView.backgroundColor = [UIColor whiteColor];
        
    }
    return _imageView;
}

- (YYLabel *)label {
    if (_label == nil) {
        _label = [[YYLabel alloc]init];
        
        NSMutableAttributedString *text = [NSMutableAttributedString new];
        UIFont *font = [UIFont systemFontOfSize:12];
        UIColor *color = [UIColor colorWithHexString:@"#737272"];

        // UIView attachment
        UIImageView *imageView = [[UIImageView alloc]initWithImageName:@"if-close-circled 1"];
        imageView.size = CGSizeMake(17, 17);
        
        NSMutableAttributedString *attachment = [NSMutableAttributedString attachmentStringWithContent:imageView contentMode:UIViewContentModeBottom attachmentSize:imageView.size alignToFont:font alignment:YYTextVerticalAlignmentCenter];
    
        [text appendAttributedString: attachment];
        
    
        NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@" 边框缺失"];
        str.font = font;
        str.color = color;
        
        [text appendAttributedString:str];
        
        
        _label.attributedText = text;
        _label.textAlignment = NSTextAlignmentCenter;
        

        
    }
    return _label;
}

@end
