<?php

namespace Signteer\Web\Install\Page;

use Plainwork\Core\App;
use Plainwork\Database\Migrator;
use Plainwork\Http\Request;
use Plainwork\Http\Redirect;
use Plainwork\Ui\Html;

class UninstallPage
{
    public $app = App::class;
    public $migrator = Migrator::class;

    public function __invoke(Request $request)
    {
        $html = new Html();

        $form = $html->form();



        $vs = $form->grab($request);
        if ($vs && $form->isValid()) {
            $this->migrator->down();

            return new Redirect('');
        }

        $ret = $html->blockList($html->button('__Click to uninstall__'));
        $ret = $form->setContent($ret);

        $ret = $html->blockList()
            ->add('__This operation can not be undone.__')
            ->add($ret)
            ;

        $ret = $html->main($ret);
        $ret->title = $html->el('h1', '__Uninstall__');

        return $ret;
    }
}
