<?php

namespace App\Forms;

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


class EighthFormFactory 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 shall be done about it?', array(
            'one' => 'Go in and help or save the person.',
            'two' => 'The house is quarantined. Do nothing.',
        ));
        $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(16, $this->user->id);

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

    }
}