<?php

declare(strict_types=1);

namespace ViartasCore\CKEditor\Providers;

use Illuminate\Support\ServiceProvider;

/**
 * CKEditor 4 asset provider for Viartas CMS.
 *
 * Ships the full CKEditor 4 distribution (n1theme skin, image upload / YouTube
 * plugins) plus the Viartas-custom `ckeditor-init.js` — the bridge that wires
 * CKEditor's file browser to Laravel File Manager (`window.Viartas.lfmUrl`).
 *
 * Assets live in this package under Resources/assets/ and are published to the
 * host's public/vendor/ckeditor/ so the admin theme can load them via
 * `asset('vendor/ckeditor/*')`. The publish target basename MUST stay `ckeditor`
 * because that URL contract is baked into the admin layout and CKEditor's skin
 * path (`n1theme,/vendor/ckeditor/skins/n1theme/`).
 *
 * LFM (unisharp/laravel-filemanager) routes + config live in va-cross/media and
 * va-core/core — this package only packages the editor side of that bridge.
 *
 * The `package-assets` tag hooks this into `deploy:sync` (which runs
 * `vendor:publish --tag=package-assets --force`), so a fresh checkout that does
 * not carry the host's public/vendor/ still regenerates the editor on deploy.
 */
class CKEditorServiceProvider extends ServiceProvider
{
    /**
     * Register the publishable CKEditor asset bundle.
     */
    public function boot(): void
    {
        $assetsPath = dirname(__DIR__, 2) . '/Resources/assets';

        if (is_dir($assetsPath)) {
            $this->publishes([
                $assetsPath => public_path('vendor/ckeditor'),
            ], ['ckeditor-assets', 'package-assets']);
        }
    }
}
