<?php

namespace common\modules\testings\widgets;

use Yii;
use yii\base\Widget;
use yii\helpers\Html;

use common\components\Browser;

class BrowsersCheckWidget extends Widget
{
    const BROWSER_COOKIE = 'test_browser_cookie';

    private function check()
    {
        $browser = new Browser();

        if($browser->getBrowser() == Browser::BROWSER_CHROME)
        {
            return false;
        }
        else
        {
            return $browser;
        }
    }
    
    public function run()
    {
        $cookies = Yii::$app->request->cookies;

        if(!$cookies->get(self::BROWSER_COOKIE) && $browser = $this->check())
        {
            $cookies->add(new \yii\web\Cookie([self::BROWSER_COOKIE => 1]));
        } 

        return $this->render('BrowsersCheckWidget', compact('browser'));
    }
}
