<?php

namespace Tests\Feature;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class HomeNavTest extends TestCase
{
    use RefreshDatabase;

    public function test_home_renders_with_separated_nav_and_tool_linked_cards(): void
    {
        $this->seed();

        $res = $this->get('/')->assertOk();

        // Learn and Resources are now distinct nav sections.
        $res->assertSee('Resources');
        $res->assertSee("dropdown === 'resources'", false);
        $res->assertSee("dropdown === 'learn'", false);

        // "What do you need today?" cards point at the matching tools.
        $res->assertSee('/tools/debt-payoff', false);
        $res->assertSee('/tools/wealth-goals', false);
        $res->assertSee('/tools/compound-growth', false);
        $res->assertSee('/tools/emergency-fund', false);
        $res->assertSee('/tools/retirement', false);

        // The watch section features a real channel video + the correct handle.
        $res->assertSee('MoneyWiseWithRinaHicks');
        $res->assertDontSee('@MoneyWiseKE');
    }

    public function test_method_section_moved_to_about_and_tools_dock_present(): void
    {
        $this->seed();

        // The method section now lives on About...
        $this->get('/about')
            ->assertOk()
            ->assertSee('The Money-Wise method')
            ->assertSee('Know yourself')
            ->assertSee('Quick tools'); // the left-side tools dock (in the layout)

        // ...and is gone from the home page.
        $this->get('/')
            ->assertOk()
            ->assertDontSee('Who you are, before what you earn');
    }

    public function test_money_foundations_free_video_course_seeded_and_renders(): void
    {
        $this->seed(\Database\Seeders\MoneyFoundationsSeeder::class);

        $course = \App\Models\Course::where('slug', 'money-foundations')->first();
        $this->assertNotNull($course, 'Free video course should be seeded');
        $this->assertSame(0, (int) $course->price_kes, 'Course should be free');
        $this->assertTrue((bool) $course->is_published);
        $this->assertGreaterThanOrEqual(5, $course->modules()->count());

        $lesson = \App\Models\Lesson::whereNotNull('video_url')->first();
        $this->assertNotNull($lesson, 'Lessons should carry real video URLs');
        $this->assertStringContainsString('youtube.com/watch', $lesson->video_url);
        $this->assertStringContainsString('youtube-nocookie.com/embed', $lesson->youtubeEmbedUrl());

        // The public curriculum page lists the real lessons.
        $this->get('/learn/money-foundations')
            ->assertOk()
            ->assertSee('Managing Your Salary');
    }
}
