<?php

namespace Portal\Mileage;

use Illuminate\Support\ServiceProvider as BaseServiceProvider;
use App\Enums\Permission;
use DB;
use Carbon\Carbon;

/**
 * Class PackageServiceProvider
 *
 * @package Portal\Ecuti
 * @see http://laravel.com/docs/master/packages#service-providers
 * @see http://laravel.com/docs/master/providers
 */
class ServiceProvider extends BaseServiceProvider
{
    /**
     * Indicates if loading of the provider is deferred.
     *
     * @see http://laravel.com/docs/master/providers#deferred-providers
     * @var bool
     */
    protected $defer = false;


    /**
     * The event listener mappings for the application.
     *
     * @var array
     */
    protected $listen = [
        
        \Portal\Mileage\Events\NotifyEmail::class => [
            \Portal\Mileage\Handlers\Events\SentEmail::class
        ],
    ];



    /**
     * Register the service provider.
     *
     * @see http://laravel.com/docs/master/providers#the-register-method
     * @return void
     */
    public function register()
    {
        // $this->app->bind('staff', \Portal\Ecuti\Data\Repo\StaffRepo::class);
    }

    /**
     * Application is booting
     *
     * @see http://laravel.com/docs/master/providers#the-boot-method
     * @return void
     */
    public function boot()
    {
        $this->loadRoutesFrom(__DIR__.'/../routes/web.php');
        $this->loadViewsFrom(__DIR__.'/../resources/views', 'mileage');
        $this->menu();
        $this->loadMigrationsFrom(__DIR__.'/../database/migrations');

        //add old laravolt view directive
        $this->loadViewsFrom(realpath(__DIR__ . '/../resources/views'), 'ui');

        // allow views to be published to the storage directory
        $this->publishes(
            [realpath(__DIR__ . '/../resources/views') => base_path('resources/views/vendor/ui')],
            'views'
          );

    }

    protected function menu()
    {

     app('laravolt.menu.sidebar')->register(function (\Lavary\Menu\Builder $menus) 
     {
          $menu = $menus->add(__('Dashboard'))->data('icon', 'align justify');
          $menu->add(__('Laman Utama'), url('/home/'))
               ->data('icon', 'home')
               ->active('home/*');
          
          $menu = $menus->add(__('Borang Permohonan'))->data('icon', 'align justify');

          $now = Carbon::today()->format('Y-m-d');
          
          $menu->add(__('Permohonan Cuti Rehat'), route('mileage::applyform.index'))
               ->data('icon', 'edit outline')
               ->active('applyform/*')
               ->data('permission', Permission::APPLY_LEAVE);
         
          $menu = $menus->add(__('Senarai Permohonan'))->data('icon', 'align justify');
          $menu->add(__('Senarai Permohonan Cuti'), route('mileage::applications.index'))
               ->data('icon', 'bars')
               ->active('applications/*');
          


     });

    }
}