<?php
/**
 * Hyvä Themes - https://hyva.io
 * Copyright © Hyvä Themes 2020-present. All rights reserved.
 * This product is licensed per Magento install
 * See https://hyva.io/license
 */

declare(strict_types=1);

use Hyva\Theme\Model\ViewModelRegistry;
use Hyva\Theme\ViewModel\CurrentProduct;
use Magento\Catalog\Model\Product;
use Magento\Framework\Escaper;
use Magento\Framework\View\Element\Template;

// phpcs:disable Magento2.Templates.ThisInTemplate.FoundThis

/** @var Template $block */
/** @var Escaper $escaper */
/** @var ViewModelRegistry $viewModels */

/** @var CurrentProduct $currentProduct */
$currentProduct = $viewModels->require(CurrentProduct::class);

/** @var Product $product */
$product = $block->hasData('product')
    ? $block->getData('product')
    : $currentProduct->get();

if (!$product || !$product->getId()) {
    return;
}

$inStock = $product->getIsSalable();
?>


<div class="flex items-center align-middle border-b border-gray-300 pb-4  stock gap-4"
     title="<?= $escaper->escapeHtmlAttr(__('Available')) ?>">
    <svg width="24px" height="24px" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="none" stroke="#000" stroke-width=".8">
        <g id="SVGRepo_iconCarrier">
            <path d="M18 5.498l-5.5-2.26L7 5.499v5.655l-5 2.054v6.443l5.5 2.259 5-2.054 5 2.054 5.5-2.26v-6.442l-5-2.054zm-.5 9.462l-3.432-1.404 3.576-1.468 3.432 1.41zM12 8.127v4.669l-4-1.643V6.492zm1 4.669V8.127l4-1.635v4.661zm-2.068.76L7.5 14.96l-3.576-1.463 3.432-1.41zM8 15.836l4-1.636v4.78l-4 1.642zm8.076-10.047L12.5 7.25 8.924 5.79 12.5 4.32zM3 14.2l4 1.636v4.786L3 18.98zm10 0l4 1.636v4.786l-4-1.642zm5 6.422v-4.786l4-1.636v4.78z" stroke-linecap="round" stroke-linejoin="round"></path>
        </g>
    </svg>

    <div class="flex items-center gap-1">
        <span class="font-sen">Stock Availability:</span>
        <span  class="font-sen" style="color: <?= $inStock ? '#16a34a' : '#ef4444' ?>; font-weight: 600;">
            <?= $escaper->escapeHtml($inStock ? __('In Stock') : __('Not available')) ?>
        </span>
    </div>
</div>


