<?php
/**
 * Landofcoder
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Landofcoder.com license that is
 * available through the world-wide-web at this URL:
 * https://landofcoder.com/terms
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade this extension to newer
 * version in the future.
 *
 * @category   Landofcoder
 * @package    Lof_Formbuilder
 * @copyright  Copyright (c) 2021 Landofcoder (https://www.landofcoder.com/)
 * @license    https://landofcoder.com/terms
 */

use Lof\Formbuilder\Helper\Data;

$helper = $this->helper(Data::class);
$collection = $this->getCollection();
$total = $collection->count();
$blockId = rand() . time();
$tabId = 'formbuilder' . $blockId;
$widgetClass = $this->getConfig('prefix_class');
$gridPagination = true;

?>
<div id="<?= $tabId; ?>" class="formbuilder-messages <?= $widgetClass; ?>">
    <div class="row lof-formbuilder">
        <div class="formbuilder-container">
            <?php if ($total) { ?>
                <ul>
                    <?php foreach ($collection as $message) { ?>
                        <?php $form = $this->getFormInfo($message->getFormId()); ?>
                        <?php if ($form && $form->getId()) { ?>
                            <li><strong><?= __("Submit from the Form: "); ?></strong> <a
                                    href="<?= $block->escapeUrl($helper->getFormUrl($form->getIdentifier())); ?>"
                                    target="_BLANK"><?= $form->getTitle(); ?></a></li>
                        <?php } ?>
                        <li><?= $message->getSafedMessage() ?></li>
                    <?php } ?>
                </ul>
            <?php } else { ?>
                <div class="message info empty">
                    <span><?= $block->escapeHtml(__('There are no messages yet.')); ?></span>
                </div>
            <?php } ?>
        </div>
        <?php if ($gridPagination) { ?>
            <?= $this->getPagerHtml(); ?>
        <?php } ?>
    </div>
</div>
