<?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->add(__('Project Manager Dashboard'), route('mileage::projectManager.index'))
                ->data('icon', 'briefcase')
                ->active('projectManager/*')
                ->data('permission', Permission::PROJECT_MANAGER);

            $menu->add(__('Project Director Dashboard'), route('mileage::projectDirector.index'))
                ->data('icon', 'compass')
                ->active('projectDirector/*')
                ->data('permission', Permission::PROJECT_DIRECTOR);            

            $menu->add(__('HOD Dashboard'), route('mileage::HOD.index'))
                ->data('icon', 'black tie')
                ->active('HOD/*')
                ->data('permission', Permission::HOD);

            $menu->add(__('BOD Dashboard'), route('mileage::BOD.index'))
                ->data('icon', 'users cog')
                ->active('BOD/*')
                ->data('permission', Permission::BOD);

            $menu->add(__('HR Dashboard'), route('mileage::HR.index'))
                ->data('icon', 'id badge')
                ->active('HR/*')
                ->data('permission', Permission::HR);

            $menu->add(__('Finance Dashboard'), route('mileage::finance.index'))
                ->data('icon', 'calculator')
                ->active('finance/*')
                ->data('permission', Permission::FINANCE);
          
          $menu = $menus->add(__('Borang Permohonan Mileage Claim'))->data('icon', 'align justify');

          $now = Carbon::today()->format('Y-m-d');
          
          $menu->add(__('Bawah Projek'), route('mileage::applyform.index'))
               ->data('icon', 'check')
               ->active('applyform/*');
            
          $menu->add(__('Tiada Projek'), route('mileage::applyform.noproject'))
               ->data('icon', 'close')
               ->active('noproject/*');               
         
          $menu = $menus->add(__('Senarai Permohonan'))->data('icon', 'align justify');
          $menu->add(__('Senarai Permohonan Mileage Claim'), route('mileage::applications.index'))
               ->data('icon', 'bars')
               ->active('applications/*');

     });

    }
}