<?php

namespace App\Http\Controllers\Web\Posts;

use App\Http\Controllers\Controller;
use App\Support\Seo\SeoFactory;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;

class HashtagFeedController extends Controller
{
    public function __construct(private SeoFactory $seoFactory) {}

    /** GET /tags/{tag} */
    public function index(Request $request, string $tag): Response
    {
        $normalTag = strtolower($tag);

        $seo = $this->seoFactory->simplePage(
            title: '#' . $normalTag . ' — ' . config('seo.site_name', 'Skinbase'),
            description: 'Explore posts tagged with #' . $normalTag . ' on Skinbase.',
            canonical: url('/tags/' . rawurlencode($normalTag)),
        );

        return Inertia::render('Feed/HashtagFeed', [
            'auth' => $request->user() ? [
                'user' => [
                    'id'       => $request->user()->id,
                    'username' => $request->user()->username,
                    'name'     => $request->user()->name,
                    'avatar'   => $request->user()->profile?->avatar_url ?? null,
                ],
            ] : null,
            'tag' => $normalTag,
            'seo' => $seo,
        ]);
    }
}
