<?php
/* @var $block \Mirasvit\Rma\Block\Rma\View\History */
$messages   = $block->getMessages();
?>
<?php if (count($messages)): ?>
    <div class="mst-rma-box _half mst-rma__history">
        <div class="mst-rma-box__title"><?= __('RMA History') ?></div>
        <div class="mst-rma-box__content">
            <?php foreach ($messages as $message): ?>
                <div class="mst-rma__message <?= $block->getBodyStyles($message); ?>">
                    <div class="mst-rma__message-title">
                        <?php if ($message->getCustomerName()): ?>
                            <strong><?= $block->escapeHtml($message->getCustomerName()) ?></strong>
                        <?php elseif (($user = $block->getUser($message)) && trim($user->getName())): ?>
                            <?php if (!$message->getStatusId()): ?>
                                <strong><?= $block->escapeHtml($user->getName()) ?></strong>
                            <?php endif ?>
                        <?php endif ?>

                        <i><?= $block->formatDate($message->getCreatedAt(), \IntlDateFormatter::MEDIUM) ?> <?= $block->formatTime($message->getCreatedAt(), \IntlDateFormatter::SHORT) ?></i>
                    </div>

                    <div class="mst-rma__message-body">
                        <?php //do filter auto messages ?>
                        <?php if ($message->getStatusId()): ?>
                            <?= $block->getTextHtml($message) ?>
                        <?php else: ?>
                            <?= $block->escapeHtml($block->getTextHtml($message), ['b', 'br', 'strong', 'i', 'u', 'a']) ?>
                        <?php endif; ?>

                        <?php if ($attachments = $block->getAttachments($message)): ?>
                            <?php foreach ($attachments as $attachment): ?>
                                <br>
                                <a href="<?= $block->getAttachmentUrl($attachment) ?>">
                                    <?= $block->escapeHtml($attachment->getName()) ?>
                                </a>
                            <?php endforeach ?>
                        <?php endif ?>
                    </div>
                </div>
            <?php endforeach ?>
        </div>
    </div>
<?php endif ?>
