<?php

namespace Plugins\Disqus;

use Illuminate\Support\ServiceProvider;
use AleshaCMS\CMS\Hook\HookManager;

class DisqusServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        $hooks = $this->app->make(HookManager::class);

        $hooks->filter('post.render_data', function (array $data, array $context) {
            $shortname = \AleshaCMS\Models\CMS\Setting::get('disqus_shortname', '');

            if ($shortname && isset($context['post'])) {
                $data['disqusShortname'] = $shortname;
            }

            return $data;
        });
    }
}
