//
//  KWMNewHomeCell.m
//  iCemarose
//
//  Created by HouWeiBin on 2017/6/2.
//  Copyright © 2017年 kollway. All rights reserved.
//

#import "KWMNewHomeCell.h"
#import "UIView+Prettify.h"
#import "KWMStringUtil.h"
#import "KWMImageUtil.h"
#import "UIImageView+WebCache.h"
#import "NSLayoutConstraint+Multiplier.h"
#import "UIColor+SAMAdditions.h"


@interface KWMNewHomeCell()

@property(nonatomic,weak) IBOutlet UILabel *lbBrand;

@property(nonatomic,weak) IBOutlet UILabel *lbName;

@property(nonatomic,weak) IBOutlet UILabel *lbPrice;

@property(nonatomic,weak) IBOutlet UIImageView *ivProduct;

@property(nonatomic,weak) IBOutlet UIView *vImageContentView;

@property(nonatomic,weak) IBOutlet NSLayoutConstraint *heightDetail;

@property(nonatomic,weak) IBOutlet NSLayoutConstraint *precentOfProductImageView;

@end

@implementation KWMNewHomeCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [self.vContent initDefaultShadow];
}

-(void)setSingleShow:(BOOL)singleShow{
    if(singleShow){
        NSTextAlignment textAlignment = NSTextAlignmentCenter;
        self.lbBrand.textAlignment = textAlignment;
        self.lbName.textAlignment = textAlignment;
        self.lbPrice.textAlignment = textAlignment;
        self.lbName.numberOfLines = 1;
        self.lbBrand.numberOfLines = 1;
//        self.precentOfProductImageView = [self.precentOfProductImageView updateMultiplier:1];
//        self.vImageContentView.backgroundColor = [UIColor sam_colorWithHex:@"F1929A"];
    }
}


-(void)setProduct:(BUYProduct *)product{
    _product = product;
    if(product){
        NSString *imageUrl = [KWMImageUtil getProductImageUrl:product ImageSize:SmallImage];
        NSURL *imageURL = [NSURL URLWithString:imageUrl];
        [self.ivProduct sd_setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@"ic_loading"]];
        self.lbBrand.text = product.vendor;
        self.lbName.text = product.title;
        if(product.variantsArray.count>0){
            BUYProductVariant *variant = product.variantsArray.firstObject;
//            self.lbPrice.text = [KWMStringUtil price:variant.price];
            self.lbPrice.text = variant.price.priceValueFormatted;
        }
    }
}

+(NSInteger)acturlHeight:(BUYProduct *)product width:(NSInteger)width{
    NSInteger lbNameWidth = width - 60;
    UIFont *font = [UIFont systemFontOfSize:9];
    if(SYSTEM_VERSION_LESS_THAN(@"9.0")){
        [UIFont fontWithName:@"PingFang SC" size:9];
    }
    NSInteger lbNameHeight = [KWMStringUtil getLabelHeight:product.title labelFont:font textWidth:lbNameWidth].height;
    return width + 50 +lbNameHeight;
}

@end