<?php

namespace Tests\Browser\WMSInventoryCore;

use App\Models\User;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;

class InventoryBrowserTest extends DuskTestCase
{
    protected ?User $adminUser = null;

    protected function setUp(): void
    {
        parent::setUp();
        $this->adminUser = User::where('email', 'admin@demo.com')->first();
    }

    public function test_inventory_dashboard_loads(): void
    {
        $this->browse(function (Browser $browser) {
            $browser->driver->manage()->deleteAllCookies();
            $browser->loginAs($this->adminUser)
                ->visit('/inventory/dashboard')
                ->assertPathIs('/inventory/dashboard')
                ->assertSee('WMS & Inventory');
        });
    }

    public function test_inventory_dashboard_shows_stats(): void
    {
        $this->browse(function (Browser $browser) {
            $browser->driver->manage()->deleteAllCookies();
            $browser->loginAs($this->adminUser)
                ->visit('/inventory/dashboard')
                ->assertSee('Total Products')
                ->assertSee('Total Warehouses');
        });
    }

    public function test_inventory_adjustments_page_loads(): void
    {
        $this->browse(function (Browser $browser) {
            $browser->driver->manage()->deleteAllCookies();
            $browser->loginAs($this->adminUser)
                ->visit('/inventory/adjustments')
                ->assertPathIs('/inventory/adjustments')
                ->assertSee('Adjustment');
        });
    }

    public function test_inventory_transfers_page_loads(): void
    {
        $this->browse(function (Browser $browser) {
            $browser->driver->manage()->deleteAllCookies();
            $browser->loginAs($this->adminUser)
                ->visit('/inventory/transfers')
                ->assertPathIs('/inventory/transfers');
        });
    }

    public function test_guest_cannot_access_inventory(): void
    {
        $this->browse(function (Browser $browser) {
            $browser->driver->manage()->deleteAllCookies();
            $browser->visit('/inventory/dashboard')
                ->assertPathIs('/auth/login');
        });
    }
}
