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

#import "XVSettingTableViewCell.h"

@interface XVSettingTableViewCell()

@property (nonatomic, strong) UIView *lineView;

@property (nonatomic, strong) UILabel *titleLabel;

@property (nonatomic, strong) UIImageView *userImageView;

@property (nonatomic, strong) UIImageView *idImageView;

@property (nonatomic, strong) UILabel *subTitleLabel;

@property (nonatomic, strong) UIImageView  *arrowImageView;


@end

@implementation XVSettingTableViewCell

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

- (void)setDict:(NSDictionary *)dict {
    _dict = dict;
    
    int type = [dict[@"type"] intValue];
    if (type == 1) {
        [self.contentView addSubview:self.userImageView];
        [self.userImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(66, 66));
            make.centerY.mas_equalTo(self.contentView);
            make.right.mas_equalTo(self.contentView).mas_offset(-13);
        }];
        
    }else if(type == 2) {
        [self.contentView addSubview:self.idImageView];
        [self.idImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(47, 47));
            make.centerY.mas_equalTo(self.contentView);
            make.right.mas_equalTo(self.contentView).mas_offset(-13);
        }];
        
        [self.contentView addSubview:self.subTitleLabel];
        [self.subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.contentView);
            make.right.mas_equalTo(self.idImageView.mas_left).mas_offset(-7);
        }];
    }else if( type == 3 || type == 4) {
   
        
        [self.contentView addSubview:self.subTitleLabel];
        [self.subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.contentView);
            make.right.mas_equalTo(self.contentView.mas_left).mas_offset(-38);
        }];
        
        if ( type == 4) {
            [self.contentView addSubview:self.arrowImageView];
            [self.arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.size.mas_equalTo(CGSizeMake(20, 20));
                make.centerY.mas_equalTo(self.contentView);
                make.right.mas_equalTo(self.contentView).mas_offset(-5);
            }];
        }
    }
    
    self.titleLabel.text = dict[@"title"];

    
}
- (void)setupUI {
    
    [self.contentView addSubview:self.lineView];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView).mas_offset(15);
        make.right.mas_equalTo(self.contentView).mas_offset(-15);
        make.bottom.mas_equalTo(self.contentView);
        make.height.mas_equalTo(1);
    }];
    
    [self.contentView addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView).mas_offset(15);
        make.centerY.mas_equalTo(self.contentView);
    }];
    

    
}

- (UIView *)lineView {
    if (_lineView == nil) {
        _lineView = [[UIView alloc]init];
        _lineView.backgroundColor = F7_3_COLOR;
    }
    return _lineView;
}

- (UILabel *)titleLabel {
    if(_titleLabel == nil) {
        _titleLabel = [[UILabel alloc]initWithText:@"标题" textColor:F_606060_COLOR textAlignment:(NSTextAlignmentLeft) fontSize:14];
    }
    return _titleLabel;
}

- (UIImageView *)userImageView {
    if(_userImageView == nil) {
        _userImageView = [[UIImageView alloc]initWithImageName:@"qishi-head"];
    }
    return _userImageView;
}

- (UIImageView *)idImageView {
    if (_idImageView == nil) {
        _idImageView = [[UIImageView alloc]initWithImageName:@"图标 15"];
    }
    return _idImageView;
}

- (UILabel *)subTitleLabel {
    if(_subTitleLabel == nil) {
        _subTitleLabel = [[UILabel alloc]initWithText:@"标题" textColor:F_101010_COLOR textAlignment:(NSTextAlignmentRight) fontSize:14];
    }
    return _subTitleLabel;

}

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

}

@end
