//
//  SLNearbyPeopleCell.m
//  SLAiELTS
//
//  Created by Gusont on 2023/5/10.
//

#import "SLNearbyPeopleCell.h"

@implementation SLNearbyPeopleCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    [self.interestcrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.userNameLabel.mas_bottom).offset(4);
        make.left.equalTo(self.userNameLabel.mas_left).offset(-2);
        make.height.mas_equalTo(24);
        make.right.equalTo(self.contentView.mas_right).offset(-16);
    }];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)confignCellWith:(SLFriendsModel *)model {
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:[model getUserHeadUrl]]];
    self.userNameLabel.text = model.userName;
    self.distanceLabel.text = model.distance;
    self.sexImageView.image = [model.sex isEqualToString:@"女"] ? ImageName(@"icon_sex_woman_r") : ImageName(@"icon_sex_man_b");
    [self.interestcrollView.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [obj removeFromSuperview];
        obj = nil;
    }];
    NSArray *interests = [model.interests componentsSeparatedByString:@","];
    __block CGFloat x = 0;
    [interests enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL * _Nonnull stop) {
        CGRect rect = YMBoundWidth(obj, [UIFont systemFontOfSize:12]);
        CGFloat width = rect.size.width;
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
        label.text = obj;
        label.frame = CGRectMake(x, 0, width + 24, 24);
        label.textColor = SLColor(@"#636366");
        label.font = [UIFont systemFontOfSize:12];
        label.backgroundColor = SLColor(@"#F2F2F7");
        label.layer.cornerRadius = 12.0;
        label.textAlignment = NSTextAlignmentCenter;
        label.clipsToBounds = YES;
        [self.interestcrollView addSubview:label];
        x += width + 28;
    }];
    self.interestcrollView.contentSize = CGSizeMake(x, 24);
}

- (UIScrollView *)interestcrollView {
    if (!_interestcrollView) {
        _interestcrollView = [[UIScrollView alloc] initWithFrame:CGRectZero];
        _interestcrollView.bounces = NO;
        _interestcrollView.showsVerticalScrollIndicator = NO;
        _interestcrollView.showsHorizontalScrollIndicator = NO;
        [self.contentView addSubview:_interestcrollView];
    }
    return _interestcrollView;
}

@end
