<?php

namespace KupShop\ComponentsBundle\Twig\Components\Utils;

use KupShop\ComponentsBundle\Attributes\Component;
use KupShop\ComponentsBundle\Attributes\Version;
use KupShop\ComponentsBundle\Twig\BaseComponent;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;

#[AsTwigComponent(template: '@Components/components/Utils/Marketing/Marketing.1.html.twig')]
#[Component(1, [
    new Version(1, newJs: null, newCss: null),
])]
class Marketing extends BaseComponent
{
    private ?\Settings $settings = null;

    public function getSettings()
    {
        if ($this->settings == null) {
            $this->settings = \Settings::getDefault();
        }

        return $this->settings;
    }

    public function getLuigisId(): string|false
    {
        if (!($lb = ($this->getSettings()->analytics['luigis_box']['id'] ?? false)) || !findModule(\Modules::LUIGIS_BOX)) {
            return false;
        }

        if (!($expl = explode('-', $lb))) {
            return false;
        }

        return $expl[1];
    }

    public function getGrowthBookId(): string|false
    {
        if (!($gb = $this->getSettings()->analytics['growthbook']['key'] ?? false)) {
            return false;
        }

        return $gb;
    }
}
