<?php

use common\helpers\AdminLTE;
use common\helpers\Image;
use yii\helpers\Html;

$this->setTitle('Tableau de bord');
$this->setMetaRefresh(true);

?>

<div class="dashboard-admin-index">

    <div id="producers-online" class="box box-solid">
        <div class="box-header with-border">
            <i class="fa fa-bookmark"></i>
            <h3 class="box-title">Producteurs en ligne</h3>
        </div>
        <div class="box-body">
            <?php if($usersWithStatusProducerOnlineArray && count($usersWithStatusProducerOnlineArray) > 0): ?>
                <?php foreach ($usersWithStatusProducerOnlineArray as $userWithStatusProducerOnline): ?>
                    <?php $producer = $userWithStatusProducerOnline->producer; ?>
                    <?php if($producer): ?>
                        <a class="btn btn-default" title="Aller sur le compte de ce producteur" href="<?= $this->getUrlManagerBackend()->createUrl(['site/switch-producer', 'id' => $producer->id]); ?>">
                            <?= $producer->name; ?>
                        </a>
                    <?php endif; ?>
                <?php endforeach; ?>
                <div class="clr"></div>
            <?php else: ?>
                <p><em>Aucun producteur en ligne actuellement.</em></p>
            <?php endif; ?>
        </div>
    </div>

    <div class="row">
        <div class="col-lg-6 col-xs-6">
            <?= AdminLTE::smallBox(
                $countUsersOnline,
                'Utilisateurs en ligne',
                $countUsersOnline ? 'green' : 'blue',
                'wifi',
                Yii::$app->urlManager->createUrl('online-admin/index')
            ) ?>
        </div>
        <div class="col-lg-6 col-xs-6">
            <?php $countUsersWithProblemReceivingEmails = $this->getUserModule()->getRepository()->countUsersWithProblemReceivingEmails(); ?>
            <?= AdminLTE::smallBox(
                $countUsersWithProblemReceivingEmails,
                'Problèmes réception emails',
                $countUsersWithProblemReceivingEmails ? 'red' : 'green',
                'send',
                Yii::$app->urlManager->createUrl('user-admin/email-deliverability')
            ) ?>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-6 col-xs-6">
            <?= AdminLTE::smallBox(
                $supportOnline ? 'Oui' : 'Non',
                'Support activé',
                $supportOnline ? 'green' : 'blue',
                'phone',
                Yii::$app->urlManager->createUrl(['dashboard-admin/support-online-toggle', 'active' => $supportOnline ? 0 : 1]),
                $supportOnline ? 'Désactiver' : 'Activer'
            ) ?>
        </div>
        <div class="col-lg-6 col-xs-6">
            <?php
                $colorBoxTicket = 'blue';
                if($countTicketsAdminOpen == 0) {
                    $colorBoxTicket = 'green';
                }
                elseif($countTicketsAdminUnread == 0) {
                    $colorBoxTicket = 'blue';
                }
                elseif($countTicketsAdminUnread > 0) {
                    $colorBoxTicket = 'red';
                }
            ?>
            <?= AdminLTE::smallBox(
                $countTicketsAdminOpen,
                'Tickets',
                $colorBoxTicket,
                'comments',
                Yii::$app->urlManager->createUrl('support-admin/index')
            ) ?>
        </div>
    </div>

    <div id="dashboard-admin-statistics-html">
        <a class="btn btn-default btn-load" href="javascript:void(0);">Charger les statistiques</a>
    </div>
</div>