<?php

namespace Sartoric\ModularCms\Providers;

use Sartoric\ModularCms\Helpers\Helper;
use Sartoric\ModularCms\Middleware\LockAccount;
use Sartoric\ModularCms\Middleware\ViewRights;

use Illuminate\Support\ServiceProvider;

class McmsServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
//  PUBLISH
//        Config
        $this->publishes([
            __DIR__.'/../Config/modularcms.php' => config_path('modularcms.php'),
        ]);
//        Assets
        $this->publishes([
            __DIR__.'/../assets' => public_path(Helper::VENDORPATH.'/assets/'),
        ], 'public');
//        Translations
        $this->publishes([
            __DIR__.'/../translations' => resource_path('lang/vendor/sartoric'),
        ]);

//  LOADER
//        Views
        $this->loadViewsFrom(__DIR__.'/../Views', 'modularcms');
//        Routes
        $this->loadRoutesFrom(__DIR__.'/../Routes/web.php');
//        Migrations
        $this->loadMigrationsFrom(__DIR__.'/../Migrations');
//        Translations
        $this->loadTranslationsFrom(__DIR__.'/../Translations', 'modularcms');

//       Config
        // TODO override auth.php provider / user / model
        //$this->app['config']['auth'] =  \Config::get('::auth');

//      Package middleware
        $this->app['router']->aliasMiddleware('lock' , LockAccount::class);
        $this->app['router']->aliasMiddleware('view.rights', ViewRights::class);

        //Share menu items with main view
        view()->composer(['modularcms::layouts.main'],'Sartoric\ModularCms\ViewComposers\MenuComposer');
        // load package helpers
        $this->loadHelpers();
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        // ...
    }

    protected function loadHelpers()
    {
        if (file_exists($file = __DIR__ . '/../Helpers/Helper.php')) {
            require_once $file;
        }
    }
}
