<?php

namespace App\Modules\Bookings;

use Laracasts\Presenter\Presenter;

define('DAY', '86400');
    define('HOUR', '3600');
    define('MINUTE', '60');
class TaskPresenter extends Presenter
{
    public function formatedProblemLimited()
    {
        $text = strip_tags($this->problem, '<br><br/>');

        return strlen($text) > 650 ? substr($text, 0, 420).'...' : $text;
    }

    public function formatedProblem()
    {
        return  strip_tags($this->problem, '<br><br/>');
    }

    public function shortFormatAttendedTime()
    {
        return self::shortFormatTime($this->attended_time);
    }

    public function shortFormatUnattendedTime()
    {
        return self::shortFormatTime($this->unattended_time);
    }

    public function attendedTime()
    {
        return self::longFormatTime($this->attended_time);
    }

    public function unattendedTime()
    {
        return self::longFormatTime($this->unattended_time);
    }

    public function longFormatTime($seconds)
    {
        $toPrint = '';

        if ($seconds / DAY >= 1) {
            $word = floor($seconds / DAY) == 1 ? 'day ' : 'days ';
            $toPrint .= floor($seconds / DAY).' '.$word;
            $seconds = $seconds % DAY;
        }

        if ($seconds / HOUR >= 1) {
            $word = floor($seconds / HOUR) == 1 ? 'hour ' : 'hours ';
            $toPrint .= floor($seconds / HOUR).' '.$word;
            $seconds = $seconds % HOUR;
        }

        if ($seconds / MINUTE >= 1) {
            $word = floor($seconds / MINUTE) == 1 ? 'minute ' : 'minutes ';
            $toPrint .= floor($seconds / MINUTE).' '.$word;
            $seconds = $seconds % MINUTE;
        }

        return $toPrint;
    }

    public function shortFormatTime($seconds)
    {
        $toPrint = '';

        if ($seconds / DAY >= 1) {
            $toPrint .= floor($seconds / DAY).'d';
            $seconds = $seconds % DAY;
        }

        if ($seconds / HOUR >= 1) {
            $toPrint .= ($toPrint ? ' ' : '').floor($seconds / HOUR).'h';
            $seconds = $seconds % HOUR;
        }

        if ($seconds / MINUTE >= 1) {
            $toPrint .= ($toPrint ? ' ' : '').floor($seconds / MINUTE).'m';
            $seconds = $seconds % MINUTE;
        }

        return $toPrint;
    }
}
