<?php
declare(strict_types=1);

use Hyva\Theme\Model\ViewModelRegistry;
use Hyva\Theme\ViewModel\ProductAttributes;
use Hyva\Theme\ViewModel\ProductCompare;
use Hyva\Theme\ViewModel\ProductPage;
use Hyva\Theme\ViewModel\Wishlist;
use Magento\Catalog\Model\Product;
use Magento\Framework\Escaper;
use Magento\Framework\View\Element\Template;

/** @var Template $block */
/** @var Escaper $escaper */
/** @var ViewModelRegistry $viewModels */
/** @var \FoundationCommerce\ThemeViewModels\ViewModels\ThemeIcons $icons */
$icons = $viewModels->require(\FoundationCommerce\ThemeViewModels\ViewModels\ThemeIcons::class);

/** @var ProductPage $productViewModel */
$productViewModel = $viewModels->require(ProductPage::class);
/** @var ProductAttributes $attributesViewModel */
$attributesViewModel = $viewModels->require(ProductAttributes::class);
/** @var Product $product */
$product = $productViewModel->getProduct();
?>
<div class="order-2 w-full mb-6 lg:pl-10 lg:w-1/2 md:mb-0">
    <div>
    <?= $block->getChildHtml('product_view_brand_logo') ?>
    </div>
    <h1 class="text-2xl font-bold text-black">
        <?= $escaper->escapeHtml($product->getName()) ?>
    </h1>

    <div class="flex flex-row mt-2 mb-5 sm:flex-row">
        <div class="flex items-center mr-6">
            <span class="leading-4 uppercase text-primary">
            <?= $escaper->escapeHtml(__('Sku')) ?>:&nbsp;</span>
            <span class="leading-4 uppercase text-primary">
                <?= $escaper->escapeHtml($product->getSku()) ?>
            </span>
        </div>
        <div class="px-2 lg:pl-6 py-1.5 font-normal leading-5 text-black bg-secondary-lighter bg-transparent px-0">
            <?= $block->getChildHtml('product_type_data') ?>
        </div>
        <?= $block->getChildHtml("aimsi_stock_message"); ?>
        <?= $block->getChildHtml("msiss_stock_message"); ?>
        <?= $block->getChildHtml("alert.urls") ?>
    </div>

    <div>
        <?= $block->getChildHtml("product.info.price") ?>
    </div>

    <?php if ($shortDescription = $productViewModel->getShortDescription()) { ?>
        <div class="mb-4 leading-relaxed prose product-description"><?= /* @noEscape */ $shortDescription ?></div>
    <?php } ?>

    <?= $block->getChildHtml('product.info.form') ?>

    <div class="flex flex-wrap items-center justify-between mt-6 mb-5 lg:justify-between<?php if ($product->isSaleable()): ?> lg:flex-nowrap<?php endif; ?>" >
            <?php if ($product->isSaleable()): ?>
                <?= $block->getChildHtml("product.info.quantity") ?>
                <?= $block->getChildHtml("product.info.addtocart") ?>
            <?php else : ?>
                <div class="flex items-center justify-around w-full lg:w-auto">
                    <div class="text-base font-normal leading-4 uppercase lg:font-semibold lg:mr-10">
                        <?= $escaper->escapeHtml(__('Out of stock')) ?>
                    </div>
                    <?php if ($backInStockDate = $product->getData('back_in_stock_date')): ?>
                    <div class="text-base font-normal leading-4">
                        <span class="font-semibold"><?= $product->getData('back_in_stock_date') ?></span>
                    </div>
                    <?php endif; ?>
                </div>
                <div class="flex items-center w-full py-2 mt-6 text-black lg:order-4">
                    <span class="mr-4">
                    <?= $icons->bellHtml(" ", 16, 18) ?>
                    </span>
                    <span class='font-semibold leading-4 text-black tracking-widerer'><?= $escaper->escapeHtml(__('Notify me when back in stock')); ?></span>
                </div>
            <?php endif; ?>
            <?= $block->getChildHtml('product.info.addtowishlist'); ?>
    </div>

    <?php if ($product->isSaleable()): ?>
        <div class="flex justify-end">
            <?= $block->getChildHtml('addtocart.shortcut.buttons') ?>
        </div>
    <?php endif; ?>

    <div class="flex justify-end">
        <?= $block->getChildHtml('product.info.emailtofriend'); ?>
    </div>

    <?php if ($tierPriceBlock = $block->getChildHtml("product.price.tier")): ?>
        <div class="py-4 my-2 tier-price-container">
            <?= /** @noEscape */ $tierPriceBlock ?>
        </div>
    <?php endif; ?>

    <?= $block->getChildHtml("product.info.additional") ?>
    <div class="flex items-center py-2 text-black">
        <span class="mr-4">
        <?= $icons->truckSolidHtml(" ", 22, 18) ?>
        </span>
        <span class='text-base font-normal leading-4 tracking-widerer'><?= $escaper->escapeHtml(__('Free delivery when you spend CHF 200, plus free returns!')); ?></span>
    </div>
    <div class="related-parent">
      <?= $block->getChildHtml('related') ?>
    </div>
</div>
