<?php

namespace Meramo\Pagemanager\ViewHelpers;

use \TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;

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);

        return $color;
    }

    protected function getBackgroundColor($endtime)
    {
         $between1And7 = strtotime('7 days');
         $between8And14 = strtotime('14 days');
         $between15And30 = strtotime('30 days');
        $between31And42 = strtotime('42 days');

        $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;
    }
}
