<?php

declare(strict_types=1);

namespace App\Http\Controllers\Api\V1;

use App\Http\Controllers\Controller;
use App\Services\Theme\ThemeManager;
use Illuminate\Http\JsonResponse;

class SiteThemeController extends Controller
{
    public function __construct(protected ThemeManager $themes) {}

    public function active(): JsonResponse
    {
        $theme = $this->themes->getActive();
        if (! $theme) {
            return response()->json([
                'slug' => 'aqua',
                'name' => 'Aqua',
                'css_url' => config('theme.themes_url', '/themes') . '/aqua/assets/theme.css',
                'screenshot_url' => null,
                'settings' => null,
            ]);
        }
        $base = config('theme.themes_url', '/themes');
        return response()->json([
            'slug' => $theme->slug,
            'name' => $theme->name,
            'css_url' => "$base/{$theme->slug}/assets/theme.css",
            'screenshot_url' => $theme->screenshot_url,
            'settings' => $theme->settings,
        ]);
    }
}
