//
//  HWBookmarkListCell.m
//  双子星云手机
//
//

#import "HWBookmarkListCell.h"

@interface HWBookmarkListCell ()

@property (weak, nonatomic) IBOutlet UILabel  *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel  *urlLabel;
@property (weak, nonatomic) IBOutlet UIButton *deleteBtn;

@end

@implementation HWBookmarkListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
}

- (void)setModel:(HWBookmarkModel *)model {
    
    _model = model;
    
    self.nameLabel.text = model.name;
    self.urlLabel.text = model.webUrl;
    
    if (model.isEditing) {
        [self setDeleteModel];
    }else {
        [self setNormalModel];
    }
}

- (void)setHistoryModel:(HWHistoryModel *)historyModel {
    
    _historyModel = historyModel;
    
    self.nameLabel.text = historyModel.name.length == 0 ? NSLocalizedString(@"history_unknown_heading",nil) : historyModel.name;
    self.urlLabel.text = historyModel.webUrl;
    
    self.deleteBtn.hidden = YES;
    
    [self.nameLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(6);
        make.left.mas_equalTo(10);
        make.right.mas_equalTo(-20);
    }];
    
    [self.urlLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(6);
        make.left.mas_equalTo(10);
        make.right.mas_equalTo(-20);
    }];
}

- (void)setNormalModel {
    
    self.deleteBtn.hidden = YES;
    
    [self.nameLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(6);
        make.left.mas_equalTo(35);
        make.right.mas_equalTo(-20);
    }];
    
    [self.urlLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(6);
        make.left.mas_equalTo(35);
        make.right.mas_equalTo(-20);
    }];
}

- (void)setDeleteModel {
    
    self.deleteBtn.hidden = NO;
    
    [self.nameLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(6);
        make.left.mas_equalTo(43);
        make.right.mas_equalTo(-20);
    }];
    
    [self.urlLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(6);
        make.left.mas_equalTo(43);
        make.right.mas_equalTo(-20);
    }];
}

- (IBAction)deleteBtnClick:(UIButton *)sender {
    HLog(@"删除书签");
    if ([_delegate respondsToSelector:@selector(bookmarkListCellDeleteBtnClick:)]) {
        [_delegate bookmarkListCellDeleteBtnClick:self.model];
    }
}

@end
