<?php

namespace Tests\Feature;

use App\Livewire\Academic\AcademicCalendarIndex;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
use Tests\TestCase;

class AcademicCalendarTest extends TestCase
{
    use RefreshDatabase;

    protected function setUp(): void
    {
        parent::setUp();
        $this->seed();
    }

    public function test_authenticated_admin_can_access_academic_calendar_page(): void
    {
        $admin = User::where('email', 'admin@smkn1gunungagung.sch.id')->first();
        $admin->update(['force_password_change' => false]);
        $this->actingAs($admin);

        $response = $this->get('/academic-calendar');
        $response->assertStatus(200);
    }

    public function test_livewire_can_add_academic_year_and_holiday(): void
    {
        $admin = User::where('email', 'admin@smkn1gunungagung.sch.id')->first();
        $admin->update(['force_password_change' => false]);
        $this->actingAs($admin);

        Livewire::test(AcademicCalendarIndex::class)
            ->set('year_name', '2026/2027')
            ->set('year_start_date', '2026-07-01')
            ->set('year_end_date', '2027-06-30')
            ->call('saveYear')
            ->assertHasNoErrors();

        $this->assertDatabaseHas('academic_years', ['name' => '2026/2027']);
    }
}
