<?php

namespace Tests\Unit\Services\PromptLandingPageEditor;

use App\Services\PromptLandingPageEditor\SectionLibrary;
use Tests\TestCase;

class SectionLibraryTest extends TestCase
{
    public function test_sections_and_elements_use_theme_variables_and_named_form_fields(): void
    {
        $blocks = (new SectionLibrary)->blocks();

        $this->assertNotEmpty($blocks['sections']);
        $this->assertNotEmpty($blocks['elements']);

        $labels = array_column($blocks['sections'], 'label');
        $this->assertContains('Hero', $labels);
        $this->assertContains('Contact', $labels);
        $this->assertNotContains('Text + Image', $labels);

        $elementLabels = array_column($blocks['elements'], 'label');
        $this->assertNotContains('Video', $elementLabels);

        $contact = collect($blocks['sections'])->firstWhere('id', 'contact');
        $this->assertIsArray($contact);
        $this->assertStringContainsString('name="email"', $contact['html']);
        $this->assertStringContainsString('type="email"', $contact['html']);
        $this->assertStringContainsString('var(--theme', $contact['css']);

        $form = collect($blocks['elements'])->firstWhere('id', 'form');
        $this->assertIsArray($form);
        $this->assertStringContainsString('name="name"', $form['html']);
        $this->assertStringContainsString('name="email"', $form['html']);
    }
}
