<?php

namespace Tests\Unit\Support;

use App\Support\CssFontFamily;
use Tests\TestCase;

class CssFontFamilyTest extends TestCase
{
    public function test_primary_skips_generic_and_icon_fallbacks(): void
    {
        $this->assertSame('Inter', CssFontFamily::primary('Inter, system-ui, sans-serif'));
        $this->assertSame('Open Sans', CssFontFamily::primary('"Open Sans", "Helvetica Neue", sans-serif'));
        $this->assertNull(CssFontFamily::primary('system-ui, -apple-system, sans-serif'));
        $this->assertNull(CssFontFamily::primary('"Font Awesome 5 Free", sans-serif'));
    }

    public function test_reads_the_first_family_from_a_google_fonts_url(): void
    {
        $this->assertSame(
            'Playfair Display',
            CssFontFamily::fromGoogleFontsUrl('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;700&display=swap'),
        );
    }

    public function test_builds_a_google_fonts_url_for_named_typefaces_but_not_web_safe_fonts(): void
    {
        $this->assertSame(
            'https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700&display=swap',
            CssFontFamily::stylesheetUrl('Montserrat'),
        );
        $this->assertNull(CssFontFamily::stylesheetUrl('Arial'));
    }

    public function test_reads_a_named_font_from_the_user_prompt_and_ignores_generic_wording(): void
    {
        $this->assertSame('Playfair Display', CssFontFamily::fromUserPrompt('Use the Playfair Display font for headlines.'));
        $this->assertSame('Roboto', CssFontFamily::fromUserPrompt('Please set font-family: Roboto.'));
        $this->assertNull(CssFontFamily::fromUserPrompt('Use the website font and keep the same look.'));
        $this->assertNull(CssFontFamily::fromUserPrompt('Make a modern landing page.'));
    }

    public function test_css_value_quotes_multi_word_families(): void
    {
        $this->assertSame('Inter, sans-serif', CssFontFamily::cssValue('Inter'));
        $this->assertSame('"Open Sans", sans-serif', CssFontFamily::cssValue('Open Sans'));
    }
}
