<?php
/**
 * SeekQuarry/Yioop --
 * Open Source Pure PHP Search Engine, Crawler, and Indexer
 *
 * Copyright (C) 2009 - 2026  Chris Pollett chris@pollett.org
 *
 * LICENSE:
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 * END LICENSE
 *
 * @author Chris Pollett chris@pollett.org
 * @license https://www.gnu.org/licenses/ GPL3
 * @link https://www.seekquarry.com/
 * @copyright 2009 - 2026
 * @filesource
 */
namespace seekquarry\yioop\views\elements;

use seekquarry\yioop as B;
use seekquarry\yioop\configs as C;
/**
 * Element used to draw the navigation bar on admin pages.
 *
 * @author Chris Pollett
 */
class AdminbarElement extends Element
{
    /**
     * Used to draw the navigation bar on the admin portion
     * of the yioop website
     *
     * @param array $data contains anti-CSRF token, as well as data on
     *     used to render what the current admin activity is
     */
    public function render($data)
    {
        $logged_in = isset($data["ADMIN"]) && $data["ADMIN"];
        $query_parts = [];
        $token_string = "";
        if ($logged_in) {
            $query_parts[C\p('CSRF_TOKEN')] = $data[C\p('CSRF_TOKEN')];
            $token_string = C\p('CSRF_TOKEN') . "=" . $data[C\p('CSRF_TOKEN')];
        }
        $current_activity = (empty($data['browse']) &&
            $data['CURRENT_ACTIVITY'] != 'manageGroups') ?
            $data['CURRENT_ACTIVITY'] : tl('adminbar_element_join_groups');
        $logo = $this->view->helper("logo")->renderResponsive($data,
            $this->view->logo_alt_text ?? "");
        ?><div class="none" >[<a href="#center-container"><?=
        tl('adminbar_element_skip_nav')
        ?>]</a></div><div id='nav-bar' class="nav-bar">
            <div class='inner-bar'>
            <?php $this->view->helper("hamburger")->render($logged_in); ?>
            <div class="title-block">
            <h1>
            <a href="<?= C\SHORT_BASE_URL . "?" .
                C\p('CSRF_TOKEN') . "=" . $data[C\p('CSRF_TOKEN')] ?>"><?php
            e($logo); ?></a></h1><div class='nav-span activity-nav'> - <?php
            $is_account = ($data['ACTIVITY_METHOD'] ?? "") == 'manageAccount';
            $css_classes = ($is_account) ? "disabled" : "";
            $this->view->helper("iconlink")->renderButton(
                B\controllerUrl("admin", true) . $token_string .
                "&amp;a=manageAccounts", "account_home", "", false, "",
                $css_classes);
            if(!$is_account) {
                e(" $current_activity");
            } else {
                e(" " . tl('adminbar_element_account'));
            }
            ?></div>
        </div>
        </div>
        </div>
        <?php
    }
}
