<?php

use App\Livewire\Public\Fuel\Recommendation;
use Livewire\Livewire;

it('renders nothing before stations-found fires', function () {
    Livewire::test(Recommendation::class)
        ->assertStatus(200)
        ->assertSet('prediction', null)
        ->assertDontSee('Recommendation');
});

it('shows recommendation card when stations-found includes a prediction', function () {
    $prediction = [
        'action' => 'fill_now',
        'confidence_score' => 80.0,
        'confidence_label' => 'high',
        'reasoning' => 'Prices are rising sharply.',
        'predicted_direction' => 'up',
        'predicted_change_pence' => 3.5,
    ];

    Livewire::test(Recommendation::class)
        ->dispatch('stations-found', results: [], meta: [], prediction: $prediction, radius: 5)
        ->assertSet('prediction', $prediction)
        ->assertSee('Recommendation')
        ->assertSee('Fill up now');
});

it('shows nothing when stations-found has null prediction', function () {
    Livewire::test(Recommendation::class)
        ->dispatch('stations-found', results: [], meta: [], prediction: null, radius: 5)
        ->assertSet('prediction', null)
        ->assertDontSee('Recommendation');
});

it('clears previous prediction when new stations-found fires with null prediction', function () {
    $prediction = [
        'action' => 'fill_now',
        'confidence_score' => 80.0,
        'confidence_label' => 'high',
        'reasoning' => 'Prices rising.',
        'predicted_direction' => 'up',
        'predicted_change_pence' => 3.5,
    ];

    Livewire::test(Recommendation::class)
        ->dispatch('stations-found', results: [], meta: [], prediction: $prediction, radius: 5)
        ->assertSee('Recommendation')
        ->dispatch('stations-found', results: [], meta: [], prediction: null, radius: 5)
        ->assertDontSee('Recommendation');
});
