<?php

use WpBookingEvent\Factory;
use WpBookingEventFrontend\app\helpers\FrontendHelper;
use WpBookingEventFrontend\app\Html\HtmlFrontend;
use WpBookingEventFrontend\app\helpers\ConfigHelper as ConfigHelperAlias;

$doc = Factory::getDocument();
$doc->addLessStyleSheet('frontend/app/assets/less/view_payment_cancel.less');
$doc->addStyleSheet('frontend/app/assets/nb-font-icon/nb-font-icon.css');
$item = $this->order->list_rate;
$price_service=$item[0]->service_price;
if(isset($price_service)){
    $price_total_event=0;
    foreach ($item as $item){
        $price_total_event +=$item->event_price;
    }
    $total = $price_total_event + $price_service;
} else {
    $total=$item[0]->total;
}


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

$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 = "";
}
if(isset($item->service_name)) {
    $name=$item->service_name;
} else {
    $name=$item[0]->event_name;
}

if(isset($item->service_id)){
    $link=($this->page_service_detail . '?service_id=' . $item->service_id);
} else {
    $link =($this->page_event_detail . '?event_id=' . $item[0]->event_id);
}?>
    <div class="bread-crumb-payment">
        <a class="link-category"
           href="<?php echo $link ?>"><?php esc_html_e($name); ?></a>
        <i class="icon-nb-down-arrow"></i>
        <span><?php esc_attr_e('Cancel','wpbookingevent'); ?></span>
    </div>
    <div class="title-payment">
        <h2><?php esc_attr_e('Cancel','wpbookingevent')?></h2>
    </div>
    <div class="view-payment-cancel">
        <div class="view-list-paynow">
            <div class="row">
                <div class="col-md-12">
                    <div class="information">
                        <p class="service-name"><?php esc_html_e($name) ?></p>
                        <div class="price">
                            <div class="icon-nb-price">
                                <i class="icon-Vector5"></i>
                                <p><?php echo(FrontendHelper::format_currency($total)) ?></p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <?php if(!empty((array)($this->order->list_rate))) {?>
                <?php foreach ($this->order->list_rate as $item) { ?>
                    <?php $this->item = $item ?>
                <?php } ?>
                <?php $this->loadTemplate('list_item') ?>
            <?php }?>
            <div class="row">
                <div class="col-sm-12 col-md-12">
                    <div class="cart-totals" >
                        <div class="detail-cart">
                            <?php if(!empty((array)($this->order->list_rate))) { ?>
                                <div class="block-payment-total">
                                    <h3><?php esc_attr_e('Total To Pay:','wpbookingevent')?></h3>
                                    <p class="subtotal_price"><?php echo(FrontendHelper::format_currency($total)); ?></p>

                                </div>
                            <?php } else {?>
                                <h3><?php esc_attr_e('Payment totals','wpbookingevent')?></h3>
                                <div class="block-payment-total">
                                    <p ><?php esc_attr_e('Payment subtotal','wpbookingevent')?></p>
                                    <p class="subtotal_price"><?php echo(HtmlFrontend::render_price($this->order_package->total)); ?></p>

                                </div>
                            <?php }?>
                        </div>
                        <div class="suggestion">
                            <p><?php esc_attr_e('If you wish to proceed with the payment!','wpbookingevent')?></p>
                        </div>
                        <div class="checkout-cart">
                            <?php if(!empty((array)($this->order->list_rate))) {?>
                                <?php echo($this->paymentPlugin->onAfterOrderConfirm($this->order)) ?>
                            <?php }?>
                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>

<?php
$doc->addScriptApplySelector('.view-payment-cancel','view_payment_paynow',array(
    "list_rate"=>  $this->order->list_rate
),'frontend/app/assets/js/view_payment_paynow.js');
