<?php

namespace App\Http\Controllers;

class ProductsHubController extends Controller
{
    public function __construct()
    {
        $this->middleware('permission:products.hub.view')->only(['index', 'page']);
    }

    /**
     * Display the products hub page.
     *
     * @return \Illuminate\View\View
     */
    public function index()
    {
        return view('products.hub');
    }

    /**
     * Display a placeholder page for specific product sections.
     *
     * @param  string  $page
     * @return \Illuminate\View\View
     */
    public function page($page)
    {
        // Map slugs to translation keys for titles
        $titles = [
            'main-categories' => 'products.cards.main_categories',
            'sub-categories' => 'products.cards.sub_categories',
            'product-details' => 'products.cards.product_details',
            'items' => 'products.cards.products',
            'inventory' => 'products.cards.inventory',
            'delivery' => 'products.cards.delivery',
        ];

        // Validate page exists
        if (! array_key_exists($page, $titles)) {
            abort(404);
        }

        return view('products.placeholder', [
            'title' => __($titles[$page]),
            'slug' => $page,
        ]);
    }
}
