<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
// phpcs:disable Generic.Files.LineLength
/** @var $block \Magento\AdminNotification\Block\ToolbarEntry */
    $notificationCount = $block->getUnreadNotificationCount();
    $notificationCounterMax = $block->getNotificationCounterMax();
?>
<div
    data-mage-init='{"toolbarEntry": {}}'
    class="notifications-wrapper admin__action-dropdown-wrap"
    data-notification-count="<?= (int)$notificationCount ?>">
    <?php if ($notificationCount > 0): ?>
        <a
            href="<?= $block->escapeUrl($block->getUrl('adminhtml/notification/index')) ?>"
            class="notifications-action admin__action-dropdown"
            data-mage-init='{"dropdown":{}}'
            title="<?= $block->escapeHtmlAttr(__('Notifications')) ?>"
            data-toggle="dropdown">
            <span class="notifications-counter">
                <?= /* @noEscape */ ($notificationCount > $notificationCounterMax) ? (int)$notificationCounterMax . '+' : (int)$notificationCount ?>
            </span>
        </a>
        <ul
            class="admin__action-dropdown-menu"
            data-mark-as-read-url="<?= $block->escapeUrl($block->getUrl('adminhtml/notification/ajaxMarkAsRead')) ?>">
            <?php foreach ($block->getLatestUnreadNotifications() as $notification): ?>
                <?php /** @var $notification \Magento\AdminNotification\Model\Inbox */ ?>
                <li class="notifications-entry<?php if ($notification->getSeverity() == 1): ?> notifications-critical<?php endif; ?>"
                    data-notification-id="<?= $block->escapeHtmlAttr($notification->getId()) ?>"
                    data-notification-severity="<?php if ($notification->getSeverity() == 1): ?>1<?php endif; ?>">
                    <?php
                        $notificationDescription = $notification->getDescription() ?? '';
                        $notificationDescriptionLength = $block->getNotificationDescriptionLength();
                    ?>
                    <strong class="notifications-entry-title">
                        <?= $block->escapeHtml($notification->getTitle()) ?>
                    </strong>
                    <?php if (strlen($notificationDescription) > $notificationDescriptionLength): ?>
                        <p class="notifications-entry-description _cutted">
                            <span class="notifications-entry-description-start">
                                <?= $block->escapeHtml(substr($notificationDescription, 0, $notificationDescriptionLength)) ?>
                            </span>
                            <span class="notifications-entry-description-end">
                                <?= $block->escapeHtml(substr($notificationDescription, $notificationDescriptionLength)) ?>
                            </span>
                        </p>
                    <?php else: ?>
                        <p class="notifications-entry-description">
                            <?= $block->escapeHtml($notificationDescription) ?>
                        </p>
                    <?php endif; ?>
                    <time class="notifications-entry-time">
                        <?= $block->escapeHtml($block->formatNotificationDate($notification->getDateAdded())) ?>
                    </time>
                    <button
                        type="button"
                        class="notifications-close"
                        title="<?= $block->escapeHtmlAttr(__('Close')) ?>"
                        ></button>
                </li>
            <?php endforeach; ?>
            <li class="notifications-entry notifications-entry-last">
                <a
                    href="<?= $block->escapeUrl($block->getUrl('adminhtml/notification/index')) ?>"
                    class="action-tertiary action-more">
                    <?= $block->escapeHtml(__('See All (')) ?><span class="notifications-counter"><?= (int)$notificationCount ?></span><?= $block->escapeHtml(__(' unread)')) ?>
                </a>
            </li>
        </ul>
    <?php else: ?>
        <a
            class="notifications-action admin__action-dropdown"
            href="<?= $block->escapeUrl($block->getUrl('adminhtml/notification/index')) ?>"
            title="<?= $block->escapeHtmlAttr(__('Notifications')) ?>">
        </a>
    <?php endif; ?>
</div>
