//
//  HotelInterception.m
//  Project
//
//  Created by Vae on 2018/10/8.
//

#import "HotelInterception.h"
#import <Foundation/Foundation.h>
#import "HotelSearchListViewController.h"
#import "InterceptionProtocol.h"
#import "Lang.h"
#import "CocoaUtils.h"

@implementation HotelInterception

-(BOOL)handleUrl:(NSURL *)url{
	if ([url.path hasSuffix:@"hotel.do"]) {
		[self routerViewControler:url.absoluteString];
		return YES;
	}
	return NO;
}

-(void)routerViewControler:(NSString *)url{
	NSURL *tempUrl = [NSURL URLWithString:url];
	NSString *query = [tempUrl.query stringByRemovingPercentEncoding];
	HotelSearchListViewController *viewController = [[HotelSearchListViewController alloc] init];
	viewController.hidesBottomBarWhenPushed = YES;
	viewController.canEdit = YES;
	HotelSearchPaginationParam *hotelParam = [[HotelSearchPaginationParam alloc] init];
	hotelParam.destination = [query componentsSeparatedByString:@"="].lastObject;
	hotelParam.checkIn = [[DateFormatUtils ISO_DATE_FORMAT] format:[DateUtils addDays:[NSDate date] amount:3]];
	hotelParam.checkOut = [[DateFormatUtils ISO_DATE_FORMAT] format:[DateUtils addDays:[NSDate date] amount:4]];
	RoomBasedCountData *roomData = [[RoomBasedCountData alloc] initWithRoomNo:1];
	roomData.adultCount = 2;
	roomData.childCount = 0;
	hotelParam.roomInfo = @[roomData];
	viewController.hotelSearchParam = hotelParam;
	UIViewController *this = [CocoaUtils topMostViewController];
	[this.navigationController pushViewController:viewController animated:YES];
}
@end
