<?php

namespace Joydea\RichEditor;

use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Joydea\RichEditor\View\Components\RichEditor;

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

    public function boot(): void
    {
        // <x-rich-editor> と、そのビューの名前空間（rich-editor::…）を登録。
        $this->loadViewsFrom(__DIR__.'/../resources/views', 'rich-editor');
        Blade::component('rich-editor', RichEditor::class);

        if ($this->app->runningInConsole()) {
            // 設定：config/rich-editor.php
            $this->publishes([
                __DIR__.'/../config/rich-editor.php' => config_path('rich-editor.php'),
            ], 'rich-editor-config');

            // ビルド済みアセット（JS/CSS）：public/vendor/rich-editor/
            $this->publishes([
                __DIR__.'/../dist' => public_path('vendor/rich-editor'),
            ], 'rich-editor-assets');

            // ビューを上書きしたい場合：resources/views/vendor/rich-editor/
            $this->publishes([
                __DIR__.'/../resources/views' => resource_path('views/vendor/rich-editor'),
            ], 'rich-editor-views');
        }
    }
}
