<?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 */

$this->addTemplate('adm::faq/scripts');

/** @var $layoutInfo \App\Entity\LayoutInfo */
$layoutInfo = $this->layoutInfo;

/** @var \App\Entity\FAQ\Category[] $categories */
$categories = $this->categories;

$renderedItems = [];

/** @var \App\Entity\FAQ\Item[] $items */
$items = $this->items;
// @fixme seems there some output buffer bug
// first value of loop foreach ($items[$category->getId()] as $itemKey => $item) rendered as ''
// it's a quick fix and required detailed research
$this->partial('adm::dummy', []);
?>

    <form method="post" action="<?= $this->url('adm.faq', []) ?>">
    <section class="b-content__title">
        <div class="wrapp">
            <h1><?= _t("Помощь") ?></h1>
            <div class="row">
                <p class="lead col sm-offset-1 sm-10"><?= _t("Вопросы с которыми чаще всего сталкиваются наши клиенты") ?></p>
            </div>
        </div>
    </section>
    <section class="b-content__accordeon">
        <div class="wrapp row">
            <div class="b-content__accordeon-category col sm-offset-1 sm-10">
                <?php
                /** @var \App\Entity\FAQ\Category $category */
                foreach ($categories as $category) :
                    ?>
                    <div class="b-content__accordeon-category-inner m-content__accordeon-category-inner_<?= $category->getId() ?>">
                        <h2 class="b-content__accordeon-category-title" data-open-category><?= $category->getName() ?>
                            <button class="btn btn-primary" role="button" type="button" data-action="<?= $this->url('adm.faq.category.edit', [
                                'id' => $category->getId(),
                                'lang' => $this->lang
                            ]) ?>"><?= _t('Edit') ?></button>
                            <div class="btn-group" role="group">
                                <button type="button" role="button" class="btn btn-primary <?= $category->getHidden() ? '': 'btn-danger' ?>"
                                        data-toggle
                                        data-activate="<?= $this->url('adm.faq.category.activate', [
                                            'id' => $category->getId(),
                                            'lang' => $this->lang,
                                        ]) ?>"
                                        data-activate-caption="<?= _t('Activate') ?>"
                                        data-hide="<?= $this->url('adm.faq.category.hide', [
                                            'id' => $category->getId(),
                                            'lang' => $this->lang,
                                        ]) ?>"
                                        data-hide-caption="<?= _t('Hide') ?>"
                                        data-value="<?= $category->getHidden() ? 'data-activate' : 'data-hide' ?>"
                                >
                                    <?= $category->getHidden() ? _t('Activate') : _t('Hide') ?>
                                </button>
                            </div>

                        </h2>
                        <div class="wrapp-category">
                            <?php /** @var \App\Entity\FAQ\Item $item */
                            if ($items[$category->getId()]) {
                                foreach ($items[$category->getId()] as $itemKey => $item) { ?>
                                    <?= $this->partial('adm::/faq/category-item', [
                                        'itemKey' => $itemKey,
                                        'item' => $item,
                                        'lang' => $this->lang,
                                        'addScripts' => false,
                                        'showButtons' => true,
                                    ]);
                                }
                            }
                            ?>
                            <div class="b-content__accordeon-category-item">

                                <div class="b-content__accordeon-category-item-title lead" data-number='+'>
                                    <button role="button" type="button" class="btn btn-primary" data-action="<?= $this->url('adm.faq.item.create', [
                                        'categoriesId' => $category->getId(),
                                        'lang' => $this->lang,
                                    ]); ?>"><?= _t("Добавить новый вопрос/ответ")?></button>
                                </div>
                            </div>
                        </div>
                    </div>
                <?php endforeach; ?>
            </div>
        </div>
    </section>
    </form>

