//
//  RDSRoomCell.m
//  Temperature
//
//  Created by RD on 2022/10/31.
//

#import "RDSRoomCell.h"

@interface RDSRoomCell()

@property (nonatomic, strong) UIView *containerView;

@property (nonatomic, strong) UIImageView *iconView;
@property (nonatomic, strong) UILabel *roomNameLabel;
@property (nonatomic, strong) UILabel *deviceTypeLabel;
@property (nonatomic, strong) UIView *lineView;
@property (nonatomic, strong) UIView *pointView;
@property (nonatomic, strong) UILabel *statusLabel;
@property (nonatomic, strong) UISwitch *deviceSwitch;

@end

@implementation RDSRoomCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self configSubviews];
    }
    return self;
}


- (void)setModel:(RDSRoomModel *)model {
    _model = model;
    self.roomNameLabel.text = model.name;
    self.iconView.image = [UIImage imageNamed:@"icon_fluorine_main_controller"];
    self.deviceTypeLabel.text = @"主控制器";
    self.pointView.backgroundColor = [UIColor colorWithHexString:@"#14C9C8"];
    self.statusLabel.textColor = [UIColor colorWithHexString:@"#14C9C8"];
    self.statusLabel.text = @"温度24°C 湿度38%";
}


- (void)configSubviews {
    [self.contentView addSubview:self.containerView];
    [self.containerView addSubview:self.iconView];
    [self.containerView addSubview:self.roomNameLabel];
    [self.containerView addSubview:self.deviceTypeLabel];
    [self.containerView addSubview:self.lineView];
    [self.containerView addSubview:self.pointView];
    [self.containerView addSubview:self.statusLabel];
    [self.containerView addSubview:self.deviceSwitch];
    
    [self.containerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsZero);
    }];
    
    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(self.containerView).offset(20);
        make.size.mas_equalTo(CGSizeMake(40, 40));
        make.bottom.equalTo(self.containerView).offset(-20);
    }];
    
    [self.deviceSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(48, 24));
        make.centerY.mas_equalTo(0);
        make.right.equalTo(self.containerView).offset(-16);
    }];
    
    [self.roomNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.mas_right).offset(12);
        make.top.equalTo(self.containerView).offset(18);
        make.right.equalTo(self.deviceSwitch.mas_left).offset(-12);
        make.height.mas_equalTo(23);
    }];
    
    [self.deviceTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.roomNameLabel);
        make.bottom.equalTo(self.containerView).offset(-18);
        make.height.mas_equalTo(17);
    }];
    [self.deviceTypeLabel setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(1, 8));
        make.centerY.equalTo(self.deviceTypeLabel);
        make.left.equalTo(self.deviceTypeLabel.mas_right).offset(8);
    }];
    
    [self.pointView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(5, 5));
        make.centerY.equalTo(self.deviceTypeLabel);
        make.left.equalTo(self.lineView.mas_right).offset(8);
    }];
    
    [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.height.equalTo(self.deviceTypeLabel);
        make.left.equalTo(self.pointView.mas_right).offset(5);
        make.right.equalTo(self.roomNameLabel);
    }];
}

- (UIView *)containerView {
    if (!_containerView) {
        _containerView = [[UIView alloc] init];
        _containerView.backgroundColor = UIColor.whiteColor;
        _containerView.layer.cornerRadius = 6;
    }
    return _containerView;
}

- (UIImageView *)iconView {
    if (!_iconView) {
        _iconView = [[UIImageView alloc] init];
    }
    return _iconView;
}

- (UILabel *)roomNameLabel {
    if (!_roomNameLabel) {
        _roomNameLabel = [[UILabel alloc] init];
        _roomNameLabel.font = [UIFont pingFangSCMediumOfSize:16];
        _roomNameLabel.textColor = [UIColor colorWithHexString:@"#333333"];
    }
    return _roomNameLabel;
}

- (UILabel *)deviceTypeLabel {
    if (!_deviceTypeLabel) {
        _deviceTypeLabel = [[UILabel alloc] init];
        _deviceTypeLabel.font = [UIFont pingFangSCRegularOfSize:12];
        _deviceTypeLabel.textColor = [UIColor colorWithHexString:@"#999999"];
    }
    return _deviceTypeLabel;
}

- (UIView *)lineView {
    if (!_lineView) {
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = [UIColor colorWithHexString:@"#999999"];
    }
    return _lineView;
}

- (UIView *)pointView {
    if (!_pointView) {
        _pointView = [[UIView alloc] init];
        _pointView.layer.cornerRadius = 2.5;
    }
    return _pointView;
}

- (UILabel *)statusLabel {
    if (!_statusLabel) {
        _statusLabel = [[UILabel alloc] init];
        _statusLabel.font = [UIFont pingFangSCRegularOfSize:12];
    }
    return _statusLabel;
}

- (UISwitch *)deviceSwitch {
    if (!_deviceSwitch) {
        _deviceSwitch = [[UISwitch alloc] init];
        _deviceSwitch.onTintColor = [UIColor colorWithHexString:@"#14C9C8"];
        _deviceSwitch.tintColor = [UIColor colorWithHexString:@"#D9D9D9"];
    }
    return _deviceSwitch;
}

@end
