//
//  ChatAtMemberCell.m
//  AIIM
//
//  Created by qitewei on 2025/5/29.
//

#import "ChatAtMemberCell.h"

@implementation ChatAtMemberCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = UIColor.whiteColor;
        [self configUI];
    }
    return self;
}

- (void)configUI{
    [self.contentView addSubview:self.avatar];
    [self.contentView addSubview:self.nickNameLbl];
    [self.contentView addSubview:self.selectedStateBtn];
    
    [self.avatar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(48, 48));
        make.left.mas_equalTo(20);
        make.top.mas_equalTo(16);
        make.bottom.mas_equalTo(-16);
    }];
    
    [self.nickNameLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(16);
        make.left.mas_equalTo(self.avatar.mas_right).offset(20);
        make.centerY.mas_equalTo(self.avatar.mas_centerY);
    }];
    
    [self.selectedStateBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(16, 16));
        make.left.mas_equalTo(12);
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
    }];
}

- (void)setMemberDict:(NSDictionary *)memberDict{
    _memberDict = memberDict;
    [_avatar sd_setImageWithURL:getURL(memberDict[@"avatar"])];
    _nickNameLbl.text = memberDict[@"name"];
}

- (void)setIsBatchMode:(BOOL)isBatchMode{
    _isBatchMode = isBatchMode;
    self.selectedStateBtn.hidden = !isBatchMode;
    if (isBatchMode) {
        [_avatar mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(48, 48));
            make.left.mas_equalTo(46);
            make.top.mas_equalTo(16);
            make.bottom.mas_equalTo(-16);
        }];
    }else{
        [_avatar mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(48, 48));
            make.left.mas_equalTo(20);
            make.top.mas_equalTo(16);
            make.bottom.mas_equalTo(-16);
        }];
    }
}

#pragma mark lazy
- (UIImageView *)avatar{
    if (!_avatar) {
        _avatar = [[UIImageView alloc] init];
        _avatar.contentMode = UIViewContentModeScaleAspectFill;
        _avatar.layer.cornerRadius = 10.f;
        _avatar.layer.masksToBounds = YES;
    }
    return _avatar;
}

- (UILabel *)nickNameLbl{
    if (!_nickNameLbl) {
        _nickNameLbl = [[UILabel alloc] init];
        _nickNameLbl.font = SYSFONT(16);
        _nickNameLbl.textColor = UIColor.blackColor;
    }
    return _nickNameLbl;
}

- (UIButton *)selectedStateBtn{
    if (!_selectedStateBtn) {
        _selectedStateBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_selectedStateBtn setImage:kImageMake(@"file_unselected") forState:UIControlStateNormal];
        [_selectedStateBtn setImage:kImageMake(@"file_selected") forState:UIControlStateSelected];
        _selectedStateBtn.hidden = YES;
    }
    return _selectedStateBtn;
}

@end
