<?php

namespace Tests\Unit;

use App\Support\HomePageHtml;
use PHPUnit\Framework\TestCase;

class HomePageHtmlTest extends TestCase
{
    public function test_merge_defaults_adds_missing_sections(): void
    {
        $legacy = [
            'sections' => [
                ['title' => 'Hero'],
                ['title' => 'Features', 'features' => []],
                ['enable_ticket_section' => '1'],
                ['title' => 'Stats', 'stats' => []],
                ['title' => 'Testimonials', 'testimonials' => []],
            ],
        ];

        $merged = HomePageHtml::parse($legacy);

        $this->assertCount(7, $merged['sections']);
        $this->assertArrayHasKey('kb_button', $merged['sections'][0]);
        $this->assertArrayHasKey('hero_overlays', $merged['sections'][0]);
        $this->assertTrue($merged['sections'][2]['enable_ticket_section']);
        $this->assertNotEmpty($merged['sections'][5]['items']);
        $this->assertNotEmpty($merged['sections'][6]['channels']);
    }

    public function test_encode_produces_valid_json(): void
    {
        $json = HomePageHtml::encode(['sections' => []]);
        $decoded = json_decode($json, true);

        $this->assertIsArray($decoded);
        $this->assertCount(7, $decoded['sections']);
    }
}
