<?php

/*
 * This file is part of the VITICORE2 package.
 *
 * (c) CP Creation <web@cpcreation.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CpCreation\VitiCore\Tests\Controller;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Yaml\Yaml;

final class GuestCustomerAdminTest extends TestCase
{
    public function testGuestCustomerListIsLinkedFromTheClientMenu(): void
    {
        $menu = file_get_contents(
            __DIR__.'/../../src/Bridge/Symfony/Bundle/Resources/views/admin/base.html.twig',
        );
        $template = file_get_contents(
            __DIR__.'/../../src/Bridge/Symfony/Bundle/Resources/views/admin/client/guest.html.twig',
        );
        $detailTemplate = file_get_contents(
            __DIR__.'/../../src/Bridge/Symfony/Bundle/Resources/views/admin/client/guest_show.html.twig',
        );
        $insightsTemplate = file_get_contents(
            __DIR__.'/../../src/Bridge/Symfony/Bundle/Resources/views/admin/client/_order_insights.html.twig',
        );
        $registeredTemplate = file_get_contents(
            __DIR__.'/../../src/Bridge/Symfony/Bundle/Resources/views/admin/client/show.html.twig',
        );

        self::assertIsString($menu);
        self::assertStringContainsString("path('admin_guest_client')", $menu);
        self::assertStringContainsString("'admin.client.guests.menu'|trans", $menu);
        self::assertIsString($template);
        self::assertStringContainsString("trans({ '%count%': items|length })", $template);
        self::assertStringContainsString('item.order_count', $template);
        self::assertStringContainsString("path('admin_guest_client_show', { id: item.representative_cart_id })", $template);
        self::assertIsString($detailTemplate);
        self::assertStringContainsString("include '@CpCreationVitiCore/admin/client/_order_insights.html.twig'", $detailTemplate);
        self::assertStringContainsString('latest_order.invoiceAddress', $detailTemplate);
        self::assertIsString($registeredTemplate);
        self::assertStringContainsString("include '@CpCreationVitiCore/admin/client/_order_insights.html.twig'", $registeredTemplate);
        self::assertIsString($insightsTemplate);
        self::assertStringContainsString('order_insights.delivery_methods', $insightsTemplate);
        self::assertStringContainsString('order_insights.cuvees', $insightsTemplate);
        self::assertStringContainsString('order_insights.orders', $insightsTemplate);
    }

    #[DataProvider('localeProvider')]
    public function testGuestCustomerLabelsAreTranslated(string $locale): void
    {
        $translations = Yaml::parseFile(\sprintf(
            '%s/../../src/Bridge/Symfony/Bundle/Resources/translations/messages.%s.yaml',
            __DIR__,
            $locale,
        ));

        self::assertIsString($translations['admin']['client']['guests']['menu'] ?? null);
        self::assertIsString($translations['admin']['client']['guests']['order_count'] ?? null);
        self::assertIsString($translations['admin']['client']['guests']['empty'] ?? null);
        self::assertIsString($translations['admin']['client']['guests']['details'] ?? null);
        self::assertIsString($translations['admin']['client']['order_insights']['average_basket'] ?? null);
        self::assertIsString($translations['admin']['client']['order_insights']['delivery_methods_title'] ?? null);
        self::assertIsString($translations['admin']['client']['order_insights']['invoice_address'] ?? null);
    }

    /**
     * @return iterable<string, array{string}>
     */
    public static function localeProvider(): iterable
    {
        yield 'German' => ['de'];
        yield 'English' => ['en'];
        yield 'Spanish' => ['es'];
        yield 'French' => ['fr'];
        yield 'Italian' => ['it'];
        yield 'Dutch' => ['nl'];
    }
}
