<?php

namespace Lc\SovBundle\Component;

use Lc\SovBundle\Resolver\UrlResolver;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;

class CookieComponent
{
    protected UrlResolver $urlResolver;
    protected ParameterBagInterface $parameterBag;

    public function __construct(UrlResolver $urlResolver, ParameterBagInterface $parameterBag)
    {
        $this->urlResolver = $urlResolver;
        $this->parameterBag = $parameterBag;
    }

    public function getCookieDomain()
    {
        return ($this->urlResolver->isServerLocalhost()) ? null : $this->parameterBag->get('app.cookie_domain_distant');
    }

    public function cryptCookie($data)
    {
        return base64_encode($data);
    }

    public function decryptCookie($data)
    {
        return base64_decode($data);
    }
}
