<?php
// app/Providers/ResourceServiceProvider.php

namespace App\Providers;

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

class ResourceServiceProvider extends ServiceProvider
{
    public function register()
    {
        $this->app->singleton(\App\Services\ResourceManagerService::class, function ($app) {
            return new \App\Services\ResourceManagerService();
        });
    }

    public function boot()
    {
        // Écoutez l'événement 'router.matched' pour chaque requête entrante
        $this->app['router']->matched(function ($event) {
            $route = $event->route;
            $this->loadResourcesForRoute($route);
        });
    }

    protected function loadResourcesForRoute($route)
    {
        // Obtenez le nom de la route
        $routeName = $route->getName();

        // Ajoutez les ressources CSS et JS en fonction du nom de la route
        $resourceService = app(\App\Services\ResourceManagerService::class);

        switch ($routeName) {
                // Add route resource s
            case 'home':
                $resourceService->addCss('css/home.css');
                $resourceService->addJs('js/home.js');
                break;

                // Brand route
            case 'brand':
                // $resourceService->addCss('css/home.css');
                $resourceService->addJs('ressources-app/back-office/js/brand/datatable.js');
                break;


            case 'model':
                // $resourceService->addCss('css/home.css');
                $resourceService->addJs('ressources-app/back-office/js/modele/datatable.js');
                break;


            case 'destinationtype':
                // $resourceService->addCss('css/home.css');
                $resourceService->addJs('ressources-app/back-office/js/destinationtype/datatable.js');
                break;


            case 'destination':
                // $resourceService->addCss('css/home.css');
                $resourceService->addJs('ressources-app/back-office/js/destination/datatable.js');
                break;


            case 'conductor':
                // $resourceService->addCss('css/home.css');
                $resourceService->addJs('ressources-app/back-office/js/conductor/datatable.js');
                break;

            case 'color':
                // $resourceService->addCss('css/home.css');
                $resourceService->addJs('ressources-app/back-office/js/color/datatable.js');
                break;

            case 'cartype':
                // $resourceService->addCss('css/home.css');
                $resourceService->addJs('ressources-app/back-office/js/cartype/datatable.js');
                break;

            case 'fueltype':
                // $resourceService->addCss('css/home.css');
                $resourceService->addJs('ressources-app/back-office/js/fueltype/datatable.js');
                break;

            case 'transmissionintype':
                // $resourceService->addCss('css/home.css');
                $resourceService->addJs('ressources-app/back-office/js/transmissiontype/datatable.js');
                break;


            case 'car':
                // $resourceService->addCss('css/home.css');
                $resourceService->addJs('ressources-app/back-office/js/car/datatable.js');
                break;


            case 'reservation':
                // $resourceService->addCss('css/home.css');
                $resourceService->addJs('https://npmcdn.com/flatpickr@4.6.13/dist/l10n/fr.js');
                $resourceService->addJs('ressources-app/back-office/js/reservation/flatpicker.js');
                break;
            case 'reservation.list':
                // $resourceService->addCss('css/home.css');
                $resourceService->addJs('ressources-app/back-office/js/reservation/datatable.js');
                break;


            default:
                // $resourceService->addCss('ressources-app/back-office/css/theme-one.css');
                // $resourceService->addJs('js/common.js');
                break;
        }
    }
}
