<?php
namespace Meramo\Mrmbepages\ViewHelpers;

use TYPO3\CMS\Core\Utility\GeneralUtility;
use \TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use Meramo\Mrmbepages\Domain\Model\Activepage;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;

class CssBackgroundViewHelper extends AbstractViewHelper
{
       /**
     * initialize Arguments
     * 
     * @return void
     */
    public function initializeArguments()
    {
        $this->registerArgument('endtime', 'integer', 'Page expiration Date', true);
        
    }

    public function render()
    {
        $endtime = intval($this->arguments['endtime']);

        $color = $this->getBackgroundColor($endtime);
        //$data = ['$endtime' => $endtime, '$color' => $color];
        //DebuggerUtility::var_dump($data);

        return $color;
    }

    protected function getBackgroundColor($endtime)
    {
         $between1And7 = strtotime('7 days');
        // echo '$betwwen1And7: '.$between1And7.'<br>';
         $between8And14 = strtotime('14 days');
        // echo '$betwwen8And14: '.$between8And14.'<br>';
         $between15And30 = strtotime('30 days');
        // echo '$between15And30: '.$between15And30.'<br>';
        $between31And42 = strtotime('42 days');
        // echo '$between15And30: '.$between31And42.'<br>';

        $color = '';
        if($endtime <= $between1And7) {
            $color = 'Red';
        }
        elseif(($endtime > $between1And7) && ($endtime <= $between8And14)) {
            $color = 'Orange';
        }
        elseif(($endtime > $between8And14) && ($endtime <= $between15And30)) {
            $color = 'Blue';
        }
        elseif(($endtime > $between15And30) && ($endtime <= $between31And42)) {
            $color = 'DarkBlue';
        }
        else $color = 'Black';

        return $color;
    }
}