//
//  ICContactsIncompleteCell.m
//  superCleaner
//
//  Created by GY.Z on 2020/7/4.
//  Copyright © 2020 Mazy. All rights reserved.
//

#import "ICContactsIncompleteCell.h"

@implementation ICContactsIncompleteCell

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

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)configWithEvent: (EKEvent *)event seleted: (BOOL)isSelected {
    self.subTitleLabel.text = event.title;
    self.subTitleLabel.hidden = false;
    self.formatter = [[NSDateFormatter alloc] init];
    self.formatter.dateFormat = @"yyyy-MM-dd HH:dd";
    NSString *startTime = [self.formatter stringFromDate: event.startDate];
    self.nameLabel.text = startTime;
    
    if (isSelected) {
        [self.chooseBtn setImage:[UIImage imageNamed:@"contact_choosed"] forState:UIControlStateNormal];
    }else{
        [self.chooseBtn setImage:[UIImage imageNamed:@"contact_choose"] forState:UIControlStateNormal];
    }
    
    [self.chooseBtn addTarget:self action:@selector(cellChooseAction:) forControlEvents:UIControlEventTouchUpInside];
}

-(void)cellChooseAction: (UIButton *)button {
    button.selected = !button.isSelected;
//    if (button.isSelected) {
//        [self.chooseBtn setImage:[UIImage imageNamed:@"contact_choosed"] forState:UIControlStateNormal];
//    }else{
//        [self.chooseBtn setImage:[UIImage imageNamed:@"contact_choose"] forState:UIControlStateNormal];
//    }
    if (self.selectedClosure) {
        self.selectedClosure(button.isSelected);
    }
}

-(void)configWithReminder: (EKReminder *)reminder seleted: (BOOL)isSelected {
    self.subTitleLabel.text = reminder.title;
    self.subTitleLabel.hidden = false;
    self.formatter = [[NSDateFormatter alloc] init];
    self.formatter.dateFormat = @"yyyy-MM-dd HH:dd";
    NSString *completionDate = [self.formatter stringFromDate: reminder.completionDate];
    self.nameLabel.text = completionDate;
    
    if (isSelected) {
        [self.chooseBtn setImage:[UIImage imageNamed:@"contact_choosed"] forState:UIControlStateNormal];
    }else{
        [self.chooseBtn setImage:[UIImage imageNamed:@"contact_choose"] forState:UIControlStateNormal];
    }
    
    [self.chooseBtn addTarget:self action:@selector(cellChooseAction:) forControlEvents:UIControlEventTouchUpInside];
}

@end
