//
//  AJPhotoGroupCell.m
//  AJPhotoPicker
//
//  Created by AlienJunX on 15/11/2.
//  Copyright (c) 2015 AlienJunX
//
//  This source code is licensed under the MIT-style license found in the
//  LICENSE file in the root directory of this source tree.
//

#import "AJPhotoGroupCell.h"

@interface AJPhotoGroupCell()

@property (nonatomic, strong) UIImageView *groupImageView;
@property (nonatomic, strong) UILabel *groupTextLabel;
@end


@implementation AJPhotoGroupCell

- (void)bindModel:(TZAlbumModel *)model{
  //  self.assetsGroup = assetsGroup;
    self.backgroundColor = [UIColor whiteColor];
    if (self.groupImageView == nil) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(14, 5, 50, 50)];
        imageView.contentMode = UIViewContentModeScaleAspectFill;
        imageView.layer.masksToBounds = YES;
        //imageView.backgroundColor = [UIColor greenColor];
        [self.contentView addSubview:imageView];
        self.groupImageView = imageView;
    }
    
    if (self.groupTextLabel == nil) {
        UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(70, 5, [UIScreen mainScreen].bounds.size.width-70, 50)];
        textLabel.font = [UIFont boldSystemFontOfSize:16];
        textLabel.backgroundColor = [UIColor clearColor];
        textLabel.numberOfLines = 0;
        [self.contentView addSubview:textLabel];
        self.groupTextLabel = textLabel;
    }
    
    [[TZImageManager manager] getPostImageWithAlbumModel:model completion:^(UIImage *postImage) {
        self.groupImageView.image = postImage;
        [self setNeedsLayout];
    }];
    
    
    NSString *curStr1 = [NSString stringWithFormat:@"%@",model.name];
    NSString *curStr2 = [NSString stringWithFormat:@"%ld",(long)model.count];
    NSString *totalStr = [[NSString alloc] initWithFormat:@"%@\n%@",curStr1,curStr2];
    
    NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:totalStr];
    
    NSRange redRange = NSMakeRange([totalStr rangeOfString:curStr2].location, [totalStr rangeOfString:curStr2].length);
    [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor hwColor:@"#959799" alpha:1.0] range:redRange];
    [noteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14.0] range:redRange];
    // 设置行间距
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:5];        //设置行间距
    
    [noteStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [totalStr  length])];

    
    self.groupTextLabel.attributedText = noteStr;
    //self.groupTextLabel.text = ;
    
    
    if (self.selectButton == nil) {
        UIButton *but = [[UIButton alloc] init];
        [but setBackgroundImage:[UIImage imageNamed:@"upload_file_uncheck"] forState:UIControlStateNormal];
        [but setBackgroundImage:[UIImage imageNamed:@"upload_file_check"] forState:UIControlStateSelected];
        [self.contentView addSubview:but];
        
        but.frame = CGRectMake([UIScreen mainScreen].bounds.size.width- 15- 25, (60 - 25)/2.0, 25, 25);
//        [but mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.width.mas_equalTo(20);
//            make.height.mas_equalTo(20);
//            make.right.mas_equalTo(-15);
//            make.centerY.equalTo(self.contentView.mas_centerX).offset(0.f);
//        }];
        
        self.selectButton = but;
    }
    
    self.selectButton.selected = NO;
}

@end
