<?php

namespace Acme\CookieConsent;

use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;

class CookieConsentServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        $this->mergeConfigFrom(
            __DIR__.'/../config/cookie-consent.php',
            'cookie-consent'
        );
    }

    public function boot(): void
    {
        // Views laden
        $this->loadViewsFrom(__DIR__.'/../resources/views', 'cookie-consent');

        // Anonyme Blade-Komponenten registrieren (ermöglicht <x-cookie-consent::manager />)
        Blade::anonymousComponentPath(__DIR__.'/../resources/views/components', 'cookie-consent');

        // Übersetzungen laden
        $this->loadTranslationsFrom(__DIR__.'/../lang', 'cookie-consent');

        if ($this->app->runningInConsole()) {
            // Config veröffentlichen
            $this->publishes([
                __DIR__.'/../config/cookie-consent.php' => config_path('cookie-consent.php'),
            ], 'cookie-consent-config');

            // Views veröffentlichen
            $this->publishes([
                __DIR__.'/../resources/views' => resource_path('views/vendor/cookie-consent'),
            ], 'cookie-consent-views');

            // Übersetzungen veröffentlichen
            $this->publishes([
                __DIR__.'/../lang' => lang_path('vendor/cookie-consent'),
            ], 'cookie-consent-lang');
        }
    }
}
