<?php

namespace Sideso\QzLaravel;

use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;

class QzLaravelServiceProvider extends ServiceProvider
{
    public function register()
    {
      $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'qz-laravel');
      $this->registerRoutes();
    }

    public function boot()
    {
      $this->loadViewsFrom(__DIR__.'/../resources/views', 'qz-laravel');
      
      if ($this->app->runningInConsole()) {

        $this->publishes([
          __DIR__.'/../config/config.php' => config_path('qz-laravel.php'),
        ], 'config');

        // Publish assets
        $this->publishes([
          __DIR__.'/../resources/assets' => public_path('qz-laravel'),
        ], 'assets');
    
      }
    }

    protected function registerRoutes()
    {
        Route::group($this->routeConfiguration(), function () {
            $this->loadRoutesFrom(__DIR__.'/../routes/web.php');
        });
    }

    protected function routeConfiguration()
    {
        return [
            'prefix' => 'qz',
            'middleware' => config('qz-laravel.middleware'),
        ];
    }
}