<?php
/**
 * MagePrince
 * Copyright (C) 2020 Mageprince <info@mageprince.com>
 *
 * @package Mageprince_Faq
 * @copyright Copyright (c) 2020 Mageprince (http://www.mageprince.com/)
 * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License,version 3 (GPL-3.0)
 * @author MagePrince <info@mageprince.com>
 */
?>
<?php
/** @var $block \Mageprince\Faq\Block\Index\Index */
$pageType = $block->getPageTypeAction();
$faqGroupCollection = $block->getFaqGroupCollection();
?>
<?php if ($faqGroupCollection->getSize()) : ?>
    <?php if ($block->isEnable()) : ?>
    <div class="faq-collection">
        <?php if ($block->getGroupId()) : ?>
            <div id="faq-content" class="faq-content">
                <?php if ($block->isShowGroupTitle()) : ?>
                <?php $groupData = $block->getGroupById($block->getGroupId()); ?>
                    <div class="group-title">
                        <?= /* @noEscape */ __($groupData->getGroupName()) ?>
                    </div>
                <?php endif; ?>
                <div class="faq-accordion">
                    <?php $faqCollection = $block->getFaqCollection($block->getGroupId()); ?>
                    <?php if ($faqCollection->getSize()) : ?>
                        <?php foreach ($faqCollection as $faq) : ?>
                            <h3><?= /* @noEscape */ __($faq->getTitle()) ?></h3>
                            <div>
                                <p><?php /* @noEscape */ echo $block->filterOutputHtml($faq->getContent()); ?></p>
                            </div>
                        <?php endforeach; ?>
                    <?php endif; ?>
                </div>
            </div>
        <?php else: ?>
            <?php if ($block->isShowGroup() || $pageType == 'ajax') : ?>
                <div class="faq-groups">
                    <?php foreach ($faqGroupCollection as $group) : ?>
                        <div class="faq-group">
                            <?php if ($block->isShowGroupTitle()) : ?>
                                <div class="faq-groupname">
                                	<?php if($block->getFaqCollection($group->getId())->getSize() > 0): ?>
                                        <a href="#group<?php /* @noEscape */ echo $group->getFaqgroupId(); ?>" class="group-link" groupId="<?php /* @noEscape */ echo $group->getFaqgroupId(); ?>">
                                            <?php /* @noEscape */ echo $group->getGroupName(); ?>
                                        </a>
                                    <?php else: ?>
                                    	<?php /* @noEscape */ echo $group->getGroupName(); ?>
                                    <?php endif; ?>
                                </div>
                            <?php endif; ?>
                        </div>
                    <?php endforeach; ?>
                </div>
            <?php endif; ?>
            <div id="faq-content" class="faq-content">
                <?php if ($pageType == 'scroll') : ?>
                    <?php foreach ($faqGroupCollection as $group) : ?>
                    	<?php $faqCollection = $block->getFaqCollection($group->getId()); ?>
                        <?php if ($faqCollection->getSize()) : ?>
                            <div id="group<?php /* @noEscape */ echo $group->getFaqgroupId(); ?>">
                                <?php if ($block->isShowGroupTitle()) : ?>
                                    <div class="group-title">
                                        <i></i><?php /* @noEscape */ echo $group->getGroupName(); ?>
                                    </div>
                                <?php endif; ?>
                                <div class="faq-accordion">
                                    <?php foreach ($faqCollection as $faq) : ?>
                                        <h3><?= /* @noEscape */ __($faq->getTitle()) ?></h3>
                                        <div>
                                            <p><?php /* @noEscape */ echo $block->filterOutputHtml($faq->getContent()); ?></p>
                                        </div>
                                    <?php endforeach; ?>
                                </div>
                            </div>
                        <?php endif; ?>
                    <?php endforeach; ?>
                <?php else :?>
                    <?php $group = $faqGroupCollection->getFirstItem(); ?>
                    <?php if ($block->isShowGroupTitle()) : ?>
                        <div class="group-title" id="group<?php /* @noEscape */ echo $group->getFaqgroupId(); ?>">
                            <i></i><?php /* @noEscape */ echo $group->getGroupName(); ?>
                        </div>
                    <?php endif; ?>
                    <div class="faq-accordion">
                        <?php $faqCollection = $block->getFaqCollection($group->getId()); ?>
                        <?php if ($faqCollection->getSize()) : ?>
                            <?php foreach ($faqCollection as $faq) : ?>
                                <h3><?= /* @noEscape */ __($faq->getTitle()) ?></h3>
                                <div>
                                    <p><?php /* @noEscape */ echo $block->filterOutputHtml($faq->getContent()); ?></p>
                                </div>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </div>
                <?php endif; ?>
            </div>
        <?php endif; ?>
    </div>
    <?php endif; ?>
<?php else : ?>
    <div>
        <h1><?= /* @noEscape */ __('No FAQ Group available') ?></h1>
    </div>
<?php endif; ?>
<script type="text/x-magento-init">
    {
        "*": {
            "faq": {
                "pageType" : "<?= $pageType ?>",
                "ajax_url" : "<?= $block->getBaseUrl() ?>"
            }
        }
    }
</script>
