<?php

use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Uri\Uri;

defined('_JEXEC') or die('Restricted access');

guruAdminHelper::loadGuruEditModal();
HTMLHelper::stylesheet('administrator/components/com_guru/css/review.css');

$course_search = $this->state->get('course_search');
$report_type = $this->state->get('report_type', -1);
$review_state = $this->state->get('review_state', -1);
?>

<form action="<?php echo Route::_('index.php?option=com_guru&controller=guruReviews') ?>" id="adminForm" name="adminForm" method="post">
    <table style="width: 100%;">
        <tr>
            <td>
                <input type="text" name="course_search" placeholder="<?php echo Text::_('GURU_COURSE_NAME') ?>" value="<?php echo htmlspecialchars($course_search) ?>">
                <input class="btn btn-primary" type="submit" name="submit_search" value="<?php echo Text::_('GURU_SEARCHTXT') ?>">
            </td>
            <td>
                <select class="inputbox" size="1" name="report_type" onchange="document.adminForm.submit()">
                    <option value="-1" <?php echo $report_type == -1 ? 'selected' : '' ?>><?php echo Text::_('GURU_REVIEW_ALL_REPORT_TYPES') ?></option>
                    <option value="0" <?php echo $report_type == 0 ? 'selected' : '' ?>><?php echo Text::_('GURU_REVIEW_ONLY_HAS_REPORT') ?></option>
                    <option value="1" <?php echo $report_type == 1 ? 'selected' : '' ?>>- <?php echo Text::_('GURU_REVIEW_REPORT_1_SHORT') ?></option>
                    <option value="2" <?php echo $report_type == 2 ? 'selected' : '' ?>>- <?php echo Text::_('GURU_REVIEW_REPORT_2_SHORT') ?></option>
                    <option value="3" <?php echo $report_type == 3 ? 'selected' : '' ?>>- <?php echo Text::_('GURU_REVIEW_REPORT_3_SHORT') ?></option>
                </select>
            </td>
            <td>
                <select class="inputbox" size="1" name="review_state" onchange="document.adminForm.submit()">
                    <option value="-1" <?php echo $review_state == -1 ? 'selected' : '' ?>>All States</option>
                    <option value="1" <?php echo $review_state == 1 ? 'selected' : '' ?>>- <?php echo Text::_('GURU_PUBLISHED') ?></option>
                    <option value="2" <?php echo $review_state == 2 ? 'selected' : '' ?>>- <?php echo Text::_('GURU_PENDING_REVIEW') ?></option>
                    <option value="0" <?php echo $review_state == 0 ? 'selected' : '' ?>>- <?php echo Text::_('Unpublished') ?></option>
                </select>
            </td>
            <td><?php echo $this->pagination->getLimitBox() ?></td>
        </tr>
    </table>
    <table class="table table-bordered table-striped adminlist" id="articleList">
        <thead>
            <tr>
                <th>
                    <input type="checkbox" onclick="Joomla.checkAll(this)" name="toggle" value="">
                    <span class="lbl"></span>
                </th>
                <th>Rating</th>
                <th>Course</th>
                <th>Content</th>
                <th>Reports</th>
                <th>State</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($this->items as $key => $item) : ?>
                <tr>
                    <td>
                        <?php echo HTMLHelper::_('grid.id', $key, $item->id, false, 'cid', 'cb', $item->id); ?>
                        <span class="lbl"></span>
                    </td>
                    <td>
                        <?php echo $this->renderRatingScore($item->rating) ?>
                        <div>User: <a href="<?php echo Route::_('index.php?option=com_guru&controller=guruCustomers&task=edit&cid[]=' . $item->user_id) ?>" target="_blank"><?php echo $item->reviewer ?></a></div>
                        <div>Date: <?php echo $item->review_time ?></div>
                    </td>
                    <td>
                        <a href="<?php echo Route::_('index.php?option=com_guru&controller=guruPrograms&task=edit&cid[]=' . $item->course_id) ?>" target="_blank">
                            <?php echo $item->course_name ?>
                        </a>
                    </td>
                    <td>
                        <a href="javascript:;" onclick="guruModal.small('<?php echo Route::_('index.php?option=com_guru&controller=guruReviews&task=viewContent&tmpl=component&id=' . $item->id) ?>')">
                            <?php echo Text::_('GURU_SHOW') ?>
                        </a>
                    </td>
                    <td>
                        <?php if ($item->num_report) : ?>
                            <a style="color: #d15b47" href="javascript:;" onclick="guruModal.small('<?php echo Route::_('index.php?option=com_guru&controller=guruReviews&task=viewReport&tmpl=component&id=' . $item->id) ?>')">
                                <?php
                                echo $item->num_report > 1
                                    ? Text::sprintf('GURU_REVIEW_NUM_REPORTS', $item->num_report)
                                    : Text::sprintf('GURU_REVIEW_NUM_REPORT', $item->num_report)
                                ?>
                            </a>
                        <?php else: ?>
                            <small><?php echo Text::_('GURU_REVIEW_NO_REPORT') ?></small>
                        <?php endif ?>
                    </td>
                    <td>
                        <?php
                        switch ($item->state) {
                            case '1':
                                $icon = 'administrator/components/com_guru/images/tick.png';
                                break;

                            case '2':
                                $icon = 'administrator/components/com_guru/images/pending-check.png';
                                break;

                            default:
                                $icon = 'administrator/components/com_guru/images/publish_x.png';
                                break;
                        }
                        ?>
                        <img src="<?php echo Uri::root() . $icon ?>" alt="">
                    </td>
                </tr>
            <?php endforeach ?>
        </tbody>
    </table>
    <?php echo $this->pagination->getListFooter(); ?>
    <?php echo HTMLHelper::_('form.token') ?>
    <input type="hidden" name="boxchecked" value="0">
    <input type="hidden" name="task" value="">
</form>
