<?php

namespace App\Components\Help\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Blade;
use App\Components\Help\View\Components\HelpIcon;
use App\Components\Help\View\Components\HelpModal;

class HelpServiceProvider extends ServiceProvider
{
    /**
     * Register services.
     */
    public function register(): void
    {
        //
    }

    /**
     * Bootstrap services.
     */
    public function boot(): void
    {
        // Register routes
        Route::middleware('web')
            ->group(function () {
                $this->loadRoutesFrom(__DIR__.'/../routes/web.php');
            });

        // Register views
        $this->loadViewsFrom(__DIR__.'/../resources/views', 'help');

        // Register Blade components
        Blade::component('help-icon', HelpIcon::class);
        Blade::component('help-modal', HelpModal::class);

        // Register migrations
        $this->loadMigrationsFrom(__DIR__.'/../database/migrations');

        // Publish assets
        $this->publishes([
            __DIR__.'/../resources/js' => public_path('js/components/help'),
            __DIR__.'/../resources/css' => public_path('css/components/help'),
        ], 'help-assets');

        // Publish views for customization
        $this->publishes([
            __DIR__.'/../resources/views' => resource_path('views/vendor/help'),
        ], 'help-views');

        // Register the main help script to be included in the layout
        view()->composer('*', function ($view) {
            $view->with('helpScriptPath', asset('js/components/help/help-system.js'));
        });
    }
}
