<?php

namespace KupShop\GTMBundle\PageType;

use KupShop\CatalogBundle\View\CategoryView;
use KupShop\CatalogElasticBundle\View\SectionView;

class CategoryPageType extends AbstractPageType
{
    public function getPageData(&$dataContainer)
    {
        $c = new \stdClass();
        if ($this->view->categoryId) {
            $c->catId = $this->view->categoryId ?? 0;
            $c->catName = $this->view->getTitle();
        }

        if ($this->view->producerId) {
            $c->producerName = $this->view->producer['name'] ?? '';
            $c->producerId = $this->view->producerId;
        }

        $c->catPath = $this->getBreadcrumbsWithoutCurrent();
        $c->catZbozi = [
            'id' => $this->view->category['feed_seznam'] ?? '',
            'name' => $this->view->category['feed_seznam_category'] ?? '',
        ];
        $dataContainer->category = $c;
    }

    public function getPageType(&$dataContainer)
    {
        /** @var SectionView|CategoryView $view */
        $view = $this->fetchView();

        if ($view->getCategoryId()) {
            $dataContainer->page->type = 'category';
        } elseif ($view->getProducerId()) {
            $dataContainer->page->type = 'producer';
        } else {
            $dataContainer->page->type = 'catalog';
        }
    }

    public static function getSupportedViews()
    {
        return [CategoryView::class];
    }
}
