<?php

/**
 * Copyright © 2020 Wyomind. All rights reserved.
 * See LICENSE.txt for license details.
 */

?>

<?php $_product = $block->getProduct() ?>

<?php if ($block->displayProductStockStatus()) : ?>

    <div class="stock available" title="<?= $block->escapeHtmlAttr(__('Availability')) ?>">
        <?php
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        /** @var $stockStatus  \Wyomind\MsiStockStatus\Helper\StockStatus */
        $stockStatus = $objectManager->create("\Wyomind\MsiStockStatus\Helper\StockStatus");
        $storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
        $storeId = $storeManager->getStore()->getStoreId();
        if ($stockStatus->framework->getStoreConfig("msistockstatus/settings/status/in_product", $storeId) && $stockStatus->framework->getStoreConfig("msistockstatus/settings/status/replace_default", $storeId)) :
            $status = $stockStatus->getStockStatus($_product);
            ?>
            <div class="msiss-message-container simple <?= $status["type"];?> <?= $status["type"] == 'success'?'text-green-500':'text-red-500'; ?>">
                <div class="msiss-message">
                    <?= $status["text"]; ?>
                </div>
            </div>
        <?php                                                                                                                                                                                                                 else: ?>
            <?php if ($_product->isAvailable()) : ?>
                <div class="stock available" title="<?= $block->escapeHtmlAttr(__('Availability')) ?>">
                    <span><?= $block->escapeHtml(__('In stock')) ?></span>
                </div>
            <?php else : ?>
                <div class="stock unavailable" title="<?= $block->escapeHtmlAttr(__('Availability')) ?>">
                    <span><?= $block->escapeHtml(__('Out of stock')) ?></span>
                </div>
            <?php endif; ?>
        <?php endif; ?>

    </div>

<?php endif; ?>
