//
//  FriendListCell.m
//  AIIM
//
//  Created by gan on 2025/4/6.
//
#import "FriendListCell.h"
#import <SDWebImage/UIImageView+WebCache.h>

@interface FriendListCell()

@end

@implementation FriendListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupViews];
    }
    return self;
}

- (void)setupViews {
    _avatar =[[UIImageView alloc] init];
    _avatar.frame=CGRectMake(8, 8, 50, 50);
    _avatar.contentMode = UIViewContentModeScaleAspectFill;
    _avatar.layer.cornerRadius = 25;
    _avatar.layer.masksToBounds = YES;
    _avatar.backgroundColor=[UIColor lightGrayColor];
    [self.contentView addSubview:_avatar];
    
    _name = [[UILabel alloc] init];
    _name.frame=CGRectMake(68, 8, 250, 50);
    _name.backgroundColor=[UIColor clearColor];
    [_name setFont:[UIFont boldSystemFontOfSize:18]];
    [_name setTextColor:[UIColor whiteColor]];
    
    [self.contentView addSubview:_name];
    
    
}

- (void)fillWithData:( NSDictionary*)data {
    
//    NSLog(@"fillWithData:%@",data);
    NSString *avatar =data[@"avatar"];
    if([avatar isKindOfClass:[NSString class]]){
        
    }
    else{
        avatar = @"";
    }
   [self.avatar sd_setImageWithURL:[NSURL URLWithString:avatar] placeholderImage:[UIImage imageNamed:@"Avatar"]];
    self.name.text = data[@"name"];
    
    // tell constraints they need updating
    [self setNeedsUpdateConstraints];

    // update constraints now so we can animate the change
    [self updateConstraintsIfNeeded];

    [self layoutIfNeeded];
}

@end
