<?php

namespace Acme\ContactForm;

use Illuminate\Support\ServiceProvider;
use Livewire\Livewire;

class ContactFormServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        $this->mergeConfigFrom(
            __DIR__.'/../config/contact-form.php',
            'contact-form'
        );

        $this->app->singleton(ContactFormService::class, function (): ContactFormService {
            return new ContactFormService;
        });
    }

    public function boot(): void
    {
        $this->loadViewsFrom(__DIR__.'/../resources/views', 'contact-form');

        $this->loadTranslationsFrom(__DIR__.'/../lang', 'contact-form');

        Livewire::component('contact-form', \Acme\ContactForm\Livewire\ContactForm::class);

        if ($this->app->runningInConsole()) {
            $this->publishes([
                __DIR__.'/../config/contact-form.php' => config_path('contact-form.php'),
            ], 'contact-form-config');

            $this->publishes([
                __DIR__.'/../resources/views' => resource_path('views/vendor/contact-form'),
            ], 'contact-form-views');

            $this->publishes([
                __DIR__.'/../lang' => lang_path('vendor/contact-form'),
            ], 'contact-form-lang');
        }
    }
}
