<?php

namespace App\Browser\Components\Hellcase;

use Laravel\Dusk\Browser;
use Laravel\Dusk\Component as BaseComponent;

class MainNav extends BaseComponent
{
    /**
     * Get the root selector for the component.
     */
    public function selector(): string
    {
        return 'header.header';
    }

    /**
     * Assert that the browser page contains the component.
     */
    public function assert(Browser $browser): void
    {
        $browser->assertVisible($this->selector());
    }

    /**
     * Get the element shortcuts for the component.
     *
     * @return array<string, string>
     */
    public function elements(): array
    {
        return [
            '@logo' => 'a.header-logo',
            '@daily-free-link' => 'a[href="/dailyfree"]',
        ];
    }

    public function goToHome(Browser $browser) {
        try {
            $browser->scrollIntoView('@logo');
            $browser->click('@logo');
        } catch (\Exception $e) {
            $browser->visit('https://hellcase.com/');
        }
    }
}
