<?php
/**
 * Copyright (c) 2016 Serhii Borodai <clarifying@gmail.com>.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 *  all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 *
 */

/** @var $this \Zend\View\Renderer\PhpRenderer */

/** @var $userSiteStatistic \App\Entity\Statistic\Site */

$this->headScript()
    ->appendFile('/js/underscore-min.js')
    ->appendFile('/js/jquery.cookie.js')
    ->appendFile('/js/bootstrap.min.js')
    ->appendFile('/js/c3.min.js')
    ->appendFile('/js/d3.min.js')
    ->appendFile('/js/datepicker.min.js')
    ->appendFile('/js/script-feeds-stat-charts.js')
    ->appendFile('/js/script-feeds-stat-table.js')
    ->appendFile('/js/script-feeds-stat.js')
;

$this->headLink()
    ->appendStylesheet('/css/c3.css')
    ->appendStylesheet('/css/datepicker.min.css')
    ->appendStylesheet('/css/styles-feeds-stat.css')
;



/** @var \App\Entity\IdentityInterface $identity */
$identity = $this->identity();
$gravatar = $this->gravatar($identity->getEmail());
$gravatar->setDefaultImg(\Zend\View\Helper\Gravatar::DEFAULT_IDENTICON);
$sxml = new SimpleXMLElement(substr($gravatar, 0, -1) . '/>');
$src = $sxml['src'];

$error = $this->error;
$periodStats = $this->periodStats;
$dates = $this->dates;


?>

<section class="b-content__title">
    <div class="wrapp">
        <!-- Вход произведен -->
        <picture>
            <img src="/img/bg-img-logo.svg" alt="No logo">
        </picture>
        <p class="lead"><?= $identity->getEmail() ?></p>
        <p class="b-content__title-settings">
            <a href="<?= $this->url('user.cabinet.profile', ['lang' => $this->lang]) ?>" title="" class="annotation"><?= _t("Настройки профиля") ?></a>
            <a href="<?= $this->url('logout', ['lang' => $this->lang]) ?>" title="" class="annotation"><?= _t("Выход") ?></a>
        </p>
    </div>
</section>

<?php if($error): ?>

    <section class="b-content__work">
        <h1><?= $error?></h1>
    </section>

<?php else: ?>

    <textarea id="period-stats" style="display: none;"><?= ($periodStats ? json_encode($periodStats) : '')?></textarea>

    <section class="b-content__work">
        <div class="wrapp">
            
            <div class="b-feeds-stat_controls form-group">
                
                <div class="b-feeds-stat_controls-report">
                    <div class="dropdown" style="display:inline-block;">
                        <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
                            <?= _t('Сводный отчет') ?>
                            <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu" aria-labelledby="dropdownMenu">
                            <li><a href="#" class="current" report="<?= $report ?>"><?= _t('Сводный отчет') ?></a></li>
                            <li><a href="#" class="current" report="<?= $report ?>"><?= _t('Отчет 1') ?></a></li>
                            <li><a href="#" class="current" report="<?= $report ?>"><?= _t('Отчет 2') ?></a></li>
                            <li><a href="#" class="current" report="<?= $report ?>"><?= _t('Отчет 3') ?></a></li>
                        </ul>
                    </div>
                </div>
                
                <span class="b-feeds-stat_controls-period">

                    <div style="display:inline-block;">Дата: </div>
                    <input type='text' id="date-value-1" class="btn btn-default date-value" value="<?=$dates[0] ?>"/> &ndash; 
                    <input type='text' id="date-value-2" class="btn btn-default date-value" value="<?=$dates[1] ?>"/>

                    <span>период: </span>
                    <select class="form-control order-period" name="period">
                        <option value="" disabled>--</option>
                        <option value="today">сегодня</option>
                        <option value="yesterday">вчера</option>
                        <option value="7days">7 дней</option>
                        <option value="30days">30 дней</option>
                        <option value="current_month">текущий месяц</option>
                        <option value="prev_month" selected>прошлый месяц</option>
                        <option value="year">год</option>
                    </select>
                </span>
            </div>
                
            <div class="chart-graph-stat-info">
                <h2>По заданным параметрам статистика отсутствует</h2>
            </div>
            <div class="chart-graph-stat-error">
                <h2>Ошибка в статистике</h2>
                <div class="message"></div>
            </div>

            <?php /* График */ ?>
            <div id="chart-graph-stat" style="height: 370px;"></div>
            <div class="chart-graph-stat-loading"></div>
                
            <?php /* Таблица */ ?>
            <div id="table-stat" class="b-table_wrapp">
                <div class="b-content__loading"></div>
                <table id="table-line" class="table table-striped admin">
                    <thead class="metric sortable">
                        <tr data-metric="<?= $metric ?>">
                            <th><?= _t('Дата/Компания')?></th>
                            <?php foreach(['shows', 'clicks', 'transactions', 'salemoney', 'admoney'] as $name): ?>
                            <th>
                                <input type="checkbox" />
                                <b id="<?= $name ?>">
                                    <?= _t($name)?>
                                    <!--
                                    <b class="arrow asc">&and;</b>
                                    <b class="arrow desc">&or;</b>
                                    -->
                                </b>
                            </th>
                            <?php endforeach ?>
                        </tr>
                    </thead>
                    <tbody>
                    </tbody>
                </table>
            </div>
            
        </div>
    </section>


<?php endif ?>