<?php

declare(strict_types=1);

namespace App\Http\Controllers\Web;

use App\Http\Controllers\Controller;
use App\Services\HomepageService;
use App\Support\Seo\SeoFactory;
use Illuminate\Http\Request;

final class HomeController extends Controller
{
    public function __construct(private readonly HomepageService $homepage) {}

    public function index(Request $request): \Illuminate\View\View
    {
        $user     = $request->user();
        $sections = $user
            ? $this->homepage->allForUser($user)
            : array_merge($this->homepage->all(), ['is_logged_in' => false]);

        $hero = $sections['hero'];

        $meta = [
            'title'       => 'Skinbase – Digital Art & Wallpapers',
            'description' => 'Discover stunning digital art, wallpapers, and skins from a global community of creators. Browse trending works, fresh uploads, and beloved classics.',
            'keywords'    => 'wallpapers, digital art, skins, photography, community, wallpaper downloads',
            'og_image'    => $hero['thumb_lg'] ?? $hero['thumb'] ?? null,
            'canonical'   => url('/'),
        ];

        return view('web.home', [
            'seo' => app(SeoFactory::class)->homepage($meta)->toArray(),
            'useUnifiedSeo' => true,
            'meta'  => $meta,
            'props' => $sections,
        ]);
    }
}
