<?php

namespace Kylin\Adminlte;

use Illuminate\Support\ServiceProvider;
use Kylin\Adminlte\Middleware\SecurityHeadersMiddleware;

/**
 * AdminLTE 服务提供者
 *
 * 提供基于 AdminLTE 模板的后台管理面板基础设施。
 * 注册配置、视图、静态资源发布。
 */
class AdminlteServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        $this->mergeConfigFrom(__DIR__ . '/../config/kylin-adminlte.php', 'kylin-adminlte');
    }

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

        $this->publishes([
            __DIR__ . '/../config/kylin-adminlte.php' => config_path('kylin-adminlte.php'),
        ], 'kylin-adminlte-config');

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

        $this->publishes([
            __DIR__ . '/../resources/assets' => public_path('vendor/kylin-adminlte'),
        ], 'kylin-adminlte-assets');

        if ($this->app->runningInConsole()) {
            $this->commands([
                Commands\InstallCommand::class,
            ]);
        }

        // 注册安全头中间件
        $this->app['router']->aliasMiddleware('admin-security', SecurityHeadersMiddleware::class);
    }
}
