<?php

use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\HtmlView;

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

class GuruViewGuruReview extends HtmlView
{
    public function display($tpl = null)
    {
        $this->items = $this->get('Items');
        $this->pagination = $this->get('Pagination');

        $this->currentUserReview = $this->get('CurrentUserReview');
        parent::display($tpl);
    }

    public function renderReviewTime($dateTime)
    {
        $config = Factory::getConfig();
        $now = Factory::getDate('now', $config->get('offset'));
        $reviewTime = Factory::getDate($dateTime, $config->get('offset'));

        $diff = $now->diff($reviewTime);

        $string = '';
        if ($diff->y) {
            $string .= $diff->y > 1 ? Text::sprintf('GURU_DATE_DIFF_YEARS', $diff->y) : Text::sprintf('GURU_DATE_DIFF_YEAR', $diff->y);
        } else if ($diff->m) {
            $string .= $diff->m > 1 ? Text::sprintf('GURU_DATE_DIFF_MONTHS', $diff->m) : Text::sprintf('GURU_DATE_DIFF_MONTH', $diff->m);
        } else if ($diff->d) {
            $string .= $diff->d > 1 ? Text::sprintf('GURU_DATE_DIFF_DAYS', $diff->d) : Text::sprintf('GURU_DATE_DIFF_DAY', $diff->d);
        } else if ($diff->h) {
            $string .= $diff->h > 1 ? Text::sprintf('GURU_DATE_DIFF_HOURS', $diff->h) : Text::sprintf('GURU_DATE_DIFF_HOUR', $diff->h);
        } else if ($diff->i) {
            $string .= $diff->i > 1 ? Text::sprintf('GURU_DATE_DIFF_MINUTES', $diff->i) : Text::sprintf('GURU_DATE_DIFF_MINUTE', $diff->i);
        } else {
            $string .= $diff->s > 1 ? Text::sprintf('GURU_DATE_DIFF_SECONDS', $diff->s) : Text::sprintf('GURU_DATE_DIFF_SECOND', $diff->s);
        }

        return $string;
    }
}
