//
//  diskListTableCell.m
//  隐私保护
//
//  Created by xd h on 2024/1/23.
//

#import "diskListTableCell.h"

@implementation diskListTableCell
@synthesize cellBgView;
@synthesize mImageView;
@synthesize titleLabel;
@synthesize titleLabel2;
@synthesize rightImage;
@synthesize lineView;
@synthesize checkButton;

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

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

- (void)drawView
{
    cellBgView = [[UIView alloc] init];
    [self.contentView addSubview:cellBgView];
    //cellBgView.backgroundColor = [UIColor whiteColor];
    [cellBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0.f);
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        make.right.mas_equalTo(0.f);
        //make.width.mas_equalTo(SCREEN_W - 2*15.f);
    }];
    
    /*图片*/
    mImageView = [[UIImageView alloc] init];
    [mImageView setBackgroundColor:[UIColor clearColor]];
    mImageView.image = [UIImage imageNamed:@"uploadFile_disk_icon"];
    [cellBgView addSubview:mImageView];
    [mImageView setContentMode:(UIViewContentModeScaleAspectFill)];
    [mImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.width.mas_equalTo(36);
        make.height.mas_equalTo(36);
        make.centerY.equalTo(cellBgView.mas_centerY);
    }];
    
    /*右侧箭头*/
    rightImage = [[UIImageView alloc] init];
    [rightImage setBackgroundColor:[UIColor clearColor]];
    [rightImage setImage:[UIImage imageNamed:@"cell_right_access"]];
    [cellBgView addSubview:rightImage];
    [rightImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(28);
        make.right.mas_equalTo(-15.f);
        make.height.mas_equalTo(28);
        make.centerY.equalTo(cellBgView.mas_centerY);
    }];
    rightImage.hidden = YES;
    
    checkButton = [[UIButton alloc] init];
    [checkButton setImage:[UIImage imageNamed:@"upload_file_uncheck"] forState:UIControlStateNormal];
    [checkButton setImage:[UIImage imageNamed:@"upload_file_check"] forState:UIControlStateSelected];
    [cellBgView addSubview:checkButton];
    [checkButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-18.f);
        make.centerY.equalTo(cellBgView.mas_centerY);
        make.width.mas_equalTo(36.f);
        make.height.mas_equalTo(36.f);
    }];
    
    [checkButton addTarget:self action:@selector(maskSwitchPressed:) forControlEvents:(UIControlEventTouchUpInside)];
    
    
    /**标题*/
    titleLabel = [[UILabel alloc] init];
    [cellBgView addSubview:titleLabel];
    titleLabel.font = [UIFont boldSystemFontOfSize:14.f];
    titleLabel.numberOfLines = 0;
    [titleLabel setTextColor:HW0A132BColor];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(mImageView.mas_right).offset(5.f);
        make.right.equalTo(checkButton.mas_left).offset(-5.f);
        //make.centerY.equalTo(cellBgView.mas_centerY);
        make.top.mas_equalTo(15.f);
    }];
    
    /**副标题*/
    titleLabel2 = [[UILabel alloc] init];
    [cellBgView addSubview:titleLabel2];
    titleLabel2.font = [UIFont systemFontOfSize:12.f];
    //[titleLabel2 setTextAlignment:(NSTextAlignmentRight)];
    [titleLabel2 setTextColor:HW666666Color];
    [titleLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-53.f);
        make.left.mas_equalTo(titleLabel.mas_left);
        //make.centerY.equalTo(cellBgView.mas_centerY);
        make.bottom.mas_equalTo(-15);
    }];
    
    lineView = [[UIView alloc] init];
    [lineView setBackgroundColor:HW979797Color10];
    [cellBgView addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-15.f);
        make.left.mas_equalTo(15.f);
        make.bottom.mas_equalTo(0);
        make.height.mas_equalTo(1.f);
    }];
    
    
    //titleLabel2.text = @"30GB/128GB";
}


- (void)setCurModel:(cloudPhoneExtraFileModel *)curModel
{
    titleLabel.text = curModel.name;
    
    CGFloat extraAvableSizeF = curModel.extraAvableSize / 1024.0 /1024.0/1024.0;
    CGFloat extraTotalSizeF = curModel.extraTotalSize / 1024.0 /1024.0/1024.0;
    
    titleLabel2.text = [[NSString alloc] initWithFormat:@"%.1fGB/%.1fGB",extraAvableSizeF,extraTotalSizeF];
    
    checkButton.selected = curModel.isCheckType;
    
    if(checkButton.selected){
        cellBgView.backgroundColor = [UIColor hwColor:@"#EEFBFF" alpha:1.0];
    }
    else{
        cellBgView.backgroundColor = [UIColor whiteColor];
    }
}

- (void)maskSwitchPressed:(UIButton *)maskSwitch{
    maskSwitch.selected = !maskSwitch.selected;
    
    if(_didClickSwitch){
        _didClickSwitch(maskSwitch.selected);
    }
}

@end

