<?php

declare(strict_types=1);

// Инициализация
$panel ?? $panel = 'profile_panel_monitoring_input_search_history';

?>
<link href="/css/pages/profile.css" rel="stylesheet">

<div id="page_profile" class="container mb-auto">
    <div class="row h-100 py-3">
        <nav class="col-3">
            <?= $sidebar ?? Yii::$app->controller->renderPartial('/profile/sidebar') ?>
        </nav>
        <article class="col-9">
            <div class="p-4 rounded">
                <div id="profile_panel_monitoring" class="profile_panel">
                    <div class="profile_panel_menu mb-3">
                        <label class="btn button_white mb-0 mr-2" for="profile_panel_monitoring_input_orders_history">Заказы</label>
                        <label class="btn button_white mb-0 mr-2" for="profile_panel_monitoring_input_search_history">Поисковые запросы</label>
                        <label class="btn button_white mb-0" for="profile_panel_monitoring_input_log">Журнал действий</label>
                    </div>
                    <div class="profile_panel_content">
                        <input type="radio" id="profile_panel_monitoring_input_orders_history" name="main_panel" <?= $panel === 'profile_panel_monitoring_input_orders_history' ? 'checked' : null ?> />
                        <div class="col p-3">
                            История заказов в разработке
                        </div>

                        <input type="radio" id="profile_panel_monitoring_input_search_history" name="main_panel" <?= $panel === 'profile_panel_monitoring_input_search_history' ? 'checked' : null ?> />
                        <div class="col rounded overflow-hidden">
                            <div class="row header_blue py-2">
                                <div class="col-sm-4 col-md-3">IPv4</div>
                                <div class="col-7 col-sm-3 col-md-4 col-lg-6 pr-0 px-sm-0 px-lg-3">Поисковый запрос</div>
                                <div class="col">Время</div>
                            </div>
                            <?php
                            foreach ($search_history ?? [] as $row) {
                                // Инициализация
                                $time = $row->jrnl;

                                // Инициализация часового пояса
                                preg_match_all('/UTC([\+\-0-9:]*)/', $account->zone ?? Settings::searchActive()['timezone_default'] ?? 'UTC+3', $timezone);
                                $timezone = $timezone[1][0];

                                $date = empty($row->jrnl) ? '' : (new DateTime())->setTimestamp(end($time)['date'])->setTimezone(new DateTimeZone($timezone))->format('H:i d.m.Y');

                                echo <<<HTML
                                        <div class="row py-1">
                                            <div class="col-sm-4 col-md-3">$row->ipv4</div>
                                            <div class="col-7 col-sm-3 col-md-4 col-lg-6 pr-0 px-sm-0 px-lg-3">$row->text</div>
                                            <div class="col">$date</div>
                                        </div>
                                    HTML;
                            }
                            ?>
                            <div class="mt-3">
                                <?php
                                $page = ($page_search_history ?? 0) + 1;

                                echo <<<HTML
                                    <div class="row">
                                            <button class="btn button_clean button_blue" onclick="return page_profile_monitoring(-1, 'profile_panel_monitoring_input_search_history');">Назад</button>
                                            <p>$page</p>
                                            <button class="btn button_clean button_blue" onclick="return page_profile_monitoring(1, 'profile_panel_monitoring_input_search_history');">Вперёд</button>
                                            <div class="col-8"></div>
                                    </div>
                                    HTML;
                                ?>
                            </div>
                        </div>

                        <input type="radio" id="profile_panel_monitoring_input_log" name="main_panel" <?= $panel === 'profile_panel_monitoring_input_log' ? 'checked' : null ?> />
                        <div class="col p-3">
                            Журнал в разработке
                        </div>
                    </div>
                </div>
            </div>
        </article>
    </div>
</div>

<script src="/js/profile.js" defer></script>
<?php if (
    !yii::$app->user->isGuest
    && (yii::$app->user->identity->type === 'administrator'
        || yii::$app->user->identity->type === 'moderator')
) : ?>
    <script src="/js/profile_panel.js" defer></script>
<?php endif ?>
