<?php

namespace App\Http\Controllers;

use App\Services\LiquidRenderer;
use Illuminate\Http\Request;
use App\Models\SitePage;
use App\Models\SitePageTag;

class CollectionController extends Controller
{

    protected $liquidRenderer;

    public function __construct(LiquidRenderer $liquidRenderer)
    {
        $this->liquidRenderer = $liquidRenderer;
    }

    public function index()
    {

        //模板支持多级目录，需要目录符号
        $output = LiquidRenderer::render('collection_list.liquid', [

        ]);

        return response($output);
    }

    public function detail($slug)
    {


        // 查找对应的 tag
        $tag = SitePageTag::where('slug', $slug)->first();

        if (!$tag) {
            return response()->json(['message' => '标签未找到'], 404);
        }


        // 获取关联的 pages
        $pages = $tag->pages()->get();

        //模板支持多级目录，需要目录符号
        $output = LiquidRenderer::render('collection_list.liquid', [
            'tag' => $tag,
            'pages' => $pages,
        ]);

        return response($output);
    }


}
