<?php namespace Qcr\QcrTheme;

use Qcr\QcrTheme\Pages\PageObserver;
use Illuminate\Support\Facades\Route;
use Anomaly\PagesModule\Page\PageModel;
use Anomaly\FaqsBlockExtension\FaqsBlockExtension;
use Anomaly\Streams\Platform\Addon\AddonServiceProvider;
use Anomaly\WysiwygBlockExtension\WysiwygBlockExtension;
use Anomaly\AccordionBlockExtension\AccordionBlockExtension;

class QcrThemeServiceProvider extends AddonServiceProvider
{

    /**
     * The addon routes.
     *
     * @type array|null
     */
    protected $routes = [
        'ics/posts/{id}'     => [
            'as'   => 'anomaly.module.posts::posts.ics',
            'uses' => 'Qcr\QcrTheme\Http\Controller\IcsController@post',
        ],
        'ics/events/{id}'    => [
            'as'   => 'events.ics',
            'uses' => 'Qcr\QcrTheme\Http\Controller\IcsController@events',
        ],
        'assets/get-domains' => 'Qcr\QcrTheme\Http\Controller\DomainsController@index',
    ];

    /**
     * Boot the addon.
     *
     * @param WysiwygBlockExtension $wysiwygBlockExtension
     */
    public function boot(WysiwygBlockExtension $wysiwygBlockExtension)
    {
        PageModel::observe(PageObserver::class);

        Route::any('login', function () {
            abort(404);
        });

        Route::any('register', function () {
            abort(404);
        });
        
        $wysiwygBlockExtension->setWrapper('qcr.theme.qcr::addons.anomaly.wysiwyg_block-extension.wrapper');

        if (class_exists(FaqsBlockExtension::class)) {
            app(FaqsBlockExtension::class)->setWrapper('qcr.theme.qcr::addons.anomaly.faqs_block-extension.wrapper');
        }
        
        if (class_exists(AccordionBlockExtension::class)) {
            app(AccordionBlockExtension::class)->setWrapper('qcr.theme.qcr::addons.anomaly.accordion_block-extension.wrapper');
        }
    }

}
