<?php

declare(strict_types=1);

namespace CpCreation\VitiCore\Tests\Marketing;

use CpCreation\VitiCore\Marketing\Model\AbandonedCartConfiguration;
use CpCreation\VitiCore\Marketing\Model\Translation\AbandonedCartConfigurationTranslation;
use PHPUnit\Framework\TestCase;

final class AbandonedCartConfigurationTest extends TestCase
{
    public function testLocalizedEmailContentPreservesEmojisAndSupportsRegionalLocales(): void
    {
        $configuration = new AbandonedCartConfiguration();
        $translation = $configuration->translate('fr');

        self::assertInstanceOf(AbandonedCartConfigurationTranslation::class, $translation);

        $translation->setEmailTitle('  Vos coups de cœur sont toujours là  ');
        $translation->setEmailSubject('  Votre panier vous attend 🛒  ');
        $translation->setEmailPreheader("Revenez vite\navant la fin de votre offre ✨");

        self::assertSame('Vos coups de cœur sont toujours là', $configuration->getEmailTitleForLocale('fr'));
        self::assertSame('Votre panier vous attend 🛒', $configuration->getEmailSubjectForLocale('fr'));
        self::assertSame(
            'Revenez vite avant la fin de votre offre ✨',
            $configuration->getEmailPreheaderForLocale('fr_FR'),
        );
        self::assertNull($configuration->getEmailSubjectForLocale('en'));
    }

    public function testEmptyOverridesRemainNullSoTranslationsCanBeUsed(): void
    {
        $configuration = new AbandonedCartConfiguration();
        $translation = $configuration->translate('fr');

        self::assertInstanceOf(AbandonedCartConfigurationTranslation::class, $translation);

        $translation->setEmailSubject('   ');
        $translation->setEmailPreheader(null);
        $translation->setEmailTitle("\n ");

        self::assertNull($configuration->getEmailTitleForLocale('fr'));
        self::assertNull($configuration->getEmailSubjectForLocale('fr'));
        self::assertNull($configuration->getEmailPreheaderForLocale('fr'));
    }
}
