<?php
    $contaAngraUser = auth()->user();
    $contaAngraAvatar = $contaAngraUser?->photo ? asset($contaAngraUser->photo) : null;
    $contaAngraInitials = $contaAngraUser
        ? mb_strtoupper(
            mb_substr($contaAngraUser->firstName ?? '', 0, 1) .
            mb_substr($contaAngraUser->lastName ?? '', 0, 1)
        )
        : '';
?>

<section class="defaultBar" role="navigation" aria-label="<?php echo e(__('Barra de acessibilidade e atalhos')); ?>">
    <div class="container">
        <div class="defaultBar-row" role="toolbar" aria-label="<?php echo e(__('Atalhos de acessibilidade')); ?>">

            <div class="defaultBar-left">
                <?php if(auth()->guard()->check()): ?>
                    <div class="defaultBar-user">
                        <button
                            type="button"
                            class="defaultBar-user-btn"
                            data-bs-toggle="modal"
                            data-bs-target="#contaAngraUserModal"
                            aria-label="<?php echo e(__('Abrir menu da Conta Angra do usuário autenticado')); ?>"
                        >
                            <span class="defaultBar-avatar" aria-hidden="true">
                                <?php if($contaAngraAvatar): ?>
                                    <img src="<?php echo e($contaAngraAvatar); ?>" alt="<?php echo e($contaAngraUser->name); ?>" loading="lazy">
                                <?php else: ?>
                                    <span class="defaultBar-avatar-initials"><?php echo e($contaAngraInitials ?: __('?')); ?></span>
                                <?php endif; ?>
                            </span>
                            <span class="defaultBar-user-inline d-none d-md-inline">
                                <?php echo e(__('Olá,')); ?> <?php echo e($contaAngraUser->firstName ?? $contaAngraUser->name); ?>

                            </span>
                            <i class="fa-solid fa-chevron-down defaultBar-user-caret" aria-hidden="true"></i>
                        </button>
                    </div>
                <?php endif; ?>
                <?php if(auth()->guard()->guest()): ?>
                    <a
                        class="px-2 defaultBar-link"
                        href="<?php echo e(route('admin.contaAngra.index')); ?>"
                        target="_blank"
                        rel="noopener"
                        aria-label="<?php echo e(__('Acessar Conta Angra (abre em nova aba)')); ?>"
                    >
                        <i class="fa-regular fa-user" aria-hidden="true"></i>
                        <span class="defaultBar-label-full"><?php echo e(__('Entrar na Conta Angra')); ?></span>
                        <span class="defaultBar-label-short"></span>
                    </a>
                <?php endif; ?>
            </div> 

            <div class="defaultBar-icons">
                <?php
                    $horaAtualBoletim = \Carbon\Carbon::now()->subHours(3);
                    $horaBoletim = $horaAtualBoletim->format('H');

                    $meteoconsWidget = [
                        'Ensolarado' => 'pmar/assets/img/icons/weather/ensolarado.svg',
                        'Sol com poucas nuvens' => 'pmar/assets/img/icons/weather/sol-com-poucas-nuvens.svg',
                        'Sol com muitas nuvens' => 'pmar/assets/img/icons/weather/sol-com-muitas-nuvens.svg',
                        'Nublado' => 'pmar/assets/img/icons/weather/nublado.svg',
                        'Sol com possibilidade de chuva' => 'pmar/assets/img/icons/weather/sol-com-possibilidade-de-chuva.svg',
                        'Nublado com possibilidade de chuva' => 'pmar/assets/img/icons/weather/nublado-com-possibilidade-de-chuva.svg',
                        'Chuvoso' => 'pmar/assets/img/icons/weather/chuvoso.svg',
                        'Pancadas de chuva e trovoada' => 'pmar/assets/img/icons/weather/pancadas-de-chuva-e-trovoada.svg',
                        'Pancadas de chuva' => 'pmar/assets/img/icons/weather/pancadas-de-chuva.svg',
                        'Sem nuvens' => 'pmar/assets/img/icons/weather/sem-nuvens.svg',
                        'Poucas nuvens' => 'pmar/assets/img/icons/weather/poucas-nuvens.svg',
                        'Muitas nuvens' => 'pmar/assets/img/icons/weather/muitas-nuvens.svg',
                        'Muitas nuvens com possibilidade de chuva' => 'pmar/assets/img/icons/weather/muitas-nuvens-com-possibilidade-de-chuva.svg',
                    ];

                    $coresWidget = [
                        'VIGILÂNCIA' => 'green',
                        'OBSERVAÇÃO' => 'warning',
                        'ATENÇÃO' => 'danger',
                        'ALERTA' => 'red',
                        'ALERTA MÁXIMO' => 'indigo',
                    ];
                    $widgetBorderClass = '';
                    if (!empty($boletimHoje)) {
                        $corWidget = $coresWidget[$boletimHoje->nivel_de_acao] ?? 'secondary';
                        $widgetBorderClass = "border-start border-{$corWidget} border-1";
                    } else {
                        $widgetBorderClass = 'border-start border-secondary border-1';
                    }

                    $weatherAriaLabel = !empty($boletimHoje)
                        ? __('Ver boletim meteorológico') . ' — ' . $boletimHoje->temperatura_minima . '° / ' . $boletimHoje->temperatura_maxima . '°'
                        : __('Boletim meteorológico — sem boletim de hoje');
                ?>

                <a
                    class="px-2 defaultBar-link defaultBar-weather <?php echo e($widgetBorderClass); ?>"
                    href="<?php echo e(route('paginas.boletim-meteorologico.index')); ?>"
                    aria-label="<?php echo e($weatherAriaLabel); ?>"
                    <?php if(empty($boletimHoje)): ?> title="<?php echo e(__('Sem boletim de hoje')); ?>" <?php endif; ?>
                >
                    <?php if(!empty($boletimHoje)): ?>
                        <?php
                            if ($horaBoletim >= 5 && $horaBoletim < 12) {
                                $condicaoWidget = $boletimHoje->estado_manha;
                            } elseif ($horaBoletim >= 12 && $horaBoletim < 18) {
                                $condicaoWidget = $boletimHoje->estado_tarde;
                            } else {
                                $condicaoWidget = $boletimHoje->estado_noite;
                            }

                            $iconeWidget = $meteoconsWidget[$condicaoWidget] ?? null;
                        ?>

                        <span class="defaultBar-weather-icon" aria-hidden="true">
                            <?php if($iconeWidget): ?>
                                <img src="<?php echo e(asset($iconeWidget)); ?>" alt="<?php echo e($condicaoWidget); ?>" loading="lazy">
                            <?php else: ?>
                                <i class="fa-solid fa-cloud-sun"></i>
                            <?php endif; ?>
                        </span>

                        <span class="defaultBar-weather-text d-none d-md-flex">
                            <span class="defaultBar-weather-meta">
                                <span class="defaultBar-weather-temp">
                                    <i class="fa-solid fa-arrow-down fa-xs me-1"></i>
                                    <?php echo e($boletimHoje->temperatura_minima); ?>°
                                    /
                                    <?php echo e($boletimHoje->temperatura_maxima); ?>°
                                    <i class="fa-solid fa-arrow-up fa-xs ms-1"></i>
                                </span>
                            </span>
                        </span>
                    <?php else: ?>
                        <span class="defaultBar-weather-icon" aria-hidden="true">
                            <i class="fa-solid fa-cloud"></i>
                        </span>
                        <span class="defaultBar-weather-text d-none d-md-flex">
                            <span class="defaultBar-weather-title">
                                <?php echo e(__('Boletim Meteorológico')); ?>

                            </span>
                            <span class="defaultBar-weather-meta">
                                <?php echo e(__('Sem boletim de hoje')); ?>

                            </span>
                        </span>
                    <?php endif; ?>
                </a>

                <a
                    class="px-2 defaultBar-link"
                    href="<?php echo e(route('transparencia.index')); ?>"
                    aria-label="<?php echo e(__('Ir para o Portal da Transparência')); ?>"
                    title="<?php echo e(__('Portal da Transparência')); ?>"
                >
                    <span class="d-md-none"><?php echo e(__('Transparência')); ?></span>
                    <span class="d-none d-md-inline"><?php echo e(__('Portal da Transparência')); ?></span>
                </a>

                <button
                    class="defaultBar-icon defaultBar-zoom-toggle"
                    data-bs-toggle="modal"
                    data-bs-target="#defaultBarZoomModal"
                    aria-label="<?php echo e(__('Abrir opções de acessibilidade de texto')); ?>"
                    title="<?php echo e(__('Acessibilidade de texto')); ?>"
                    type="button"
                >
                    <i class="fa-solid fa-magnifying-glass-plus" aria-hidden="true"></i>
                    <span class="visually-hidden"><?php echo e(__('Acessibilidade de texto')); ?></span>
                </button>

                
                <a
                    href="#"
                    id="darkModeToggle"
                    class="dark-mode-toggle defaultBar-icon"
                    title="<?php echo e(__('Alternar modo noturno')); ?>"
                    aria-label="<?php echo e(__('Alternar entre modo claro e escuro')); ?>"
                    aria-pressed="false"
                >
                    <i class="fa-solid fa-sun dark-mode-icon-sun" aria-hidden="true"></i>
                    <i class="fa-solid fa-moon dark-mode-icon-moon" aria-hidden="true"></i>
                    <span class="visually-hidden"><?php echo e(__('Alternar modo noturno')); ?></span>
                </a>
            </div>
        </div>
    </div>
</section>

<?php if(auth()->guard()->check()): ?>
    <div
        class="modal fade defaultBar-user-modal"
        id="contaAngraUserModal"
        tabindex="-1"
        aria-labelledby="contaAngraUserModalLabel"
        aria-hidden="true"
        data-bs-backdrop="false"
        data-bs-keyboard="true"
    >
        <div class="modal-dialog modal-sm defaultBar-user-popup">
            <div class="modal-content">
                <div class="modal-body">
                    <div class="d-flex justify-content-between align-items-start mb-3">
                        <div class="defaultBar-modal-header defaultBar-modal-header-user flex-grow-1">
                        <div class="defaultBar-avatar defaultBar-avatar-xl" aria-hidden="true">
                            <?php if($contaAngraAvatar): ?>
                                <img src="<?php echo e($contaAngraAvatar); ?>" alt="<?php echo e($contaAngraUser->name); ?>" loading="lazy">
                            <?php else: ?>
                                <span class="defaultBar-avatar-initials"><?php echo e($contaAngraInitials ?: __('?')); ?></span>
                            <?php endif; ?>
                        </div>
                        <div class="defaultBar-modal-user text-center">
                            <p id="contaAngraUserModalLabel" class="defaultBar-modal-greeting"><?php echo e(__('Olá,')); ?></p>
                            <h2 class="defaultBar-modal-name"><?php echo e($contaAngraUser->name); ?></h2>
                        </div>
                        </div>
                        <button type="button" class="btn-close ms-2" data-bs-dismiss="modal" aria-label="<?php echo e(__('Fechar')); ?>"></button>
                    </div>

                    <div class="defaultBar-modal-actions" role="list">
                        <a href="<?php echo e(route('admin.contaAngra.index')); ?>" class="defaultBar-modal-link" role="listitem">
                            <i class="fa-solid fa-house" aria-hidden="true"></i>
                            <span><?php echo e(__('Minha Conta Angra')); ?></span>
                            <i class="fa-solid fa-arrow-up-right-from-square defaultBar-modal-link-icon" aria-hidden="true"></i>
                        </a>

                        <div class="defaultBar-modal-divider" role="separator" aria-hidden="true"></div>

                        <a href="<?php echo e(route('admin.profile')); ?>" class="defaultBar-modal-link" role="listitem">
                            <i class="fa-solid fa-id-card" aria-hidden="true"></i>
                            <span><?php echo e(__('Dados Pessoais')); ?></span>
                            <i class="fa-solid fa-chevron-right defaultBar-modal-link-icon" aria-hidden="true"></i>
                        </a>

                        <a href="<?php echo e(route('admin.password')); ?>" class="defaultBar-modal-link" role="listitem">
                            <i class="fa-solid fa-shield-halved" aria-hidden="true"></i>
                            <span><?php echo e(__('Segurança da Conta')); ?></span>
                            <i class="fa-solid fa-chevron-right defaultBar-modal-link-icon" aria-hidden="true"></i>
                        </a>

                        <a href="<?php echo e(route('admin.logout')); ?>" class="defaultBar-modal-link defaultBar-modal-link-danger" role="listitem">
                            <i class="fa-solid fa-arrow-right-from-bracket" aria-hidden="true"></i>
                            <span><?php echo e(__('Sair')); ?></span>
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>
<?php endif; ?>

<div
    class="modal fade defaultBar-zoom-modal"
    id="defaultBarZoomModal"
    tabindex="-1"
    aria-labelledby="defaultBarZoomModalLabel"
    aria-hidden="true"
    data-bs-backdrop="false"
    data-bs-keyboard="true"
>
    <div class="modal-dialog modal-sm defaultBar-zoom-popup">
        <div class="modal-content">
            <div class="modal-body">
                <div class="d-flex justify-content-between align-items-start mb-3">
                    <div class="defaultBar-modal-header defaultBar-modal-header-user flex-grow-1">
                        <div class="defaultBar-avatar defaultBar-avatar-xl" aria-hidden="true">
                            <i class="fa-solid fa-magnifying-glass-plus"></i>
                        </div>
                        <div class="defaultBar-modal-user text-center">
                            <p id="defaultBarZoomModalLabel" class="defaultBar-modal-greeting"><?php echo e(__('Acessibilidade de texto')); ?></p>
                            <h2 class="defaultBar-modal-name"><?php echo e(__('Tamanho da fonte')); ?></h2>
                        </div>
                    </div>
                    <button type="button" class="btn-close ms-2" data-bs-dismiss="modal" aria-label="<?php echo e(__('Fechar')); ?>"></button>
                </div>
                <div class="defaultBar-modal-actions" role="list">
                    <a class="defaultBar-modal-link zoom" href="#" data-value="0.25" role="listitem">
                        <i class="fa-solid fa-magnifying-glass-plus" aria-hidden="true"></i>
                        <span><?php echo e(__('Aumentar fonte')); ?></span>
                    </a>
                    <a class="defaultBar-modal-link zoom" href="#" data-value="-0.25" role="listitem">
                        <i class="fa-solid fa-magnifying-glass-minus" aria-hidden="true"></i>
                        <span><?php echo e(__('Reduzir fonte')); ?></span>
                    </a>
                    <a class="defaultBar-modal-link zoom" href="#" data-value="1" role="listitem">
                        <i class="fa-solid fa-font" aria-hidden="true"></i>
                        <span><?php echo e(__('Fonte padrão')); ?></span>
                    </a>
                </div>
            </div>
        </div>
    </div>
</div>
<?php /**PATH /var/www/html/portal/resources/views/layouts/pmar/elements/defaultBar.blade.php ENDPATH**/ ?>