<?php

use WpBookingEvent\Factory;
use WpBookingEvent\Language\Text;
use WpBookingEventFrontend\app\helpers\FrontendHelper;
use WpBookingEventFrontend\app\Html\HtmlFrontend;

$service = $this->service;
$list_review=$service->list_review;
$total_star=0;
$number_reviews=count($list_review);
foreach ($list_review as $review){
    $total_star +=($review->rating_service + $review->rating_staff + $review->rating_ambience)/3;
}
if ($number_reviews>0){
    $average_star=$total_star/$number_reviews;
}else{
    $average_star=0;
}


$list_star_sum = HtmlFrontend::get_rating_star($average_star);
?>
<div class="row">
    <div class="col-md-12">
        <div class="block-service-item-display-list">
            <div class="block-info-content">
                <div class="img-block">
                    <a class="div-link" href="<?php echo($this->page_service_detail.'?service_id='.$service->id); ?>"><?php esc_attr_e('Link','wpbookingevent');?></a>
                    <div>
                        <img class="lazy" data-src="<?php echo (Factory::getRootUrlPlugin());?><?php echo ($service->image);?>" >
                    </div>
                </div>
                <div class="block-feature">
                    <div class="label-feature <?php Text::_echo_no_translate($service->is_feature == 1?'visible':'');?>">
                        <span><?php esc_attr_e('Featured','wpbookingevent');?></span>
                    </div>
                </div>
            </div>
            <div class="content-infor-service">
                <p class="place-service">
                    <i class="icon-nb-pin"></i>
                    <span>
                        <?php
                        if(isset($service->location->address)){
                            echo ($service->location->address);
                        }
                        ?>
                    </span>
                </p>
                <h4 class="name-service">
                    <a href="<?php echo ($this->page_service_detail.'?service_id='.$service->id); ?>">
                        <?php echo ($service->name);?>
                    </a>
                </h4>
                <div class="block-rating">
                    <ul class="list-rating-star">
                        <?php if($average_star > 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 }?>
                    </ul>
                    <div class="rating-review">
                        <span><?php esc_html_e($number_reviews)?> <?php $number_reviews > 1 ? esc_attr_e('Reviews','wpbookingevent') : esc_attr_e('Review','wpbookingevent'); ?></span>
                    </div>
                </div>
                <div class="description">
                    <?php echo ($service->description);?>
                </div>
            </div>
            <div class="content-right">
                <div class="price-service">
                    <p class="new-price">
                        <span><i class="fas fa-bolt"></i><span>from</span></span>
                        <span class="price"><?php esc_html_e(FrontendHelper::format_currency(number_format((float)$service->price,2)));?></span>
                    </p>
                </div>
                <div class="trip-time">
                    <i class="icon-nb-clock"></i>
                    <span><?php echo ($service->duration);?> <?php esc_attr_e('hours','wpbookingevent');?></span>
                </div>
                <div class="view-more">
                    <a href="<?php echo ($this->page_service_detail.'?service_id='.$service->id); ?>" class="btn btn-primary"><?php esc_attr_e('View service','wpbookingevent');?></a>
                </div>
            </div>
        </div>
    </div>
</div>
