<?php
use WpBookingEvent\Factory as FactoryAlias;
use WpBookingEvent\Html\WpBookingEventHtmlFrontend;
use WpBookingEvent\Language\Text;
use WpBookingEventFrontend\app\helpers\ConfigHelper as ConfigHelperAlias;

$doc= FactoryAlias::getDocument();
$doc->addLessStyleSheet('frontend/app/assets/less/view-list-services.less');
$doc->addStyleSheet('frontend/app/assets/nb-font-icon/nb-font-icon.css');
WpBookingEventHtmlFrontend::load_jquery_library('datatables');
WpBookingEventHtmlFrontend::load_jquery_library('moment');
WpBookingEventHtmlFrontend::load_jquery_library('daterangepicker');
WpBookingEventHtmlFrontend::load_jquery_library('fontawesome');
WpBookingEventHtmlFrontend::load_jquery_library('ui');
WpBookingEventHtmlFrontend::load_jquery_library('icheck');
WpBookingEventHtmlFrontend::load_jquery_library('select2');
WpBookingEventHtmlFrontend::load_jquery_library('twbs_pagination');
$page_service_detail= ConfigHelperAlias::get_page_service_detail();
if($page_service_detail) {
    $this->page_service_detail = get_page_link($page_service_detail);
}else{
    $this->page_service_detail="";
}
$number_service=count($this->list);
$page_list_service= ConfigHelperAlias::get_page_list_service();
if($page_list_service) {
    $this->page_list_service = get_page_link($page_list_service);
}else{
    $this->page_list_service="";
}

$input=FactoryAlias::getInput();
$location_id=$input->getInt('location',0);
$list_employee_id=[];
if(array_key_exists('employee',(array)$input->getData())) {
    $list_employee_id=(array)$input->getData()['employee'];
}
$list_category_id=[];
if(array_key_exists('category',(array)$input->getData())) {
    $list_category_id=(array)$input->getData()['category'];
}
$limit=$input->getInt('limit', 6);
$start=$input->getInt('start', 0);
?>
<form class="list-services"  action="<?php echo($this->page_list_service) ?>"  method="get" name="pagination">
    <div class="view-list-services">
        <div class="row">
            <div class="col-md-3">
                <div class="wrapper-search-service">
                    <form action="<?php echo ($this->page_list_service)  ?>" method="get" class="form-search-service">
                        <div class="block-title-search-service">
                            <h4><?php esc_attr_e('Search services','wpbookingevent');?></h4>
                        </div>
                        <div class="block-select-location">
                            <i class="icon-nb-pin"></i>
                            <label><?php esc_attr_e('Destination','wpbookingevent');?></label>
                            <select name="location" class="select-location">
                                <option value=""><?php esc_attr_e('Select place','wpbookingevent');?></option>
                                <?php foreach ($this->list_countries as $country) {?>
                                    <optgroup label="<?php echo ($country->countryname);?>">
                                        <?php foreach ($country->list_location as $location) {?>
                                            <option <?php echo (($location_id==$location->location_id)?'selected':'') ?> value="<?php echo ($location->location_id);?>"><?php echo ($location->location_name);?></option>
                                        <?php }?>
                                    </optgroup>
                                <?php }?>
                            </select>
                        </div>
                        <div class="block-select-employees">
                            <h5><?php esc_attr_e('Select employee','wpbookingevent');?></h5>
                            <div class="block-service-employee">
                                <?php foreach ($this->list_employees as $employee) {?>
                                    <?php if (count((array)$list_employee_id)) {?>
                                        <label><input <?php echo (in_array($employee->id,$list_employee_id)?'checked':'')?> type="checkbox" name="employee[]" value="<?php echo ($employee->id);?>"/> <span><?php echo ($employee->first_name.' '.$employee->last_name);?></span></label>
                                    <?php } else {?>
                                        <label><input type="checkbox" name="employee[]" value="<?php echo ($employee->id);?>"/> <span><?php echo ($employee->first_name.' '.$employee->last_name);?></span></label>
                                    <?php }?>
                                <?php }?>
                            </div>
                        </div>
                        <div class="block-more-option">
                            <div class="title-more-option">
                                <p class="more-option"><span><?php esc_attr_e('More option','wpbookingevent');?></span><i class="fas fa-sort-down"></i></p>
                                <div class="block-filter-price block-filter-price-more-option">
                                    <h5><?php esc_attr_e('Filter price','wpbookingevent');?></h5>
                                    <input type="text" id="amount_1" readonly/>
                                    <div id="slider-container-1"></div>
                                    <input type="hidden" name="price_search">
                                </div>
                                <div class="block-service-categories">
                                    <h5><?php esc_attr_e('Select category','wpbookingevent');?></h5>
                                    <div class="block-service-category">
                                        <?php foreach ($this->list_categories as $category) {?>
                                            <?php if (count((array)$list_category_id)) {?>
                                                <label><input <?php echo (in_array($category->id,$list_category_id)?'checked':'')?> type="checkbox" name="category[]" value="<?php echo ($category->id);?>"/> <span><?php echo ($category->name);?></span></label>
                                            <?php } else {?>
                                                <label><input type="checkbox" name="category[]" value="<?php echo ($category->id);?>"/> <span><?php echo ($category->name);?></span></label>
                                            <?php }?>
                                        <?php }?>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="block-button-search">
                            <button type="submit" class="btn btn-primary"><?php esc_attr_e('Search','wpbookingevent');?></button>
                        </div>
                    </form>
                </div>
            </div>
            <div class="col-md-9">
                <?php if($number_service > 0) {?>
                    <div class="wrapper-block-result">
                        <div class="block-top-result">
                            <div class="result-title">
                                <h3><?php echo ($number_service) ?> <?php esc_attr_e('services found','wpbookingevent');?></h3>
                            </div>
                            <div class="block-sorting-display">
                                <div class="block-display-button">
                                    <ul class="nav nav-tabs">
                                        <li class="active"><a data-toggle="tab" href="#grid-display"><i class="fas fa-th"></i></a></li>
                                        <li><a data-toggle="tab" href="#list-display"><i class="fas fa-list"></i></a></li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                        <div class="tab-content wrapper-result-body">
                            <div id="grid-display" class="tab-pane fade in active">
                                <div class="row">
                                    <?php foreach ($this->list as $service){ ?>
                                        <?php
                                        $this->service=$service;
                                        ?>
                                        <div class="col-sm-6 col-md-4"><?php $this->loadTemplate('list_item') ?></div>
                                    <?php } ?>
                                </div>
                                <div id="pagination-service"></div>
                            </div>
                            <div id="list-display" class="tab-pane fade">
                                <?php foreach ($this->list as $service){ ?>
                                    <?php
                                    $this->service=$service;
                                    ?>
                                    <?php $this->loadTemplate('list_row_item') ?>
                                <?php } ?>
                                <div id="pagination-service1"></div>
                            </div>
                        </div>
                        <input type="hidden" name="start" value="<?php echo $start ?>">
                    </div>
                <?php } else {?>
                <div class="wrapper-block-result">
                    <div class="block-top-result">
                        <div class="result-title">
                            <h3><?php echo ($number_service) ?> <?php esc_attr_e('Could not find any services','wpbookingevent');?></h3>
                        </div>
                        <div class="block-sorting-display">
                            <div class="block-display-button">
                                <ul class="nav nav-tabs">
                                    <li class="active"><a data-toggle="tab" href="#grid-display"><i class="fas fa-th"></i></a></li>
                                    <li><a data-toggle="tab" href="#list-display"><i class="fas fa-list"></i></a></li>
                                </ul>
                            </div>
                        </div>
                    </div>
                    <div class="tab-content wrapper-result-body">
                        <div id="grid-display" class="tab-pane fade in active">
                            <div class="row">
                                <div class="col-md-12">
                                    <div class="alert-block">
                                        <span><?php esc_attr_e('Could not find any services','wpbookingevent')?></span>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div id="list-display" class="tab-pane fade">
                            <div class="row">
                                <div class="col-md-12">
                                    <div class="alert-block">
                                        <span><?php esc_attr_e('Could not find any services','wpbookingevent')?></span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <?php }?>
            </div>
        </div>
    </div>
</form>
<?php
$input = FactoryAlias::getInput();
$doc->addScriptApplySelector('.view-list-services','view_list_services',array(
        'data_input'=>$input->getData(),
        "total_record"=>$this->totalRecord,
        "limit"=>$limit,
        "start"=>$start,
),"frontend/app/assets/js/view_list_services.js");
?>