<?php

namespace App\Forms;

use Nette;
use Nette\Application\UI\Form;
use Nette\Security\User;
use App;


class FirstFormFactory extends Nette\Object
{
	public $results = array();
	
	/** @var User */
	private $user;


	private $GameM;


	public function __construct(User $user, App\Model\GameManager $g)
	{
		$this->user = $user;
        $this->GameM = $g;

    }

    /**
	 * @return Form
	 */
	public function create()
	{
		$form = new Form;

        $form->addRadioList('result', 'What will you do?', array(
            'one' => 'Let him go.',
            'two' => 'Force him to stay till the plague is over.',
        ));
        $form['result']->setDefaultValue('one');

        $form->addHidden("time_started",date("Y-m-d H:i:s"))->setAttribute("id","time_started");
        $form->addSubmit('send', 'Submit')->setAttribute('id','send-input');

        $form->onSuccess[] = array($this, 'formSucceeded');
        return $form;
	}


	public function formSucceeded(Form $form, $values)
    {
        $this->GameM->MoveNextStage(2, $this->user->id);

        if ($values['result'] == 'one')
        {
            $this->GameM->MorePlague($this->user->id);
            $this->GameM->InsertResult($this->user->id, 1, 1);
        }
        else {
            $this->GameM->InsertResult($this->user->id, 1, 2);
        }

	}

}
