<?php

namespace Signteer\Web;

use Plainwork\Core\App;
use Plainwork\Http\Router;
use Plainwork\Ui\Ui;

class Boot
{
    public function __construct(App $app)
    {
        $app->onBoot(Router::class, function ($router) {
            $router
                ->shortcut('', 'admin')
                ->shortcut('admin', 'admin/sheet')

            // SHEETS
                ->any('admin/sheet', Admin\Page\Sheet\ListSheetsPage::class)
                    ->meta('admin/sheet', 'breadcrumb', '__Sign-up sheets__')
                ->any('admin/sheet/create', Admin\Page\Sheet\CreateSheetPage::class)
                ->any('admin/sheet/{sheet}', Admin\Page\Sheet\ListSignupsPage::class)
                    ->paramInt('sheet')
                    ->meta('admin/sheet/{sheet}', 'breadcrumb', [Admin\Page\Sheet\ViewSheetPage::class, 'breadcrumbTitle'])
                ->any('admin/sheet/{sheet}/edit', Admin\Page\Sheet\ViewSheetPage::class)

                ->any('admin/sheet/{sheet}/task', Admin\Page\Sheet\ListSheetTasksPage::class)
                    ->meta('admin/sheet/{sheet}/task', 'breadcrumb', '__Tasks__')
                ->any('admin/sheet/{sheet}/task/create', Admin\Page\Sheet\CreateTaskPage::class)
                ->any('admin/sheet/{sheet}/task/{task}', Admin\Page\Sheet\EditTaskPage::class)
                    ->paramInt('task')
                ->any('admin/sheet/{sheet}/assign', Admin\Page\Sheet\AssignVolunteerPage::class)
                    ->paramInt('task')
                    ->paramInt('volunteer')
                ->any('admin/sheet/{sheet}/assign/new', Admin\Page\Sheet\AssignNewVolunteerPage::class)

                ->any('admin/sheet/{sheet}/signup/{signup}', Admin\Page\Sheet\ViewSignupPage::class)
                    ->paramInt('signup')
                    ->meta('admin/sheet/{sheet}/signup/{signup}', 'breadcrumb', [Admin\Page\Sheet\ViewSignupPage::class, 'breadcrumbTitle'])
                ->any('admin/sheet/{sheet}/signup/{signup}/unassign', Admin\Page\Sheet\UnassignVolunteerPage::class)
                ->any('admin/sheet/{sheet}/signup/{signup}/notify', Admin\Page\Sheet\ResendSignupNotificationPage::class)

            // VOLUNTEERS
                ->any('admin/volunteer', Admin\Page\Volunteer\Index::class)
                    ->meta('admin/volunteer', 'breadcrumb', '__Volunteers__')
                ->any('admin/volunteer/create', Admin\Page\Volunteer\Create::class)
                // ->any('admin/volunteer/{volunteer}', Admin\Page\Volunteer\ViewVolunteerPage::class)
                ->any('admin/volunteer/{volunteer}', Admin\Page\Volunteer\Index::class)
                    ->paramInt('volunteer')

                // ->any('admin/sheet/{sheet}/task/create', Admin\Page\Sheet\CreateSheetTaskPage::class)
                // ->any('admin/sheet/{sheet}/task/{task}', Admin\Page\Sheet\ViewSheetTaskPage::class)

            // FRONT
                ->any('front/sheet/{sheet}', Front\Page\Sheet\ViewSheetPage::class)
                    ->paramInt('sheet')
                ->any('front/sheet/{sheet}/signup/create', Front\Page\Sheet\CreateSignupPage::class)
                    ->paramInt('task')

            // INSTALL
                ->middleware('*', Install\Middleware\CheckInstallMiddleware::class, 25)
                ->any('install', Install\Page\InstallPage::class)
                // ->any('uninstall', Install\Page\UninstallPage::class)

            // ADMIN
                ->any('admin', Admin\Page\SettingIndexPage::class)
                ->any('admin/setting', Admin\Page\SettingIndexPage::class)
                    ->meta('admin/setting', 'breadcrumb', '__Settings__')
                ->any('admin/setting/general', Admin\Page\GeneralSettingPage::class)
                ->any('admin/setting/emailnotification', Admin\Page\Setting\EmailNotification\ListEmailNotificationsPage::class)
                    ->meta('admin/setting/emailnotification', 'breadcrumb', '__Email notifications__')
                ->any('admin/setting/emailnotification/edit', Admin\Page\Setting\EmailNotification\EditEmailNotificationPage::class)
                ->any('admin/about', Admin\Page\AboutPage::class)
                ;
        });

        $app->onBoot(Ui::class, function ($ui) {
            $ui
                ->renderer(\Plainwork\Ui\Component\Main::class, namespace\Common\Ui\Renderer\MainRenderer::class)
                ->renderer(\Plainwork\Ui\Component\Main::class, namespace\Admin\MainRenderer::class)
                ->renderer(\Signteer\Core\Model\SignupField::class, namespace\Common\Ui\Renderer\SignupFieldRenderer::class)
                ->renderer(\Signteer\Core\Model\Volunteer::class, namespace\Common\Ui\Renderer\VolunteerRenderer::class)
                ->renderer(\Signteer\Core\Model\Task::class, namespace\Common\Ui\Renderer\TaskRenderer::class)
                ;
        });
    }
}
