<?php

use WpBookingHotel\Factory as FactoryAlias;
use WpBookingHotel\Html\WpBookingHotelHtmlFrontend;
use WpBookingHotelFrontend\app\Html\HtmlFrontend;
use WpBookingHotel\Language\Text;
use WpBookingHotelFrontend\app\helpers\ConfigHelper as ConfigHelperAlias;

$doc = FactoryAlias::getDocument();
$doc->addLessStyleSheet('frontend/app/assets/less/view-list-hotellocator.less');
$doc->addStyleSheet('frontend/app/assets/nb-font-icon/nb-font-icon.css');
WpBookingHotelHtmlFrontend::load_jquery_library('datatables');
WpBookingHotelHtmlFrontend::load_jquery_library('moment');
WpBookingHotelHtmlFrontend::load_jquery_library('daterangepicker');
WpBookingHotelHtmlFrontend::load_jquery_library('fontawesome');
WpBookingHotelHtmlFrontend::load_jquery_library('ui');
WpBookingHotelHtmlFrontend::load_jquery_library('icheck');
WpBookingHotelHtmlFrontend::load_jquery_library('select2');
WpBookingHotelHtmlFrontend::load_jquery_library('loading_js');
WpBookingHotelHtmlFrontend::load_jquery_library('confirm');
WpBookingHotelHtmlFrontend::load_jquery_library('store_locator_js');
WpBookingHotelHtmlFrontend::load_jquery_library('twbs_pagination');
$url_plugin = WPBOOKINGHOTEL_PLUGIN_NAME;

$page_hotel_detail = ConfigHelperAlias::get_page_hotel_detail();
if ($page_hotel_detail) {
    $this->page_hotel_detail = get_page_link($page_hotel_detail);
} else {
    $this->page_hotel_detail = "";
}
$number_hotel = count($this->list);
$page_list_hotel = ConfigHelperAlias::get_page_list_hotel();
if ($page_list_hotel) {
    $page_list_hotel = get_page_link($page_list_hotel);
} else {
    $page_list_hotel = "";
}
$rate = 0;
if (!empty($_SESSION["rate"])){
    $rate = $_SESSION["rate"];
}else{
    $rate = (int)1;
}

$input = FactoryAlias::getInput();
$roomtype_id = $input->getString('room_type_id','');
$location_id = $input->getInt('location', 0);
$near_me = $input->getInt('near_me', 0);
$sort = $input->getString('key_sort', 'a.ordering');
$direction = $input->getString('direction', '');
$rating = $input->getString('total_rating_avg','');
$service_id = $input->getString('service_id[]','');
$near_me = $input->getInt('near_me', 0);

?>
    <div class="view-list-hotellocator">
        <form action="" method="post" name="filter-form" id="bh-sl-user-location" class="form-search-service">
            <div class="row">
                <div class="col-md-12">
                    <div class="bh-sl-container">
                        <div id="bh-sl-map-container" class="bh-sl-map-container">
                            <div class="wrapper-content-left col-md-6">
                                <div class="wrapper-search-service2 bh-sl-filters-container">
                                    <div class="find_your_services wrapper-price-rating">
                                        <h4><?php esc_attr_e('Find Your Hotels', 'wpbookinghotel') ?></h4>
                                        <div class="list-roomtype bh-sl-filters">
                                            <select name="room_type_id" class="list-roomtype">
                                                <option value=""><?php esc_attr_e('Choose an Roomtype', 'wpbookinghotel') ?></option>
                                                <?php foreach ($this->list_roomtype as $roomtype) { ?>
                                                    <option value="<?php esc_html_e($roomtype->id); ?>"><?php esc_html_e($roomtype->name); ?></option>
                                                <?php } ?>
                                            </select>
                                        </div>
                                        <div class="list-location bh-sl-filters">
                                            <select name="location_id" class="list-location">
                                                <option value=""><?php esc_attr_e('Select Address', 'wpbookinghotel') ?></option>
                                                <?php foreach ($this->list_locations as $location) { ?>
                                                    <option
                                                            value="<?php esc_html_e($location->id); ?>"><?php esc_html_e($location->address); ?></option>
                                                <?php } ?>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="filter-more">
                                        <p class="more-option"><span><?php esc_attr_e('More option','wpbookinghotel');?></span><i class="fas fa-sort-down"></i></p>
                                        <div class="block-filter-price block-filter-price-more-option">
                                            <h4><?php esc_attr_e('Filter price','wpbookinghotel');?></h4>
                                            <input type="text" id="amount_1" readonly/>
                                            <div id="slider-container-1"></div>
                                            <input type="hidden" name="price_search">
                                        </div>
                                        <div class="list-rating">
                                            <h4><?php esc_attr_e('Filter By Rating', 'wpbookinghotel') ?></h4>
                                            <div class="block-filter-star">
                                                <div class="item-star-filter">
                                                    <input type="radio" name="total_rating_avg" id="five-star" value="5" <?php echo ($rating!='' && $rating == 5 ?'checked':'');?>>
                                                    <label for="five-star">
                                                        <ul class="list-rating-star">
                                                            <?php for($i = 1; $i <= 5; $i++) {?>
                                                                <li class="item-star"><i class="fas fa-star"></i></li>
                                                            <?php }?>
                                                        </ul>
                                                        <span class="number-hotel">
                                        <?php echo (esc_html(count($five_star)));?>
                                        </span>
                                                    </label>
                                                </div>
                                                <div class="item-star-filter">
                                                    <input type="radio" name="total_rating_avg" id="four-star" value="4" <?php echo ($rating!='' && $rating == 4 ?'checked':'');?>>
                                                    <label for="four-star">
                                                        <ul class="list-rating-star">
                                                            <?php for($i = 1; $i <= 4; $i++) {?>
                                                                <li class="item-star"><i class="fas fa-star"></i></li>
                                                            <?php }?>
                                                            <li class="item-star"><i class="far fa-star"></i></li>
                                                        </ul>
                                                        <span class="number-hotel">
                                        <?php echo (esc_html(count($four_star)));?>
                                    </span>
                                                    </label>
                                                </div>
                                                <div class="item-star-filter">
                                                    <input type="radio" name="total_rating_avg" id="three-star" value="3" <?php echo ($rating!='' && $rating == 3 ?'checked':'');?>>
                                                    <label for="three-star">
                                                        <ul class="list-rating-star">
                                                            <?php for($i = 1; $i <= 3; $i++) {?>
                                                                <li class="item-star"><i class="fas fa-star"></i></li>
                                                            <?php }?>
                                                            <?php for($i = 1; $i <= 2; $i++) {?>
                                                                <li class="item-star"><i class="far fa-star"></i></li>
                                                            <?php }?>
                                                        </ul>
                                                        <span class="number-hotel">
                                        <?php echo (esc_html(count($three_star)));?>
                                        </span>
                                                    </label>
                                                </div>
                                                <div class="item-star-filter">
                                                    <input type="radio" name="total_rating_avg" id="two-star" value="2" <?php echo ($rating!='' && $rating == 2 ?'checked':'');?>>
                                                    <label for="two-star">
                                                        <ul class="list-rating-star">
                                                            <?php for($i = 1; $i <= 2; $i++) {?>
                                                                <li class="item-star"><i class="fas fa-star"></i></li>
                                                            <?php }?>
                                                            <?php for($i = 1; $i <= 3; $i++) {?>
                                                                <li class="item-star"><i class="far fa-star"></i></li>
                                                            <?php }?>
                                                        </ul>
                                                        <span class="number-hotel">
                                        <?php echo (esc_html(count($two_star)));?>
                                        </span>
                                                    </label>
                                                </div>
                                                <div class="item-star-filter">
                                                    <input type="radio" name="total_rating_avg" id="one-star" value="1" <?php echo ($rating!='' && $rating == 1 ?'checked':'');?>>
                                                    <label for="one-star">
                                                        <ul class="list-rating-star">
                                                            <li class="item-star"><i class="fas fa-star"></i></li>
                                                            <?php for($i = 1; $i <= 4; $i++) {?>
                                                                <li class="item-star"><i class="far fa-star"></i></li>
                                                            <?php }?>
                                                        </ul>
                                                        <span class="number-hotel">
                                        <?php echo (esc_html(count($one_star)));?>
                                        </span>
                                                    </label>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="block-location-near-me">
                                            <h4><?php esc_attr_e('Select near me','wpbookinghotel');?></h4>
                                            <label class="label-near-me">
                                                <input type="checkbox" class="input-near-me" name="near_me" value="1" />
                                                <?php esc_html_e('Near me','wpbookinghotel');?>
                                            </label>
                                            <input type="hidden" name="latitude">
                                            <input type="hidden" name="longitude">
                                        </div>
                                        <div class="wrapper-price-rating2">
                                            <div class="list-category">
                                                <h4><?php esc_attr_e('Filter By Service') ?></h4>
                                                <ul class="ul-list-category bh-sl-filters">
                                                    <?php foreach ($this->list_services as $service) { ?>
                                                        <li>
                                                            <div class="block-label">
                                                                <label class="label-category">
                                                                    <input type="radio" class="check-box-category"
                                                                           name="service_id[]" value="<?php echo($service->id); ?>"/>
                                                                    <span><?php echo($service->name); ?></span>
                                                                </label>
                                                            </div>
                                                        </li>
                                                    <?php } ?>
                                                </ul>
                                            </div>
                                        </div>
                                    </div>

                                </div>
                                <div class="block-top-result bh-sl-filters-container">
                                    <div class="result-title">
                                        <h3><span class="number-service"><?php echo($number_service) ?></span><?php esc_attr_e(' Hotels found', 'wpbookinghotel'); ?></h3>
                                    </div>
                                    <div class="block-sorting-display">
                                        <div class="block-display-button">
                                            <div class="nav nav-tabs">
                                                <div class="active"><a data-toggle="tab" href="#grid-display"><i
                                                                class="fas fa-th"></i></a></div>
                                                <div><a data-toggle="tab" href="#list-display"><i
                                                                class="fas fa-list"></i></a></div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="sort-by-price">
                                        <div class="dropdown">
                                            <a class="dropdown-toggle" data-toggle="dropdown" href="javascript:void(0)">
                                                <span class="select-by-default"><?php esc_attr_e('Sort by', 'wpbookinghotel') ?></span>
                                                <i class="fas fa-chevron-down"></i>
                                            </a>
                                            <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                                                <ul class="sort-display bh-sl-filters">
                                                    <li class="<?php echo ($sort=="a.price" && $direction=="ASC"?' active ':'') ?>">
                                                        <a class="lowest-price select-sort-item <?php echo ($sort=="a.price" && $direction=="ASC"?' active ':'') ?>" data-key_sort="a.price" data-direction="ASC"   href="javascript:void(0)">
                                                            <?php esc_attr_e('Lowest price', 'wpbookinghotel') ?>
                                                        </a>
                                                    </li>
                                                    <li class="<?php echo ($sort=="a.price" && $direction=="DESC"?' active ':'') ?>">
                                                        <a class="highest-price select-sort-item <?php echo ($sort=="a.price" && $direction=="DESC"?' active ':'') ?>" data-key_sort="a.price" data-direction="DESC"   href="javascript:void(0)">
                                                            <?php esc_attr_e('Highest price', 'wpbookinghotel') ?>
                                                        </a>
                                                    </li>
                                                </ul>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="tab-content wrapper-result-body">
                                    <div id="grid-display" class="tab-pane fade in active">
                                        <div class="bh-sl-loc-grid">
                                            <div class="grid">
                                            </div>
                                        </div>
                                    </div>
                                    <div id="list-display" class="tab-pane fade">
                                        <div class="bh-sl-loc-list">
                                            <div class="list">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div id="bh-sl-map" class="bh-sl-map"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <div class="bh-sl-pagination-container">
                        <ol class="bh-sl-pagination">
                        </ol>
                    </div>
                </div>
            </div>
            <input type="hidden" name="key_sort" value="<?php echo (esc_attr($sort)) ?>">
            <input type="hidden" name="direction" value="<?php echo (esc_attr($direction)) ?>">
        </form>
    </div>

<?php
$input = FactoryAlias::getInput();
$doc->addLessStyleSheet('frontend/app/assets/less/view-list-hotellocator.less');
$doc->addScriptApplySelector('.view-list-hotellocator', 'view_list_hotellocator', array(
    'data_input' => $input->getData(),
    'list_service'=>$this->list,
    "symbol"=>$this->symbol->symbol,
    "rate"=>$rate,
    'url_plugin' => $url_plugin

), "frontend/app/assets/js/view_list_hotellocator.js");
?>