<?php

declare(strict_types=1);

/*
 * This file is part of the Ferienpass package.
 *
 * (c) Richard Henkenjohann <richard@ferienpass.online>
 *
 * For more information visit the project website <https://ferienpass.online>
 * or the documentation under <https://docs.ferienpass.online>.
 */

namespace Ferienpass\CoreBundle\Tests\Ux;

use Ferienpass\CoreBundle\Ux\Flash;
use PHPUnit\Framework\TestCase;

final class FlashTest extends TestCase
{
    public function testConfirmationFactory(): void
    {
        [$type, $msg] = Flash::confirmation()->create();

        self::assertSame('confirmation', $type);
    }

    public function testErrorFactory(): void
    {
        [$type] = Flash::error()->create();

        self::assertSame('error', $type);
    }

    public function testInfoBannerFactory(): void
    {
        [$type] = Flash::infoBanner()->create();

        self::assertSame('banner-info', $type);
    }

    public function testConfirmationModalFactory(): void
    {
        [$type] = Flash::confirmationModal()->create();

        self::assertSame('modal-confirm', $type);
    }

    public function testWarningModalFactory(): void
    {
        [$type] = Flash::warningModal()->create();

        self::assertSame('modal-warning', $type);
    }

    public function testTextSetsMessage(): void
    {
        [, $msg] = Flash::confirmation()->text('Hello World')->create();

        self::assertSame('Hello World', $msg['text']);
    }

    public function testHeadlineSetsHeadline(): void
    {
        [, $msg] = Flash::confirmation()->headline('My Headline')->create();

        self::assertSame('My Headline', $msg['headline']);
    }

    public function testDismissableSetsDismissable(): void
    {
        [, $msg] = Flash::confirmation()->dismissable()->create();

        self::assertTrue($msg['dismissable']);
    }

    public function testLinkTextSetsLinkText(): void
    {
        [, $msg] = Flash::confirmation()->linkText('Click here')->create();

        self::assertSame('Click here', $msg['linkText']);
    }

    public function testHrefSetsHref(): void
    {
        [, $msg] = Flash::confirmation()->href('/some/path')->create();

        self::assertSame('/some/path', $msg['href']);
    }

    public function testDefaultsAreNullAndFalse(): void
    {
        [, $msg] = Flash::confirmation()->create();

        self::assertNull($msg['headline']);
        self::assertNull($msg['text']);
        self::assertFalse($msg['dismissable']);
        self::assertNull($msg['linkText']);
        self::assertNull($msg['href']);
    }

    public function testChaining(): void
    {
        [$type, $msg] = Flash::error()
            ->headline('Error!')
            ->text('Something went wrong.')
            ->dismissable()
            ->linkText('Try again')
            ->href('/retry')
            ->create();

        self::assertSame('error', $type);
        self::assertSame('Error!', $msg['headline']);
        self::assertSame('Something went wrong.', $msg['text']);
        self::assertTrue($msg['dismissable']);
        self::assertSame('Try again', $msg['linkText']);
        self::assertSame('/retry', $msg['href']);
    }
}
