<?php

namespace App\View\Components\Grocery;

use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
use App\Repositories\Catalog\CategoryRepository;
use App\Repositories\Catalog\ProductRepository;

class PopularProducts extends Component
{

    protected $categories = [];
    protected $products = [];

    /**
     * Create a new component instance.
     */
    public function __construct(CategoryRepository $categoryRepository, ProductRepository $productRepository)
    {
        //

        $this->categories = $categoryRepository->getList([]);
        $this->products = $productRepository->getList([
            'limit' => 12,
        ]);
        }

    /**
     * Get the view / contents that represent the component.
     */
    public function render(): View|Closure|string
    {
        return view('components.grocery.popular-products', [
            'categories' => $this->categories,
            'products' => $this->products,
        ]);
    }
}
