//
// HotelSearchListViewController.m
// Project
//
// Created by Ziv on 15/12/11.
//
//

#import "HotelSearchListViewController.h"
#import "Lang.h"
#import "SDK.h"
#import "BeanUtils.h"
#import "CocoaUtils.h"
#import "DrawUtils.h"
#import "ImageUtils.h"
#import "NetUtils.h"
#import "UIConstants.h"
#import "UIToolkit.h"
#import "DZNEmptyDataSetDefault.h"
#import "MJRefreshLocalization.h"
#import <BlocksKit/BlocksKit.h>
#import <BlocksKit/UIView+BlocksKit.h>
#import <libextobjc/EXTScope.h>
#import <MJRefresh/MJRefresh.h>
#import <SDWebImage/UIImageView+WebCache.h>
#import <PureLayout/PureLayout.h>
#import "Utility.h"
#import "AppTracker.h"
#import "HotelWS.h"
#import "HotelSearchData.h"
#import "CheckAvailabilityAndPricesResponseJsonMapper.h"
#import "SearchHotelResponseJsonMapper.h"
#import "HotelSearchListSmallCell.h"
#import "HotelSearchFilterViewController.h"
#import "HotelSearchDetailViewController.h"
#import "HotelSearchBoxViewController.h"
#import "HotelListHeaderView.h"
#import "Vars.h"
#import "RangeCalendarViewController.h"
#import "RoomBasedCountViewController.h"

@interface HotelSearchListParam () <NSCopying>
@end

@implementation HotelSearchListParam

- (instancetype)init {
	self = [super init];
	if (self) {
		self.orderBy = @"popular";
	}
	return self;
}

- (BOOL)isEqual:(id)object {
	if (self == object) {
		return YES;
	}
	if (![object isKindOfClass:self.class]) {
		return NO;
	}
    return [[BeanUtils describe:self] isEqualToDictionary:[BeanUtils describe:object]];
}

- (id)copyWithZone:(NSZone *)zone {
	HotelSearchListParam *param = [BeanUtils copyWithZone:zone origin:self];
	param.stars = [self.stars mutableCopyWithZone:zone];
	param.brands = [self.brands mutableCopyWithZone:zone];
	param.locations = [self.locations mutableCopyWithZone:zone];
	param.boards = [self.boards mutableCopyWithZone:zone];
	param.amenities = [self.amenities mutableCopyWithZone:zone];
	return param;
}

#pragma mark - Property

- (NSInteger)roomCount {
	return self.roomInfo.count;
}

- (NSInteger)nights {
	return [CocoaUtils dateIntervalForComponent:NSCalendarUnitDay fromDate:[[DateFormatUtils ISO_DATE_FORMAT] parse:self.checkIn] toDate:[[DateFormatUtils ISO_DATE_FORMAT] parse:self.checkOut]];
}

#pragma mark - Public

- (NSDictionary *)toParameters {
	NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:[CocoaUtils nonEmptyDictionary:[BeanUtils describeAccessibleSimple:self]]];
	if (self.roomInfo.count > 0) {
		NSMutableArray *roomInfos = [NSMutableArray array];
		for (RoomBasedCountData *roomData in self.roomInfo) {
			NSMutableArray *childAge = [NSMutableArray array];
			for (NSNumber *age in roomData.childAges) {
				[childAge addObject:@{ @"age" : age }];
			}
			[roomInfos addObject:@{ @"adultNum" : @(roomData.adultCount), @"childAges" : @{ @"childAge" : childAge }, @"childNum" : @(roomData.childCount) }];
		}
		NSDictionary *roomInfo = @{ @"roomInfo" : roomInfos };
		dict[@"roomInfo"] = [CocoaUtils jsonStringWithDictionary:roomInfo];
	}
	if (self.stars.count > 0) {
		dict[@"stars"] = [self.stars componentsJoinedByString:@";"];
	}
	if (self.brands.count > 0) {
		dict[@"brands"] = [self.brands componentsJoinedByString:@";"];
	}
	if (self.locations.count > 0) {
		dict[@"locations"] = [self.locations componentsJoinedByString:@";"];
	}
	if (self.boards.count > 0) {
		dict[@"boards"] = [self.boards componentsJoinedByString:@";"];
	}
	if (self.amenities.count > 0) {
		dict[@"amenities"] = [self.amenities componentsJoinedByString:@";"];
	}
	return [NSDictionary dictionaryWithDictionary:dict];
}

@end

@interface HotelSearchPaginationParam () <NSCopying>
@end

@implementation HotelSearchPaginationParam

- (id)copyWithZone:(NSZone *)zone {
	return [BeanUtils copyWithZone:zone origin:self superClass:self.superclass];
}

#pragma mark - Public

- (NSDictionary *)toParameters {
	NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:[CocoaUtils nonEmptyDictionary:[BeanUtils describeAccessibleSimple:self superClass:self.superclass]]];
	[dict addEntriesFromDictionary:[super toParameters]];
	return [NSDictionary dictionaryWithDictionary:dict];
}

@end

@interface HotelSearchListViewController () <DZNEmptyDataSetDefault, DZNEmptyDataSetDelegate>
@property (nonatomic, strong) NSMutableArray *hotelSeachResults;
@property (nonatomic, strong) NSDictionary *hotelFilterDict;
@property (nonatomic, strong) NSMutableArray *cellDataArray;
@property (nonatomic, strong) CheckAvailabilityAndPricesResponse *busPriceResponse;
@property(nonatomic, strong) HotelListHeaderView *hotelListHeaderView;
@end

@implementation HotelSearchListViewController

- (instancetype)init {
	self = [super init];
	if (self) {
		// Custom initialization
		self.title = IMLocalizedString(@"Loading...");
		[[Vars appDelegate] applyDefaultConfigurationForViewController:self];
	}
	return self;
}

- (void)viewDidLoad {
	[super viewDidLoad];

	[[AppTracker sharedInstance] sendView:[self class]];
	
	self.hotelSeachResults = [NSMutableArray array];
	self.cellDataArray = [NSMutableArray array];

	self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[DrawUtils imageWithFAKIcon:[FAKFontAwesome filterIconWithSize:24] fillColor:[UIColor blackColor]] style:UIBarButtonItemStylePlain target:self action:@selector(filterSearchResult)];
	self.navigationItem.rightBarButtonItem.enabled = NO;

	self.tableView.emptyDataSetDelegate = self;
	[self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([HotelSearchListSmallCell class]) bundle:[NSBundle mainBundle]] forCellReuseIdentifier:NSStringFromClass([HotelSearchListSmallCell class])];

	@weakify(self)
	MJRefreshNormalHeader * refreshHeader = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
		@strongify(self)
		[self clearHotelSearchResults];
		[self searchHotel:YES];
	}];
	refreshHeader.automaticallyChangeAlpha = YES;
	refreshHeader.lastUpdatedTimeLabel.hidden = YES;
	self.tableView.mj_header = refreshHeader;
	MJRefreshBackNormalFooter *refreshFooter = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
		@strongify(self)
		[self searchHotel: YES];
	}];
	refreshFooter.automaticallyChangeAlpha = YES;
	self.tableView.mj_footer = refreshFooter;
}

- (void)viewDidAppear:(BOOL)animated {
	[super viewDidAppear:animated];
	// ajax
	if (self.hotelSearchParam.pageNumber == 0) {
		[self searchHotel:NO];
	}
}

#pragma mark - Public

- (void)clearHotelSearchResults {
	self.hotelSearchParam.pageNumber = 0;
}

#pragma mark - Action

- (void)filterSearchResult {
	HotelSearchFilterViewController *viewController = [[HotelSearchFilterViewController alloc] init];
	viewController.hotelFilterDict = self.hotelFilterDict;
	viewController.hotelSearchParam = self.hotelSearchParam;
	[self.navigationController pushViewController:viewController animated:YES];
}

- (void)showDetailWithObject:(HotelSearchData *)object {
	HotelSearchDetailViewController *viewController = [[HotelSearchDetailViewController alloc] init];
	viewController.hotelSearchData = object;
	viewController.hotelSearchParam = self.hotelSearchParam;
	viewController.isBusHotelPackage = self.isBusHotelPackage;
	viewController.busPriceResponse = self.busPriceResponse;
	[self.navigationController pushViewController:viewController animated:YES];
}

#pragma mark - Network

- (void)searchHotel:(BOOL)circle {
	BOOL initial = self.hotelSearchParam.pageNumber == 0;
	self.hotelSearchParam.pageNumber++;
	__block NSInteger total = 0;
	__block BOOL needUpdate = NO;
	void (^beforeSendBlock)(void) = ^{
		if (!circle) {
			[CocoaUtils showBusyIndicator:self.view];
			self.tableView.mj_header.hidden = YES;
			self.tableView.mj_footer.hidden = YES;
		}
		self.tableView.emptyDataSetSource = nil;
		self.tableView.emptyDataSetDelegate = nil;
	};
	void (^completeBlock)(void) = ^{
		if (!circle) {
			if (self.hotelSeachResults.count >= total) {
				[self.tableView.mj_footer endRefreshingWithNoMoreData];
				self.tableView.mj_footer.hidden = YES;
			} else {
				[self.tableView.mj_footer resetNoMoreData];
				self.tableView.mj_footer.hidden = NO;
			}
		} else {
			[self.tableView.mj_header endRefreshing];
			if (self.hotelSeachResults.count >= total) {
				[self.tableView.mj_footer endRefreshingWithNoMoreData];
				self.tableView.mj_footer.hidden = YES;
			} else {
				[self.tableView.mj_footer endRefreshing];
				self.tableView.mj_footer.hidden = NO;
			}
		}
		if (!circle) {
			self.tableView.mj_header.hidden = NO;
			[CocoaUtils hideBusyIndicator:self.view];
		}
		self.tableView.emptyDataSetSource = self;
		self.tableView.emptyDataSetDelegate = self;
		[self.tableView reloadData];
	};
	void (^successPreBlock)(NSString *xml) = ^(NSString *xml) {
		NSString *responseStr = xml;
		// NSLog(@"%@", responseStr);
		if (initial) {
			[self.hotelSeachResults removeAllObjects];
			[self.cellDataArray removeAllObjects];
			self.hotelFilterDict = nil;
		}
		NSString *ret = [CocoaUtils firstValueMatchedInString:responseStr forElement:@"return"];
		if (ret) {
			NSDictionary *jsonObject = [NSJSONSerialization JSONObjectWithData:[ret dataUsingEncoding:NSUTF8StringEncoding] options:0 error:NULL];
			if (jsonObject.count > 0) {
				NSDictionary *root = jsonObject;
				total = [root[@"totalCount"] intValue];
				NSString *resultXml = root[@"resultXml"];
				// NSLog(@"%@", resultXml);
				if (![StringUtils isEmpty:resultXml]) {
					// resultXml = [resultXml stringByReplacingOccurrencesOfString:@"\n" withString:@""];
				}
				resultXml = [CocoaUtils noDeclarationXmlString:resultXml];
				// NSLog(@"%@", resultXml);
				SearchHotelResponseJsonMapper *mapper = [[SearchHotelResponseJsonMapper alloc] init];
				NSDictionary *jsonDict = [Utility JSONObjectWithXMLString:resultXml objectMapping:mapper.objectMapping];
				// NSLog(@"%@", jsonDict);
				if (![mapper parseWithJSONObject:jsonDict]) {
					SearchHotelResponse *response = mapper.response;
					[self.hotelSeachResults addObjectsFromArray:response.products];
					[self updateTableViewCellDataArrayByHotelSearchDataList:response.products];
				}
				NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithDictionary:root];
				[dictionary removeObjectForKey:@"resultXml"];
				self.hotelFilterDict = [NSDictionary dictionaryWithDictionary:dictionary];
				// NSLog(@"%@", self.hotelFilterDict);
				needUpdate = YES;
			}
		}
	};
	void (^successPostBlock)(void) = ^{
		if (!needUpdate) {
			[self.hotelSeachResults removeAllObjects];
			[self.cellDataArray removeAllObjects];
			self.hotelFilterDict = nil;
		}
		if (needUpdate) {
			if (initial) {
				[self.tableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:NO];
			}
			self.title = total > 0 ? [NSString stringWithFormat:(total > 1 ? IMLocalizedString(@"Found %d Hotels") : IMLocalizedString(@"Found %d Hotel")), total] : IMLocalizedString(@"No Search Results");
			self.navigationItem.rightBarButtonItem.enabled = self.hotelFilterDict ? YES : NO;
		} else {
			self.title = IMLocalizedString(@"No Search Results");
			self.navigationItem.rightBarButtonItem.enabled = NO;
		}
	};
	if (self.isBusHotelPackage && !self.busPriceResponse) {
		[NetUtils beginTransation];
		beforeSendBlock();
		NSMutableArray *batchOf = [NSMutableArray array];
		if (YES) {
			CheckAvailabilityAndPrices *checkAvailabilityAndPrices = [[CheckAvailabilityAndPrices alloc] init];
			checkAvailabilityAndPrices.travelerDetails = [WebService travelerDetailsWithCartEntries:[[Vars appDelegate].shopCarts.entries bk_select:^BOOL (CartEntry *obj) {
				return obj.product.is_bus;
			}]];
			NSDictionary *requestDict = [Utility perlParamXml:[checkAvailabilityAndPrices innerXML] action:checkAvailabilityAndPrices.name];

			id obj = [Utility getXMLFromRequestWithMethod:@"POST" url:checkAvailabilityAndPrices.address parameters:requestDict beforeSend:nil success:^(NSString *xml) {
				NSString *responseStr = xml;
				// NSLog(@"%@", responseStr);
				CheckAvailabilityAndPricesResponseJsonMapper *mapper = [[CheckAvailabilityAndPricesResponseJsonMapper alloc] init];
				NSDictionary *jsonDict = [Utility JSONObjectWithXMLString:responseStr objectMapping:mapper.objectMapping];
				if (![mapper parseWithJSONObject:jsonDict]) {
					CheckAvailabilityAndPricesResponse *response = mapper.response;
					if (response.error_code > 0) {
						[CocoaUtils showAlertWithTitle:IMLocalizedString(@"Error") message:response.error_message];
					} else {
						self.busPriceResponse = response;
					}
				}
			} complete:nil];
			[batchOf addObject:obj];
		}
		if (YES) {
			SearchHotel *searchHotel = [[SearchHotel alloc] init];
			NSDictionary *requrestDict = [self.hotelSearchParam toParameters];

			id obj = [Utility performSOAPRequestWithUrl:searchHotel.address namespace:searchHotel.namespace name:searchHotel.name parameters:requrestDict beforeSend:nil success:successPreBlock complete:nil];
			[batchOf addObject:obj];
		}
		[NetUtils performBatchOf:batchOf completion:^{
			if (self.isBusHotelPackage && !self.busPriceResponse) {
				needUpdate = NO;
			}
			successPostBlock();
			completeBlock();
		}];
	} else {
		SearchHotel *searchHotel = [[SearchHotel alloc] init];
		NSDictionary *requrestDict = [self.hotelSearchParam toParameters];

		[Utility performSOAPRequestWithUrl:searchHotel.address namespace:searchHotel.namespace name:searchHotel.name parameters:requrestDict beforeSend:beforeSendBlock success:^(NSString *xml) {
			successPreBlock(xml);
			successPostBlock();
		} complete:completeBlock];
	}
}

#pragma mark - Private

- (void)updateTableViewCellDataArrayByHotelSearchDataList:(NSArray *)objects {
	@weakify(self)
	NSMutableArray * tempArray = [NSMutableArray array];
	for (HotelSearchData *obj in objects) {
		TableViewCellData *data = [[TableViewCellData alloc] init];
		data.reuseIdentifier = NSStringFromClass([HotelSearchListSmallCell class]);
		data.weaklyAssociatedObject = obj;
		[data setNeedLayoutFittingHeight];
		[data setDidSelectBlock:^(UITableView *tableView, NSIndexPath *indexPath, TableViewCellData *data) {
			@strongify(self)
			[self showDetailWithObject: obj];
		}];
		[tempArray addObject:data];
	}
	[self.cellDataArray addObjectsFromArray:tempArray];
}

-(void)editDate{
	RangeCalendarViewController *viewController = [[RangeCalendarViewController alloc] init];
	viewController.title = @"Departure & Return";
	[[Vars appDelegate] applyDefaultConfigurationForViewController:viewController];
	viewController.isRoundTrip = YES;
	viewController.isHotel = YES;
	viewController.isHeaderViewUserInteractionEnabled = NO;
	viewController.minimumDate = [NSDate date];
	viewController.maximumDate = [DateUtils addMonths:[NSDate date] amount:6];
	viewController.hidesBottomBarWhenPushed = YES;
	[viewController selectRangeFromStartDate:[[DateFormatUtils ISO_DATE_FORMAT] parse:self.hotelSearchParam.checkIn] toEndDate:[[DateFormatUtils ISO_DATE_FORMAT]  parse:self.hotelSearchParam.checkOut]];
	[viewController setDidCancelBlock:^{
		[self.navigationController popViewControllerAnimated:YES];
	}];
	[viewController setDidDoneRangeBlock:^(NSDate *startDate, NSDate *endDate) {
		if (!startDate || !endDate) {
			[CocoaUtils showAlertWithTitle:IMLocalizedString(@"Information") message:@"Please select departure date and return date"];
			return;
		}
		[self.navigationController popViewControllerAnimated:YES];
		self.hotelSearchParam.checkIn = [[DateFormatUtils ISO_DATE_FORMAT] format:startDate];
		self.hotelSearchParam.checkOut = [[DateFormatUtils ISO_DATE_FORMAT] format:endDate];
		[self changeHeadertext];
		[self clearHotelSearchResults];
		[self.cellDataArray removeAllObjects];
		[self.tableView reloadData];
		[self searchHotel:NO];
	}];
	if (![StringUtils isEmpty:self.hotelSearchParam.checkIn] && ![StringUtils isEmpty:self.hotelSearchParam.checkOut]) {
		[viewController selectRangeFromStartDate:[[DateFormatUtils ISO_DATE_FORMAT] parse:self.hotelSearchParam.checkIn] toEndDate:[[DateFormatUtils ISO_DATE_FORMAT] parse:self.hotelSearchParam.checkOut]];
	}
	[self.navigationController pushViewController:viewController animated:YES];
}

-(void)editRoomInfo{
	RoomBasedCountViewController *roomViewController = [[RoomBasedCountViewController alloc] initWithRoomBasedCountDatas:self.hotelSearchParam.roomInfo];
	roomViewController.childEnabled = YES;
	roomViewController.minimumAdultCount = 1;
	roomViewController.maximumAdultCount = 4;
	roomViewController.maximumChildCount = 3;
	roomViewController.minimumChildAge = 1;
	roomViewController.maximumChildAge = 17;
	roomViewController.preferredChildAge = 12;
	[roomViewController setDidCancelBlock:^{
		[self.navigationController popViewControllerAnimated:YES];
	}];
	[roomViewController setDidDoneBlock:^(NSArray *countDatas) {
		[self.navigationController popViewControllerAnimated:YES];
		self.hotelSearchParam.roomInfo = countDatas;
		[self changeHeadertext];
		[self clearHotelSearchResults];
		[self.cellDataArray removeAllObjects];
		[self.tableView reloadData];
		[self searchHotel:NO];
	}];
	[self.navigationController pushViewController:roomViewController animated:YES];
}

-(void)changeHeadertext{
	NSDate *checkInDate = [[DateFormatUtils ISO_DATE_FORMAT] parse:self.hotelSearchParam.checkIn];
	NSDate *checkOutDate = [[DateFormatUtils ISO_DATE_FORMAT] parse:self.hotelSearchParam.checkOut];
	self.hotelListHeaderView.dateLabel.text = [NSString stringWithFormat:@"%@ - %@",[[Utility RANGECALENDAR_DATE_FORMAT] format:checkInDate],[[Utility RANGECALENDAR_DATE_FORMAT] format:checkOutDate]];
	
	__block NSInteger peopleCount = 0;
	[ self.hotelSearchParam.roomInfo bk_each:^(RoomBasedCountData * roomData) {
		peopleCount += roomData.peopleCount;
	}];
	NSString *roomInfoText = [NSString stringWithFormat:@"Room %d, Guest %d",self.hotelSearchParam.roomInfo.count,peopleCount];
	self.hotelListHeaderView.roomInfoLabel.text = roomInfoText;
}

#pragma mark - Table view methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
	return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
	return self.cellDataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
	TableViewCellData *data = self.cellDataArray[indexPath.row];
	if ([data.reuseIdentifier isEqualToString:NSStringFromClass([HotelSearchListSmallCell class])]) {
		return [UIToolkit instantiateRowHeightForTableViewCellWithNibName:NSStringFromClass([HotelSearchListSmallCell class])];
	}
	return [UIConstants defaultTableViewRowHeight];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
	TableViewCellData *data = self.cellDataArray[indexPath.row];
	return [UIToolkit tableView:tableView atIndexPath:indexPath rowHeightWithData:data];
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
	HotelListHeaderView *headerView = [HotelListHeaderView viewFromNib];
	self.hotelListHeaderView = headerView;
	headerView.calendarImageView.image = [DrawUtils imageWithFAKIcon:[FAKFontAwesome calendarIconWithSize:17] fillColor:[UIColor darkGrayColor]];
	headerView.roomImageView.image = [DrawUtils imageWithFAKIcon:[FAKFontAwesome bedIconWithSize:20] fillColor:[UIColor darkGrayColor]];
	[self changeHeadertext];
	UITapGestureRecognizer *tapCalendarGestureReconizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(editDate)];
	headerView.calendarView.userInteractionEnabled = YES;
	headerView.calendarView.gestureRecognizers = @[tapCalendarGestureReconizer];
	
	UITapGestureRecognizer *tapRoomInfoGestureReconizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(editRoomInfo)];
	headerView.roomInfoView.userInteractionEnabled = YES;
	headerView.roomInfoView.gestureRecognizers = @[tapRoomInfoGestureReconizer];
	return headerView;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
	return 58;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	TableViewCellData *data = self.cellDataArray[indexPath.row];
	if ([data.reuseIdentifier isEqualToString:NSStringFromClass([HotelSearchListSmallCell class])]) {
		HotelSearchListSmallCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([HotelSearchListSmallCell class])];
		HotelSearchData *object = data.weaklyAssociatedObject;
		NSString *imageUrl = [object adaptiveImageUrl];
		if (imageUrl) {
			[cell.hotelImageView sd_setImageWithURL:[NSURL URLWithString:imageUrl]];
		}
		if (YES) {
			NSMutableString *productName = [NSMutableString im_stringWithString:object.product_name];
			if (![StringUtils isEmpty:object.hotel_description_ext.location.searchingCity]) {
				[productName im_appendString:IMLocalizedString(PUNCTUATION_COMMA)];
				[productName im_appendString:IMLocalizedString(WORD_DIVIDER_SPACE)];
				[productName im_appendString:object.hotel_description_ext.location.searchingCity];
			}
			cell.productNameLabel.text = [NSString stringWithString:productName];
		}
		cell.hotelRatingLabel.attributedText = [object attributedRatingTextWithFont:cell.hotelRatingLabel.font];
		[cell setTripAdvisorImageWithURLString:object.tripadvisor_image_url];
		cell.describeLabel.text = [StringUtils isEmpty:object.hotel_description_ext.location.location] ? object.hotel_description_ext.ref_point.shortDescription : object.hotel_description_ext.location.location;
		if (self.isBusHotelPackage) {
			cell.priceLabel.attributedText = [object attributedTotalPriceTextWithFont:[UIFont preferredFontForTextStyle:UIFontTextStyleCaption2] roomCount:self.hotelSearchParam.roomInfo.count nights:self.hotelSearchParam.nights additionalPrice:self.busPriceResponse.total_charge headerTitle:@"Package Price"];
		} else {
			cell.priceLabel.attributedText = [object attributedPriceTextWithFont:[UIFont preferredFontForTextStyle:UIFontTextStyleCaption2]];
		}
		cell.amenityImgView.image = [object concatenateAmenityImageToWidth:cell.describeLabel.font.pointSize tintColor:[CocoaUtils colorWithRGBs:StandardColorBlue] borderWidth:cell.describeLabel.font.pointSize / 5];
		[cell showRiband:object.hotel_description_ext.hotel_base_info.bestValue];
		return cell;
	}
	return [UIToolkit tableView:tableView atIndexPath:indexPath cellWithData:data];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	[tableView deselectRowAtIndexPath:indexPath animated:YES];
	TableViewCellData *data = self.cellDataArray[indexPath.row];
	[UIToolkit tableView:tableView atIndexPath:indexPath didSelectWithData:data];
}

#pragma mark - <DZNEmptyDataSetDelegate>

- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView {
	return YES;
}

@end
