<?php

namespace Plainwork\UiWordPress;

use Plainwork\Core\App;
use Plainwork\Ui\Ui;
use Plainwork\Ui\Component\Link;
use Plainwork\Ui\Component\Main;
use Plainwork\Ui\Component\Table;
use Plainwork\Ui\Renderer\MainMenuRenderer;
use Plainwork\Ui\Component\TabMenu;
use Plainwork\Ui\Component\Nav;
use Plainwork\Ui\Component\Menu;
use Plainwork\Ui\Component\Ul;
use Plainwork\Ui\Component\Form\Button;
use Plainwork\Ui\Component\Form\ButtonInput;

class Boot
{
    public function __construct(App $app)
    {
        if (is_admin()) {
            $app->decorate(MainMenuRenderer::class, '__invoke', Renderer\AdminMainMenuRenderer::class);
        }

        $app->onBoot(Ui::class, function ($ui) {
            $ui
                ->renderer(Main::class, Renderer\MainRendererDecorator::class)
                ;

            if (is_admin()) {
                $ui
                    ->renderer(Menu::class, Renderer\AdminMenuRenderer::class)
                    ->renderer(Table::class, Renderer\AdminTableRenderer::class)
                    ->renderer(Link::class, Renderer\AdminLinkRenderer::class)
                    ->renderer(Ul::class, Renderer\AdminUlRenderer::class)
                    ->renderer(TabMenu::class, Renderer\AdminTabMenuRenderer::class)
                    ->renderer(Button::class, Renderer\Form\AdminButtonRendererDecorator::class)
                    ->renderer(ButtonInput::class, Renderer\Form\AdminButtonInputRendererDecorator::class)
                    // ->renderer(\Plainwork\Ui\Component\Card::class, Renderer\AdminCardRenderer::class)
                    ;
            } else {
                $ui
                    ->renderer(Button::class, Renderer\Form\FrontButtonRendererDecorator::class)
                    ;
            }
        });
    }
}
