<?php

declare(strict_types=1);

namespace KupShop\OrderingBundle\View;

use KupShop\KupShopBundle\Context\CountryContext;
use KupShop\KupShopBundle\Context\LanguageContext;
use KupShop\KupShopBundle\Views\View;
use Symfony\Component\HttpFoundation\RequestStack;

class PPLParcelShopView extends View
{
    /** @required */
    public RequestStack $requestStack;
    /** @required */
    public LanguageContext $languageContext;
    /** @required */
    public CountryContext $countryContext;

    protected $template = 'deliveries.PPLParcelShop.iframe.tpl';

    protected string $smartyFallback = 'blank';

    public function getBodyVariables()
    {
        $vars = parent::getBodyVariables();

        $vars['code'] = $this->requestStack->getMainRequest()->get('code');
        $vars['deliveryId'] = $this->requestStack->getMainRequest()->get('deliveryId');

        $delivery = \Delivery::getAll(false)[$vars['deliveryId']];

        $vars['widgetOptions'] = $delivery->getCustomData()['widget_options'] ?? [];

        if (in_array($this->languageContext->getActiveId(), ['cs', 'sk', 'de', 'pl'])) {
            $vars['language'] = $this->languageContext->getActiveId();
        } else {
            $vars['language'] = 'en';
        }

        $vars['country'] = mb_strtolower($this->countryContext->getActiveId());

        return $vars;
    }
}
