//
// HotelSearchDetailsTopCell.m
// Project
//
// Created by Ziv on 16/1/6.
//
//

#import "HotelSearchDetailTopCell.h"
#import "CocoaUtils.h"
#import "DrawUtils.h"
#import <SDWebImage/UIImageView+WebCache.h>

@interface HotelSearchDetailTopCell ()
@property (nonatomic, weak) IBOutlet UIView *stackView;
@property (nonatomic, weak) IBOutlet UIImageView *addressIcon;
@property (nonatomic, weak) IBOutlet NSLayoutConstraint *widthConstraint;
@property (nonatomic, weak) IBOutlet NSLayoutConstraint *alignLeftConstraint;
@property (nonatomic, weak) IBOutlet NSLayoutConstraint *alignRightConstraint;
@end

@implementation HotelSearchDetailTopCell

- (void)awakeFromNib {
	[super awakeFromNib];
	// Initialization code
	self.pointDescriptionLabel.text = nil;
	self.addressIcon.image = [DrawUtils imageWithFAKIcon:[FAKFontAwesome mapMarkerIconWithSize:24] fillColor:[UIColor lightGrayColor]];

	[CocoaUtils fillSeparatorOfCell:self];
}

- (void)updateConstraints {
	if (self.pointDescriptionLabel.attributedText || self.pointDescriptionLabel.text) {
		self.alignLeftConstraint.priority = 1;
		self.alignRightConstraint.priority = UILayoutPriorityRequired - 1;
	} else if (self.amenityImageView.image) {
		self.alignLeftConstraint.priority = UILayoutPriorityRequired - 1;
		self.alignRightConstraint.priority = 1;
	}

	[super updateConstraints];
}

#pragma mark - Public

- (void)setTripAdvisorImageWithURLString:(NSString *)urlString {
	[self.tripadvisorImgView sd_setImageWithURL:urlString completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
		self.widthConstraint.constant = image ? ceil(CGRectGetHeight(self.tripadvisorImgView.frame) * image.size.width / image.size.height) : 0;
	}];
}

@end
