<?php

namespace App\Http\Controllers\Shop;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

use App\Repositories\Shop\Articles;
use App\Repositories\Shop\Categories;
use App\Repositories\Shop\TagGroups;

use App\Datatables\Shop\CategoriesDataTable;

class CategoryController extends Controller
{
    public function index(CategoriesDataTable $dataTable)
    {
        return $dataTable->render('Shop.Categories.list');
    }

    public function show(Request $request, $category_id)
    {
        $data = [
            'category' => Categories::getFull($category_id),
            'breadcrumb' => Categories::getAncestorsByCategory($category_id),
            'display_by_rows' => $request->input('display_by_rows') ?? false,
            'product_type' => $request->input('product_type') ?? 'botanic',
            'tags_selected' => $request->input('tags') ?? [],
            'articles' => Articles::getArticlesToSell([
                'category_id' => $category_id,
                'tags' => $request->input('tags') ?? [],
                'product_type' => $request->input('product_type') ?? 'botanic',
            ]),
            'tags' => TagGroups::getWithTagsAndCountOffers($category_id),
        ];
        return view('Shop.Shelves.shelve', $data);
    }

    public function getTree()
    {
        return response()->json(Categories::getTree());
    }
}
