<?php

namespace App\View\Components\Home;

use App\Repositories\Catalog\BrandRepository;
use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;

class BrandHome extends Component
{
    public $brands;

    public $template = 'fashion-v1';

    /**
     * Create a new component instance.
     */
    public function __construct(BrandRepository $brandRepository)
    {
        $this->brands = $brandRepository->getList([]);

        if ($this->brands->count() < 9) {
            // Ensure we have at least 9 brands by duplicating if necessary
            while ($this->brands->count() < 9) {
                $this->brands = $this->brands->concat($this->brands);
            }
            $this->brands = $this->brands->take(9);
        }
    }

    /**
     * Get the view / contents that represent the component.
     */
    public function render(): View|Closure|string
    {
        $view = 'components.home.brand-home-fashion-v1';
        if ($this->template === 'fashion-v2') {
            $view = 'components.home.brand-home-fashion-v2';
        }
        return view($view);
    }
}
