//
// HomeSegmenView.m
// Project
//
// Created by vae on 2018/4/2.
//

#import "HomeSegmentView.h"
#import "BlocksKit.h"
#import "PureLayout.h"
#import "Vars.h"
@interface HomeSegmentView()
@property (nonatomic, strong) UIButton *fromButton;
@property (nonatomic, strong) UIButton *toButton;
@end

@implementation HomeSegmentView

- (void)awakeFromNib {
	[super awakeFromNib];
	
	if ([Vars clientDomainId] == 3838) {
		[self.findHotelBtn removeFromSuperview];
		[_findBusBtn autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:10];
		[_findBusBtn autoPinEdgeToSuperviewEdge:ALEdgeBottom];
		[_findBusBtn autoPinEdgeToSuperviewEdge:ALEdgeTop];
		[_findBusBtn autoSetDimension:ALDimensionWidth toSize:self.bounds.size.width / 2.0 - 20];
		[_findBusHotelBtn autoPinEdge:ALEdgeLeft toEdge:ALEdgeRight ofView:_findBusBtn withOffset:20];
		[_findBusHotelBtn autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:10];
		[_findBusHotelBtn autoPinEdgeToSuperviewEdge:ALEdgeBottom];
		[_findBusHotelBtn autoPinEdgeToSuperviewEdge:ALEdgeTop];
		[_findBusHotelBtn autoSetDimension:ALDimensionWidth toSize:self.bounds.size.width / 2.0 - 20];
		[self layoutIfNeeded];
	}
	self.fromButton = self.findBusBtn;
	self.toButton = self.findBusBtn;
}

- (IBAction)finBus:(id)sender {
	self.toButton = self.findBusBtn;
	[self changeButtonStyle];
	[self.delegate findBus];
}

- (IBAction)findHotel:(id)sender {
	self.toButton = self.findHotelBtn;
	[self changeButtonStyle];
	[self.delegate findHotel];
}

- (IBAction)findBusHotel:(id)sender {
	self.toButton = self.findBusHotelBtn;
	[self changeButtonStyle];
	[self.delegate findBusHotel];
}


- (void)changeButtonStyle {
	if ([self.fromButton isEqual:self.toButton]) {
		return;
	}
	[self.fromButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
	[self.toButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
	[self.toButton setBackgroundImage:[UIImage imageNamed:@"rectangle"] forState:UIControlStateNormal];
	[self.fromButton setBackgroundImage:nil forState:UIControlStateNormal];
	self.fromButton = self.toButton;
}

@end
