<?php

namespace App\View\Components;

use Illuminate\View\Component;
use Illuminate\Support\Facades\Auth;
use App\Models\Settings;

class Nav extends Component
{
    /**
     * Create a new component instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Get the view / contents that represent the component.
     *
     * @return \Illuminate\Contracts\View\View|\Closure|string
     */
    public function render()
    {
        $user = Auth::user();
        if(isset($user)){
            return view('components.nav', [
                "getPrimaryOptions" => $this->getPrimaryOptions(),
                "getSecondaryOptions" => $this->getSecondaryOptions(),
                "user" => Auth::user()
            ]);
        }else{
            return view('components.nav', [
                "getPrimaryOptions" => $this->getPrimaryOptions(),
                "getSecondaryOptions" => $this->getSecondaryOptions(),
                "user" => Auth::user()
            ]);
        }
    }

    /**
     * 
     */
    public function getPrimaryOptions(): array
    {
        $user = Auth::user();
        $options = [];

        if(isset($user)){
            $accessMode = Settings::getAccessMode();
            array_push($options, "<li><a class='dropdown-item' href='/admin/dashboard'>" . __('options.nav.home') . "</a></li>");
            array_push($options, "<li><a class='dropdown-item' href='/admin/view-email'>" . __('options.nav.email.title') . "</a></li>");
            if (Auth::user()->isAbleTo('create-patient')) {
                array_push($options, "<li><a class='dropdown-item' href='/admin/create-patient'>" . __('options.nav.patients.create') . "</a></li>");
            }
            if (Auth::user()->isAbleTo('create-area')) {
                array_push($options, "<li><a class='dropdown-item' href='/admin/create-areas'>" . __('options.nav.areas.create') . "</a></li>");
            }
            if (Auth::user()->isAbleTo('create-user')) {
                array_push($options, "<li><a class='dropdown-item' href='/admin/create-users'>" . __('options.nav.users.create') . "</a></li>");
            }
            if (Auth::user()->isAbleTo('create-appointment') && (in_array(Settings::APPOINTMENT_ONLY_MODE, $accessMode) || in_array(Settings::FULL_ACCESS_MODE, $accessMode))) {
                array_push($options, "<li><a class='dropdown-item' href='/admin/create-appointment'>" . __('options.nav.appointments.create') . "</a></li>");
            }
        }
        return $options;
    }

    /**
     * 
     */
    public function getSecondaryOptions(): array
    {
        $user = Auth::user();
        $options = [];

        if(isset($user))
            array_push($options, "<li class='text-center' style='color:#ebb103'><hr class='dropdown-divider'><a href='#' class='link-logout' data-bs-toggle='modal' data-bs-target='#modalLogout'>" . __('options.nav.logout') . "</a></li>");
        else
            array_push($options, "<li class='text-center' style='color:#ebb103'><hr class='dropdown-divider'><a href='/admin/login' class='link-logout'>" . __('options.nav.login') . "</a></li>");
        return $options;
    }
}