<?php

namespace App\Forms;

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


class TenthFormFactory 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', 'Who would get the priority?', array(
            'one' => 'Children.',
            'two' => 'The ill.',
            'three' => 'Working men and women.',
            'four' => 'Don’t prioritize anybody.',
        ));
        $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->addSubmit('skip', 'Skip >>')->setAttribute('id', 'send-input3');

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


    public function formSucceeded(Form $form, $values)
    {
        $this->GameM->MoveNextStage(20, $this->user->id);
        $submit = $form->isSubmitted()->getName();
        if ($submit == 'send') {
            if ($values['result'] == 'one') {
                $this->GameM->KillPeople($this->user->id, 30);
                $this->GameM->InsertResult($this->user->id, 10, 1);
            } else if ($values['result'] == 'two') {
                $this->GameM->InsertResult($this->user->id, 10, 2);
            } else if ($values['result'] == 'three') {
                $this->GameM->InsertResult($this->user->id, 10, 3);
            } else {
                $this->GameM->InsertResult($this->user->id, 10, 4);
            }
        } else {
            $this->GameM->InsertResult($this->user->id, 10, 0);
        }
    }
}