<?php

use WpBookingEvent\Factory as FactoryAlias;
use WpBookingEvent\Html\WpBookingEventHtmlFrontend;
use WpBookingEventFrontend\app\helpers\FrontendHelper;
use WpBookingEventFrontend\app\Html\HtmlFrontend;
use WpBookingEventFrontend\app\helpers\ConfigHelper as ConfigHelperAlias;
WpBookingEventHtmlFrontend::load_jquery_library('slick');
WpBookingEventHtmlFrontend::load_jquery_library('validate');
WpBookingEventHtmlFrontend::load_jquery_library('confirm');
$doc = FactoryAlias::getDocument();
$doc->addStyleSheet('frontend/app/assets/nb-font-icon/nb-font-icon.css');
$doc->addLessStyleSheet('frontend/app/assets/less/view_service_detail.less');
$appConfig = FactoryAlias::getAppConfig();
$booking_style = $appConfig->get('booking_style', 'in_line');
$is_multi_product_in_cart = HtmlFrontend::is_multi_product_in_cart();
if(!empty((array)$this->item) ) {
    $price_event=0;
    foreach ($this->list_event as $event){
        $price_event += $event->price;
    }
    $open_time = $this->item->open_time;
    $open_time = date('h:i A', strtotime($open_time));
    $close_time = $this->item->close_time;
    $close_time = date('h:i A', strtotime($close_time));
    $working_day = $this->item->working_day;
    $working_day = isset($working_day) ? json_decode($working_day) : array();
}

$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 = "";
}

$page_event_detail=ConfigHelperAlias::get_page_event_detail();
if ($page_event_detail) {
    $this->page_event_detail = get_page_link($page_event_detail);
} else {
    $this->page_event_detail = "";
}
$page_list_category = ConfigHelperAlias::get_page_list_category();
if ($page_list_category) {
    $this->page_list_category = get_page_link($page_list_category);
} else {
    $this->page_list_category = "";
}
?>
    <div class="view-service-detail">
        <?php if(!empty( (array)$this->item)) {?>

        <div class="bread-crumb">
            <a class="link-category"
               href="<?php echo($this->page_list_service . '?category=' . $this->item->category->id) ?>"><?php esc_html_e($this->item->category->name); ?></a>
            <i class="icon-nb-down-arrow"></i>
            <span><?php esc_html_e($this->item->name); ?></span>
        </div>
        <div class="block-alert"></div>
        <div class="gallery-container">
            <div class="wrapper-gallery-slider">
                <a class="arrow-prev"><i class="icon-nb-down-arrow"></i></a>
                <a class="arrow-next"><i class="icon-nb-down-arrow"></i></a>
                <div class="block-gallery-slider-large">
                    <?php foreach ($this->item->list_image as $image) { ?>
                        <div class="img-gallery-large">
                            <div>
                                <img src="<?php echo(FactoryAlias::getRootUrlPlugin()) ?><?php esc_html_e($image->path) ?>"alt="image-gallery">
                            </div>
                        </div>
                    <?php } ?>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-8 col-lg-8">
                <div class="block-title-service">
                    <h2><?php esc_html_e($this->item->name); ?></h2>
                    <p> <i class=""></i><?php echo(isset($this->item->location->address) ? $this->item->location->address : ''); ?></p>
                </div>
                <div id="listing-nav" class="listing-nav-container">
                    <ul class="listing-nav">
                        <li><a href="#overview" class=""><?php esc_html_e('Overview', 'wpbookingevent')?></a></li>
                        <li><a href="#booking" class=""><?php esc_html_e('Booking', 'wpbookingevent')?></a></li>
                        <li><a href="#reviews" class=""><?php esc_html_e('Reviews', 'wpbookingevent')?></a></li>
                        <li><a href="#add-review"><?php esc_html_e('Add Review', 'wpbookingevent')?></a></li>
                    </ul>
                </div>
                <div id="overview" class="service-information">
                    <p><?php echo(html_entity_decode($this->item->description)); ?></p>
                </div>
                <div class="block-location-info">
                    <h3><?php esc_html_e('event location', 'wpbookingevent')?></h3>
                    <div class="map-block">
                        <?php echo(isset($this->item->location->iframe) ? html_entity_decode($this->item->location->iframe) : ''); ?>
                    </div>
                </div>

                <div class="service-title-war"><h3><?php esc_html_e('Booking Process', 'wpbookingevent')?></h3></div>
                <form action="" method="post" class="booking-form" name="client-form" enctype="multipart/form-data">
                    <div id="booking" class="block-booking-information">
                        <h5><i class="icon-nb-shapes"></i><?php esc_attr_e('Select expert', 'wpbookingevent') ?></h5>
                        <?php
                        $field = $this->form->getField('employee_id');
                        echo($field->input);
                        ?>
                    </div>
                    <div class="select-time">
                        <h5><i class="icon-nb-shapes"></i><?php esc_attr_e('Select time', 'wpbookingevent') ?></h5>
                        <?php
                        $field = $this->form->getField('calendar');
                        echo($field->input);
                        ?>
                    </div>

                    <?php if ($booking_style == "in_line") { ?>
                        <div class="wrapper-block-check-out">

                            <div class="block-check-out">
                                <div class="row">
                                    <h5><i class="icon-nb-shapes"></i><?php esc_attr_e('Your Payment Detail', 'wpbookingevent') ?></h5>
                                    <div class="col-sm-6 col-md-6">
                                        <div class="input-firstname">
                                            <?php
                                            $field = $this->form->getField('first_name');
                                            echo($field->input);
                                            ?>
                                        </div>
                                    </div>
                                    <div class="col-sm-6 col-md-6">
                                        <div class="input-lastname">
                                            <?php
                                            $field = $this->form->getField('last_name');
                                            echo($field->input);
                                            ?>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-sm-6 col-md-6">
                                        <div class="input-email">
                                            <?php
                                            $field = $this->form->getField('email');
                                            echo($field->input);
                                            ?>
                                        </div>
                                    </div>
                                    <div class="col-sm-6 col-md-6">
                                        <div class="input-phone">
                                            <?php
                                            $field = $this->form->getField('phone');
                                            echo($field->input);
                                            ?>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="block-select-payment">
                                <?php
                                $field = $this->form->getField('payment_id');
                                $disable_payment_online = (boolean)isset($this->item->disable_payment_online) ? $this->item->disable_payment_online : false;
                                $field->setDisablePaymentOnline($disable_payment_online);
                                ?>
                                <h5><i class="icon-nb-shapes"></i><?php esc_attr_e('Select payment', 'wpbookingevent') ?></h5>
                                <?php echo($field->input); ?>
                            </div>
                            <div class="block-information">
                                <h5><i class="icon-nb-shapes"></i><?php esc_attr_e('Booking Information', 'wpbookingevent') ?></h5>
                                <div class="row">
                                    <div class="col-sm-6 col-md-6">
                                        <div class="infor-payment-left">
                                            <p><?php esc_attr_e('Expert:', 'wpbookingevent') ?><span
                                                    class="trainer-info"></span></p>
                                            <p><?php esc_attr_e('Local time:', 'wpbookingevent') ?><span
                                                    class="local-time"></span></p>
                                            <p><?php esc_attr_e('Location', 'wpbookingevent') ?>: <span
                                                    class="location-info"><?php echo(isset($this->item->location->address) ? $this->item->location->address : '') ?></span>
                                            </p>
                                        </div>
                                    </div>
                                    <div class="col-sm-6 col-md-6">
                                        <div class="info-payment-right">
                                            <p><?php esc_attr_e('Date', 'wpbookingevent') ?>: <span class="date-info"></span>
                                            </p>
                                            <p><?php esc_attr_e('Location', 'wpbookingevent') ?>: <span
                                                    class="location-info"><?php echo(isset($this->item->location->address) ? $this->item->location->address : '') ?></span>
                                            </p>
                                            <p><?php esc_attr_e('All events of the service:', 'wpbookingevent') ?></p>
                                            <ul>
                                                <?php foreach ($this->list_event as $item){ ?>
                                                    <li><a href="<?php echo( $this->page_event_detail . '?event_id=' . $item->id) ?>"><?php esc_html_e($item->name) ?> (<?php esc_html_e(FrontendHelper::format_currency($item->price))?>)</a></li>
                                                <?php } ?>
                                            </ul>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="block-payment-item">
                                <h5><i class="icon-nb-shapes"></i><?php esc_attr_e('Payment info', 'wpbookingevent') ?></h5>
                                <div class="detail-payment-item">
                                    <span><?php esc_attr_e('Total number of persons', 'wpbookingevent') ?>:</span>
                                    <span class="number-person">1</span>
                                </div>
                                <div class="detail-payment-item">
                                    <?php $price_total=$this->item->price + $price_event ?>
                                    <span><?php esc_attr_e('Base price', 'wpbookingevent') ?>:</span>
                                    <span class="base-price"><?php echo(FrontendHelper::format_currency(number_format((float)($this->item->price), 2))) ?></span>
                                </div>
                                <div class="detail-payment-item total-cost-event">
                                    <span><?php esc_attr_e('Total cost all event of the service', 'wpbookingevent') ?>:</span>
                                    <span class="total-cost-sum"><?php echo(FrontendHelper::format_currency(number_format((float)$price_event, 2))) ?></span>
                                </div>
                                <div class="detail-payment-item total-cost">
                                    <span><?php esc_attr_e('Total Cost', 'wpbookingevent') ?>:</span>
                                    <span class="total-cost-sum"><?php echo(FrontendHelper::format_currency(number_format((float)$price_total, 2))) ?></span>
                                </div>
                            </div>

                            <div class="wrapper-btn-checkout">
                                <button type="button" class="btn btn-danger btn-book-now">
                                    <span><?php esc_attr_e('Book now', 'wpbookingevent') ?></span>
                                </button>
                            </div>
                        </div>
                    <?php } ?>
                    <input type="hidden" name="task" value="booking.book_service">
                    <input type="hidden" name="service_id" value="<?php esc_html_e($this->item->id) ?>"/>
                    <input type="hidden" name="event_id" value=""/>
                </form>
                <div id="reviews" class="block-review-by-customer">
                    <h4>
                        <?php echo(ucfirst(esc_attr('our beloved customer reviews'))) ?>
                    </h4>
                    <?php foreach ($this->list_review as $list_review) { ?>

                        <div class="block-review-item">
                            <div class="img-block">
                                <i class="fas fa-user-tie"></i>
                            </div>
                            <div class="block-content">
                                <?php
                                    $create_date=date('M d, Y ',strtotime($list_review->created_date));
                                    $create_hour=date('h:m ', strtotime($list_review->created_date));
                                ?>
                                <h5><?php esc_html_e($list_review->name) ?></h5>
                                <h6><?php esc_html_e($create_date) ?>
                                    <span><?php esc_attr_e('at', 'wpbookingevent') ?> <?php esc_html_e($create_hour) ?></span>
                                </h6>
                                <p><?php esc_html_e($list_review->comment) ?></p>

                            </div>
                            <div class="block-star-review">
                                <ul class="list-rating-star">

                                    <?php $rating_star = HtmlFrontend::get_rating_star($list_review->rating_avg) ?>

                                    <?php for ($i = 0; $i < $rating_star[0]; $i++) { ?>
                                        <li class="item-star"><i class="fas fa-star"></i></li>
                                    <?php } ?>
                                    <?php for ($i = 0; $i < $rating_star[1]; $i++) { ?>
                                        <li class="item-star"><i class="fas fa-star-half-alt"></i></li>
                                    <?php } ?>
                                    <?php for ($i = 0; $i < $rating_star[2]; $i++) { ?>
                                        <li class="item-star"><i class="far fa-star"></i></li>
                                    <?php }
                                    ?>

                                </ul>
                            </div>
                        </div>
                    <?php } ?>
                </div>
                <form id="add-review" action="" method="post" class="review-form" name="reviewer-form">
                    <div class="review">
                        <div class="add-review">
                            <div class="row">
                                <div class="col-md-12">
                                    <h4><?php esc_attr_e('Add Review', 'wpbookingevent') ?></h4>
                                    <p><?php esc_attr_e('Your email address will not be published. Required fields are marked *', 'wpbookingevent') ?></p>
                                </div>
                            </div>
                            <div class="row">
                                <div class=" col-sm-4 col-md-4">
                                    <div class="service-rating">
                                        <span><?php esc_attr_e('Services Rating', 'wpbookingevent') ?></span>
                                        <div class='rating-stars'>
                                            <?php
                                            $field = $this->form->getField('rating_service');
                                            echo($field->input);
                                            ?>
                                        </div>
                                    </div>
                                </div>
                                <div class=" col-sm-4 col-md-4">
                                    <div class="service-rating">
                                        <span><?php esc_attr_e('Staff Rating', 'wpbookingevent') ?></span>
                                        <div class='rating-stars'>
                                            <?php
                                            $field = $this->form->getField('rating_staff');
                                            echo($field->input);
                                            ?>
                                        </div>
                                    </div>
                                </div>
                                <div class=" col-sm-4 col-md-4">
                                    <div class="service-rating">
                                        <span><?php esc_attr_e('Ambience Rating', 'wpbookingevent') ?></span>
                                        <div class='rating-stars'>
                                            <?php
                                            $field = $this->form->getField('rating_ambience');
                                            echo($field->input);
                                            ?>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class=" col-sm-6 col-md-6">
                                    <div class="reviewer-first-name">
                                        <?php
                                        $field = $this->form->getField('full_name');
                                        echo($field->input);
                                        ?>
                                    </div>
                                </div>
                                <div class=" col-sm-6 col-md-6">
                                    <div class="reviewer-last-name">
                                        <?php
                                        $field = $this->form->getField('email');
                                        echo($field->input);
                                        ?>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-sm-12 col-md-12">
                                    <div class="review-comment">
                                        <?php
                                        $field = $this->form->getField('note');
                                        echo($field->input);
                                        ?>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class=" col-sm-12 col-md-12">
                                    <button type="button" class="btn btn-danger btn-add-review">
                                        <span><?php esc_attr_e('Post Comment', 'wpbookingevent') ?></span>
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <input type="hidden" name="task" value="review.add_review"/>
                </form>
            </div>
            <div class="col-md-4 col-lg-4">
                <div class="block-rating-service">
                    <div class="row">
                        <div class="col-xs-5 col-sm-5 col-md-5">
                            <div class="block-rating-left">
                                <h6><?php esc_attr_e('Venue rating', 'wpbookingevent') ?></h6>
                                <?php

                                $sum_avg = 0;
                                $sum_avg_service = 0;
                                $sum_avg_staff = 0;
                                $sum_avg_ambience = 0;

                                foreach ($this->list_review as $list_review){

                                    $sum_avg +=  HtmlFrontend::total_review_avg($this->list_review,$list_review->rating_avg);

                                    $sum_avg_service +=  HtmlFrontend::total_review_avg($this->list_review,$list_review->rating_service);

                                    $sum_avg_staff +=  HtmlFrontend::total_review_avg($this->list_review,$list_review->rating_staff);

                                    $sum_avg_ambience +=  HtmlFrontend::total_review_avg($this->list_review,$list_review->rating_ambience);
                                }
                                ?>
                                <h1 style="text-align: center"><?php esc_html_e(round($sum_avg,1)) ?></h1>
                                <div class="block-rating">
                                    <ul class="list-rating-star">
                                        <?php $list_star_sum = HtmlFrontend::get_rating_star($sum_avg); ?>
                                        <?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 } ?>
                                    </ul>
                                    <div class="rating-review">
                                        <span><?php esc_html_e(count($this->list_review)) ?>
                                            <span><?php count($this->list_review) <= 1 ?  esc_attr_e('review', 'wpbookingevent') :  esc_attr_e('reviews', 'wpbookingevent') ?></span>

                                        </span>

                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-7 col-sm-7 col-md-7">
                            <div class="block-rating-right">
                                <div class="item-rating">
                                    <p><?php esc_attr_e('Ambience', 'wpbookingevent') ?></p>
                                    <ul class="list-rating-star">
                                        <?php $list_star_ambience = HtmlFrontend::get_rating_star($sum_avg_ambience); ?>
                                        <?php for ($i = 0; $i < $list_star_ambience[0]; $i++) { ?>
                                            <li class="item-star"><i class="fas fa-star"></i></li>
                                        <?php } ?>
                                        <?php for ($i = 0; $i < $list_star_ambience[1]; $i++) { ?>
                                            <li class="item-star"><i class="fas fa-star-half-alt"></i></li>
                                        <?php } ?>
                                        <?php for ($i = 0; $i < $list_star_ambience[2]; $i++) { ?>
                                            <li class="item-star"><i class="far fa-star"></i></li>
                                        <?php } ?>
                                    </ul>
                                </div>
                                <div class="item-rating">
                                    <p><?php esc_attr_e('Service', 'wpbookingevent') ?></p>
                                    <ul class="list-rating-star">
                                        <?php $list_star_service = HtmlFrontend::get_rating_star($sum_avg_service); ?>
                                        <?php for ($i = 0; $i < $list_star_service[0]; $i++) { ?>
                                            <li class="item-star"><i class="fas fa-star"></i></li>
                                        <?php } ?>
                                        <?php for ($i = 0; $i < $list_star_service[1]; $i++) { ?>
                                            <li class="item-star"><i class="fas fa-star-half-alt"></i></li>
                                        <?php } ?>
                                        <?php for ($i = 0; $i < $list_star_service[2]; $i++) { ?>
                                            <li class="item-star"><i class="far fa-star"></i></li>
                                        <?php } ?>
                                    </ul>
                                </div>
                                <div class="item-rating">
                                    <p><?php esc_attr_e('Staff', 'wpbookingevent') ?></p>
                                    <ul class="list-rating-star">
                                        <?php $list_star_staff = HtmlFrontend::get_rating_star($sum_avg_staff); ?>
                                        <?php for ($i = 0; $i < $list_star_staff[0]; $i++) { ?>
                                            <li class="item-star"><i class="fas fa-star"></i></li>
                                        <?php } ?>
                                        <?php for ($i = 0; $i < $list_star_staff[1]; $i++) { ?>
                                            <li class="item-star"><i class="fas fa-star-half-alt"></i></li>
                                        <?php } ?>
                                        <?php for ($i = 0; $i < $list_star_staff[2]; $i++) { ?>
                                            <li class="item-star"><i class="far fa-star"></i></li>
                                        <?php } ?>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="block-info-working-time">
                    <div>
                        <div class="listing-badge now-open">
                            <?php esc_html_e('Now Open', 'wpbookingevent')?>
                        </div>
                        <h4 class="widget-title">
                            <?php esc_html_e('Opening Hours', 'wpbookingevent')?>
                        </h4>
                    </div>
                    <?php if(count((array)$working_day)) {?>
                        <?php foreach ($working_day as $day) {?>
                            <div class="work-time-item">
                                <span><?php echo esc_attr($day)?></span>
                                <span><?php echo esc_html($open_time);?> - <?php echo esc_html($close_time);?></span>
                            </div>
                        <?php }?>
                    <?php }?>
                </div>
                <div class="block-information-employee">
                    <div class="row hosted-by-title">
                        <div class="col-md-8">
                            <p><?php esc_attr_e('Added By', 'wpbookingevent')?></p>
                            <h4><?php esc_attr_e('jessica smith', 'wpbookingevent')?></h4>
                        </div>
                        <div class="col-md-4">
                            <img class="employee-image" src="http://demo12.cmsmart.net/event_calendar/wp-content/plugins/wpbookingevent/frontend/app/assets/image/image69.jpg" alt="employee-image" title="" style="">
                        </div>
                    </div>
                    <div class="hosted-by-bio">
                        <p><?php esc_attr_e('Quisque rhoncus tellus et suscipit pellentesque. Donec viverra eros sed justo dignissim laoreet. Aenean justo risus, imperdiet id massa ac, convallis condimentum risus.', 'wpbookingevent')?></p>
                    </div>
                    <div class="listeo_core">
                            <span>
                                <?php esc_attr_e('Please click', 'wpbookingevent')?>
                                <a class="btn-click-here" href="#"><?php esc_attr_e('here', 'wpbookingevent')?> </a>
                                <?php esc_attr_e('to see contact detail', 'wpbookingevent')?>
                            </span>
                        <a class="btn-send-message" href="#">
                            <i class="far fa-envelope"></i>
                            <p><?php esc_attr_e('Send message', 'wpbookingevent')?></p>
                        </a>
                    </div>
                </div>
                <div class="share-buttons">
                    <h4><?php esc_html_e('Please subcribe us', 'wpbookingevent')?></h4>
                    <ul>
                        <?php
                        global $wp;
                        $share_url = home_url(add_query_arg(array($_GET), $wp->request));
                        ?>
                        <li>
                            <a target="_blank" class="fb-share" href="//www.facebook.com/sharer.php?u=<?php echo esc_url($share_url); ?>"><i class="fab fa-facebook-square"></i> <?php esc_html_e('Share', 'wpbookingevent')?></a>
                        </li>
                        <li>
                            <a target="_blank" class="twitter-share" href="//twitter.com/share?url=<?php echo esc_url($share_url); ?>" title="Twitter"><i class="fab fa-twitter"></i> <?php esc_html_e('Tweet', 'wpbookingevent')?></a>
                        </li>
                        <li>
                            <a target="_blank" class="pinterest-share" href="//pinterest.com/pin/create/button/?url=<?php echo esc_url($share_url); ?>"><i class="fab fa-pinterest-p"></i><?php esc_html_e('Pin it', 'wpbookingevent')?></a>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    <?php } else {?>
            <div class="row">
                <div class="col-md-12 text-center">
                    <h3 class="page-not-found"><?php esc_html_e('Can not found service','wpbookingevent')?></h3>
                    <a class="btn btn-primary" href="<?php esc_attr_e($this->page_list_service)?>"><?php esc_html_e('List service','wpbookingevent')?></a>
                </div>
            </div>
    <?php }?>
    </div>
<?php
$doc->addScriptApplySelector('.view-service-detail', 'view_service_detail', array(
    'list_event' => $this->list_event,
    'service_item' => $this->item
), 'frontend/app/assets/js/view_service_detail.js');