//
// BusVendorReviewSummaryViewController.m
// Project
//
// Created by Ziv on 16/11/8.
//
//

#import "BusVendorReviewSummaryViewController.h"
#import "SDK.h"
#import "CocoaUtils.h"
#import <HCSStarRatingView/HCSStarRatingView.h>
#import <PureLayout/PureLayout.h>
#import <SDWebImage/UIImageView+WebCache.h>
#import "Utility.h"
#import "Vars.h"

@interface BusVendorReviewSummaryViewController ()

@property (nonatomic, weak) IBOutlet UIImageView *busImgView;
@property (nonatomic, weak) IBOutlet UILabel *descriptionLabel;
@property (nonatomic, weak) IBOutlet UILabel *totalNumLabel;
@property (nonatomic, weak) IBOutlet HCSStarRatingView *overallStarRatingView;
@property (nonatomic, weak) IBOutlet UILabel *overallLabel;
@property (nonatomic, weak) IBOutlet HCSStarRatingView *cleanlinessStarRatingView;
@property (nonatomic, weak) IBOutlet UILabel *cleanlinessLabel;
@property (nonatomic, weak) IBOutlet HCSStarRatingView *punctualityStarRatingView;
@property (nonatomic, weak) IBOutlet UILabel *punctualityLabel;
@property (nonatomic, weak) IBOutlet HCSStarRatingView *serviceStarRatingView;
@property (nonatomic, weak) IBOutlet UILabel *serviceLabel;
@property (nonatomic, weak) IBOutlet HCSStarRatingView *comfortStarRatingView;
@property (nonatomic, weak) IBOutlet UILabel *comfortLabel;
@property (nonatomic, weak) IBOutlet UILabel *recommendLabel;
@property (nonatomic, weak) IBOutlet NSLayoutConstraint *imageViewHeightConstraint;

@end

@implementation BusVendorReviewSummaryViewController

- (instancetype)init {
	if (self = [super init]) {
		self.title = @"Summary";
		[[Vars appDelegate] applyDefaultConfigurationForViewController:self];
	}
	return self;
}

- (void)viewDidLoad {
	[super viewDidLoad];

	[self initStarRating];
	[self.busImgView sd_setImageWithURL:[NSURL URLWithString:self.summary.image_url] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
		if (image) {
			self.imageViewHeightConstraint.constant = CGRectGetWidth([UIScreen mainScreen].bounds) * (image.size.height / image.size.width);
		}
	}];
	self.descriptionLabel.text = self.summary.reviews_description;
	self.totalNumLabel.text = [NSString stringWithFormat:@"%d", self.summary.reviews_num];
	self.overallStarRatingView.value = self.summary.avg_overall;
	self.overallLabel.text = [NSString stringWithFormat:@"%.1f", self.summary.avg_overall];
	self.cleanlinessStarRatingView.value = self.summary.avg_cleanliness;
	self.cleanlinessLabel.text = [NSString stringWithFormat:@"%.1f", self.summary.avg_cleanliness];
	self.punctualityStarRatingView.value = self.summary.avg_punctuality;
	self.punctualityLabel.text = [NSString stringWithFormat:@"%.1f", self.summary.avg_punctuality];
	self.serviceStarRatingView.value = self.summary.avg_service;
	self.serviceLabel.text = [NSString stringWithFormat:@"%.1f", self.summary.avg_service];
	self.comfortStarRatingView.value = self.summary.avg_comfort;
	self.comfortLabel.text = [NSString stringWithFormat:@"%.1f", self.summary.avg_comfort];
	self.recommendLabel.text = [[NSString stringWithFormat:@"%.1f", self.summary.recommend_rate * 100] stringByAppendingString:@"%"];
}

#pragma mark - Private

- (void)initStarRating {
	NSArray *subviews = @[self.overallStarRatingView, self.cleanlinessStarRatingView, self.punctualityStarRatingView, self.serviceStarRatingView, self.comfortStarRatingView];
	for (HCSStarRatingView *ratingView in subviews) {
		[CocoaUtils configureStarRatingView:ratingView editing:NO];
		ratingView.tintColor = [CocoaUtils colorWithRGBs:StandardColorOrange];
	}
}

@end
