<?php

namespace KupShop\ComponentsBundle\Twig\Components\Product;

use KupShop\ComponentsBundle\Attributes\Component;
use KupShop\ComponentsBundle\Attributes\Version;
use KupShop\ComponentsBundle\Twig\BaseComponent;
use KupShop\ComponentsBundle\Twig\DataProvider\ProductDataTrait;
use KupShop\KupShopBundle\Context\CurrencyContext;
use KupShop\KupShopBundle\Util\Contexts;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;

#[AsTwigComponent(template: '@Components/components/Product/Essox/Essox.1.html.twig')]
#[Component(1, [
    new Version(1, newJs: null),
])]
class Essox extends BaseComponent
{
    use ProductDataTrait;

    /**
     * @return ?array{parts: int, price: int}
     */
    public function getSplitPrice(): ?array
    {
        $essox = new \Essox2Rozdeleni();
        $price = $this->getProductUnified()->getProductPrice()->getPriceWithVat();

        return $essox->getEssoxCalcDetail($price);
    }

    public function getOfferUrl(): ?string
    {
        $essox = new \Essox2Splatky();
        $price = $this->getProductUnified()->getProductPrice()->getPriceWithVat();

        return $essox->getEssoxCalcDetail($price);
    }

    public function getCurrencySymbol(): string
    {
        return Contexts::get(CurrencyContext::class)->getActive()->getSymbol();
    }

    public function getMoreInfoUrl(): ?string
    {
        try {
            $url = createScriptURL(['s' => 'page', 'label' => 'credit-purchase']);
        } catch (\Exception $e) {
            $url = null;
        }

        return $url;
    }
}
