//
// BusSearchBoxCell.m
// MyProject
//
// Created by Ziv on 15-6-1.
//
//

#import "CustomDualSubtitleCell.h"
#import "SDK.h"
#import "DrawUtils.h"
#import "ImageUtils.h"
#import "UIConstants.h"
#import <PureLayout/PureLayout.h>
#import "Vars.h"

@interface CustomDualSubtitleCell ()
@property (nonatomic, weak) IBOutlet UIView *separatorView;
@property (nonatomic, weak) IBOutlet UIView *topReferenceView;
@property (nonatomic, weak) IBOutlet UIView *bottomReferenceView;
@property (nonatomic, weak) IBOutlet NSLayoutConstraint *separatorHeight;
@end

@implementation CustomDualSubtitleCell

- (void)awakeFromNib {
	[super awakeFromNib];
	// Initialization code
	self.separatorHeight.constant = 1 / [UIScreen mainScreen].scale;
	[self.topSelectionButton setBackgroundImage:[ImageUtils imageWithColor:[UIColor darkGrayColor]] forState:UIControlStateHighlighted];
	[self.bottomSelectionButton setBackgroundImage:[ImageUtils imageWithColor:[UIColor darkGrayColor]] forState:UIControlStateHighlighted];

	[self.separatorView autoPinEdge:ALEdgeLeft toEdge:ALEdgeRight ofView:self.imageView withOffset:[UIConstants defaultTableViewCellLayoutInsets].left];
	[self.topReferenceView autoPinEdge:ALEdgeLeft toEdge:ALEdgeRight ofView:self.imageView withOffset:[UIConstants defaultTableViewCellLayoutInsets].left];
	[self.bottomReferenceView autoPinEdge:ALEdgeLeft toEdge:ALEdgeRight ofView:self.imageView withOffset:[UIConstants defaultTableViewCellLayoutInsets].left];
}

#pragma mark - public

- (UIView *)topRightView {
	return [self.contentView viewWithTag:NSStringFromSelector(@selector(topRightView)).hash];
}

- (void)setTopRightView:(UIView *)topRightView {
	if (self.topRightView != topRightView) {
		[self.topRightView removeFromSuperview];
		topRightView.tag = NSStringFromSelector(@selector(topRightView)).hash;
		[self.contentView addSubview:topRightView];

		[self.topRightView autoAlignAxis:ALAxisHorizontal toSameAxisOfView:self.topReferenceView];
		[self.topRightView autoPinEdge:ALEdgeRight toEdge:ALEdgeRight ofView:self.topReferenceView];
	}
}

- (UIView *)bottomRightView {
	return [self.contentView viewWithTag:NSStringFromSelector(@selector(bottomRightView)).hash];
}

- (void)setBottomRightView:(UIView *)bottomRightView {
	if (self.bottomRightView != bottomRightView) {
		[self.bottomRightView removeFromSuperview];
		bottomRightView.tag = NSStringFromSelector(@selector(bottomRightView)).hash;
		[self.contentView addSubview:bottomRightView];

		[self.bottomRightView autoAlignAxis:ALAxisHorizontal toSameAxisOfView:self.bottomReferenceView];
		[self.bottomRightView autoPinEdge:ALEdgeRight toEdge:ALEdgeRight ofView:self.bottomReferenceView];
	}
}

@end
