<?php

use WpBookingEvent\Factory as FactoryAlias;
use WpBookingEvent\Html\ToolBar;
use WpBookingEvent\Html\WpBookingEventHtmlBackend as WpBookingEventHtmlBackendAlias;
use WpBookingEvent\Utilities\Utility as UtilityAlias;
use WpBookingEvent\Language\Text;
use WpBookingEventAdmin\app\Html\HtmlBackend;

$doc = FactoryAlias::getDocument();
WpBookingEventHtmlBackendAlias::load_jquery_library('icheck');
ToolBar::setTitle("List review");
WpBookingEventHtmlBackendAlias::load_jquery_library('datatables');

?>
    <form action="<?php echo(UtilityAlias::getBackendGoToLink("review.form")) ?>" name="admin-form" method="post">
        <div class="view-list-review">
            <table id="example" class="display table">
                <thead>
                    <tr>
                        <th class="nowrap"></th>
                        <th class="view-list-review-th nowrap"><?php esc_attr_e('REVIEWER','wpbookingevent')?></th>
                        <th class="view-list-review-th nowrap"><?php esc_attr_e('Comment','wpbookingevent')?></th>
                        <th class="view-list-review-th nowrap"><?php esc_attr_e('Email','wpbookingevent')?></th>
                        <th class="view-list-review-th nowrap"><?php esc_attr_e('Rating','wpbookingevent')?></th>
                        <th class="view-list-review-th nowrap"><?php esc_attr_e('Service Name','wpbookingevent')?></th>
                        <th class="view-list-review-th nowrap"><?php esc_attr_e('Note','wpbookingevent')?></th>
                        <th class="view-list-review-th nowrap"><?php esc_attr_e('Id','wpbookingevent')?></th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($this->list as $item){?>
                    <tr>
                        <td class="sorting_1"><?php echo (HtmlBackend::render_checkbox($item->id)) ?></td>
                        <td class="name nowrap"><?php esc_html_e($item->name); ?></td>
                        <td class="name nowrap"><?php esc_html_e($item->comment); ?></td>
                        <td class="name nowrap"><?php esc_html_e($item->email); ?></td>
                        <td class="name nowrap">
                            <?php

                                $max_star = 5;
                                $tour_rating = ($item->rating_service + $item->rating_staff + $item->rating_ambience) / 3;
                                while ($tour_rating > $max_star) {
                                    $tour_rating = $tour_rating - $max_star;
                                }

                                $star = $tour_rating % 10;
                                $non_star = ($max_star - $tour_rating) % 10;
                                $half_star = ceil($max_star - $star - $non_star);
                                $i = 1;


                            ?>
                            <?php if($item->rating_service >= 0 && $item->rating_staff >= 0 && $item->rating_ambience >= 0) {?>
                                <?php for ($i=0; $i <$star; $i++) {?>
                                    <li class="item-star"><i class="fas fa-star"></i></li>
                                <?php }?>
                                <?php for ($i=0; $i <$half_star; $i++) {?>
                                    <li class="item-star"><i class="fas fa-star-half-alt"></i></li>
                                <?php }?>
                                <?php for ($i=0; $i <$non_star; $i++) {?>
                                    <li class="item-star"><i class="far fa-star"></i></li>
                                <?php }?>
                            <?php }?>
                        </td>
                        <td class="name nowrap"><?php esc_html_e($item->service_name); ?></td>
                        <td class="category-description nowrap"><?php esc_html_e($item->description)?></td>
                        <td class="id nowrap"><?php esc_html_e($item->id); ?></td>
                        <td class="state-action">
                            <a href="<?php echo(UtilityAlias::getBackendGoToLink("review.form",array('id'=>$item->id))) ?>" class="btn-edit" title="<?php esc_attr_e('Edit','wpbookingevent')?>"><i class="fas fa-edit"></i></a>
                            <a href="<?php echo(UtilityAlias::goToTaskByView("review","review.delete",array('id'=>$item->id))) ?>" class="btn-delete" title="<?php esc_attr_e('Delete','wpbookingevent')?>"><i class="fas fa-trash-alt"></i></a>
                        </td>
                    </tr>
                    <?php } ?>
                </tbody>
            </table>
        </div>
        <input type="hidden" name="task" value="">
    </form>
<?php
$doc->addLessStyleSheet('admin/app/assets/less/view_list_review.less');
$doc->addScriptApplySelector('.view-list-review', 'view_list_review', array(

), "admin/app/assets/js/view_list_review.js");
?>