<?php

use WpBookingHotel\Factory;
use WpBookingHotel\Language\Text;
use WpBookingHotel\Router\Route;
use WpBookingHotelFrontend\app\helpers\FrontendHelper;
use WpBookingHotelFrontend\app\Html\HtmlFrontend;

$service = $this->service;

$rating_avg=isset($service->rating_avg)?$service->rating_avg:0;
if($rating_avg > 0) {
    $list_star_sum = HtmlFrontend::get_rating_star($rating_avg);
}
$list_review = isset($service->list_review)?$service->list_review:array();
$input = Factory::getInput();
$near_me=$input->getInt('near_me',0);
$appConfig = Factory::getAppConfig();
$unit_for_search = $appConfig->get('unit_for_search', '');
?>

<div class="block-service-item">
    <a href="<?php echo  ($this->page_service_detail.'?service_id='.$service->id); ?>">
        <div class="content-top">
            <div class="block-img">
                <div>
                    <img  src="<?php echo (Factory::getRootUrlPlugin());?><?php echo ($service->image);?>" >
                </div>
            </div>
            <div class="block-feature">
                <div class="label-feature <?php esc_attr_e(isset($service->is_feature) && $service->is_feature==1 ? 'visible':'');?>">
                    <span><?php esc_attr_e('Featured','wpbookingpro');?></span>
                </div>
                <i class="fas fa-heart"></i>
            </div>
        </div>
        <div class="content-bottom">
            <p class="place-service">
                <i class="icon-nb-pin"></i>
                <?php
                if(isset($service->location->address)){
                    esc_html_e($service->location->address);
                }
                ?>
            </p>
            <h4 class="name-service">
                <?php esc_html_e($service->name);?>
            </h4>
            <div class="block-rating">
                <ul class="list-rating-star">
                    <?php if($rating_avg > 0) {?>
                        <?php for ($i=0; $i < $list_star_sum[0]; $i++) {?>
                            <li class="item-star"><i class="fas fa-star"></i></li>
                        <?php }?>
                        <?php for ($i=0; $i <$list_star_sum[1]; $i++) {?>
                            <li class="item-star"><i class="fas fa-star-half-alt"></i></li>
                        <?php }?>
                        <?php for ($i=0; $i <$list_star_sum[2]; $i++) {?>
                            <li class="item-star"><i class="far fa-star"></i></li>
                        <?php }?>
                    <?php } else {?>
                        <?php for ($i=0; $i < 5;$i++) {?>
                            <li class="item-star"><i class="far fa-star"></i></li>
                        <?php }?>
                    <?php }?>
                </ul>
                <div class="rating-review">
                    <span><?php echo (esc_html(count($list_review)))?> <?php esc_attr_e('Reviews','wpbookingpro');?></span>
                </div>
            </div>
            <div class="block-trip-price">
                <div class="time-trip">
                    <i class="icon-nb-clock"></i>
                    <span><?php echo ($service->duration);?> <?php esc_attr_e('hours','wpbookingpro');?></span>
                </div>
                <div class="price-service">
                    <span><i class="fas fa-bolt"></i><span><?php esc_attr_e('From','wpbookingpro');?></span></span>
                    <span class="price"><?php esc_html_e(FrontendHelper::format_currency(number_format((float)$service->price,2)));?></span>
                </div>
            </div>
            <?php if($near_me == 1) {?>
                <div class="distance-between-your-location">
                    <i class="fas fa-map-pin"></i>
                    <span>
                        <?php echo (esc_html(isset($service->distance)?$service->distance:0))?>
                        <?php
                        if($unit_for_search == 'Km') {
                            echo (esc_html('Km'));
                        } elseif ($unit_for_search='Mi') {
                            echo (esc_html('Mile'));
                        }
                        ?>
                    </span>
                </div>
            <?php }?>
        </div>
    </a>
</div>
