<?php
$generateHelper = $this->helper('MGS\Fbuilder\Helper\Generate');

use Magento\Framework\App\Action\Action;

$callHelper = $this->helper('MGS\Callforprice\Helper\Data');
$test = $this->getLayout()->createBlock('MGS\Callforprice\Block\RequestQuote')->getFormAction();
$_product = $block->getProduct();
$priceRender = $block->getLayout()->getBlock('product.price.render.default');
if (!$priceRender) {
    $priceRender = $block->getLayout()->createBlock(\Magento\Framework\Pricing\Render::class, 'product.price.render.default');
}

$priceHtml = $priceRender->render(
    \Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE,
    $_product,
    [
        'display_minimal_price' => false,
        'zone' => \Magento\Framework\Pricing\Render::ZONE_ITEM_VIEW,
        'list_category_page' => true
    ]
);


/** @var \Magento\Customer\Model\Session $customerSession */
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->get(\Magento\Customer\Model\Session::class);
$UrlInterface = $objectManager->get(\Magento\Framework\UrlInterface::class);

?>
<?php if ($generateHelper->getCurrentTheme() == "Smartwave/porto"): ?>
    <?php
    $_helper = $this->helper('Magento\Catalog\Helper\Output');
    $_imagehelper = $this->helper('Magento\Catalog\Helper\Image');
    // Daily deal Helper
    $_dailydealhelper = $this->helper('Smartwave\Dailydeals\Helper\Data');
    $_portohelper = $this->helper('Smartwave\Porto\Helper\Data');
    $_category_config = $_portohelper->getConfig('porto_settings/category');
    $_category_grid_config = $_portohelper->getConfig('porto_settings/category_grid');
    $_product_label_config = $_portohelper->getConfig('porto_settings/product_label');
    $_lazyload = $_portohelper->getConfig('porto_settings/optimization/lazyload');
    $_product = $this->getLoadProduct($this->getProductId());
    $_helper = $this->helper('Magento\Catalog\Helper\Output');
    $builderHelper = $this->helper('MGS\Fbuilder\Helper\Data');
    $hideName = $this->getBlockData('hide_name');
    $hideReview = $this->getBlockData('hide_review');
    $hidePrice = $this->getBlockData('hide_price');
    $hideAddCart = $this->getBlockData('hide_addcart');
    $hideAddWishlist = $this->getBlockData('hide_addwishlist');
    $hideAddCompare = $this->getBlockData('hide_addcompare');
    $htmlStructure = $builderHelper->getStoreConfig('fbuilder/html_structure/product_grid');
    $viewMode = 'grid';
    $image = 'category_page_grid';
    $hover_image = 'category_page_grid-hover';
    $showDescription = false;
    $templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
    $columns = 'columns' . $_category_grid_config['columns'];
    $product_type = $_category_grid_config['product_type'];
    if ($product_type == null) {
        $product_type = 1;
    }
    $image_width = ($_category_config['ratio_width']) ? $_category_config['ratio_width'] : 300;
    $image_height = ($_category_config['ratio_height']) ? $_category_config['ratio_height'] : 300;
    $aspect_ratio = $_category_config['aspect_ratio'];
    if ($aspect_ratio) {
        $image_height = $image_width;
    }
    ?>
    <div class="product-item-info type<?php echo $product_type; ?>" data-container="product-grid">
        <?php // Product Image ?>
        <div class="product photo product-item-photo">
            <a href="<?php echo $_product->getProductUrl() ?>" tabindex="-1">
                <?php
                if ($aspect_ratio) {
                    $productImage = $_imagehelper->init($_product, $image)->constrainOnly(false)->keepAspectRatio(true)->keepFrame(false)->resize($image_width);
                } else {
                    $productImage = $_imagehelper->init($_product, $image)->resize($image_width, $image_height);
                }
                $productImageUrl = $productImage->getUrl();
                ?>
                <img class="product-image-photo default_image <?php if (!$_lazyload): ?>porto-lazyload<?php endif; ?>"
                     <?php if (!$_lazyload): ?>data-<?php endif; ?>src="<?php echo $productImageUrl; ?>"
                     width="<?php echo $image_width; ?>" height="<?php echo $image_height; ?>" alt=""/>
                <?php if ($_category_config['alternative_image']): ?>
                    <?php
                    if ($aspect_ratio) {
                        $productHoverImage = $_imagehelper->init($_product, $hover_image)->constrainOnly(false)->keepAspectRatio(true)->keepFrame(false)->resize($image_width);
                    } else {
                        $productHoverImage = $_imagehelper->init($_product, $hover_image)->resize($image_width, $image_height);
                    }
                    $productHoverImageUrl = $productHoverImage->getUrl();
                    ?>
                    <?php if ($productImageUrl != str_replace("/thumbnail/", "/small_image/", $productHoverImageUrl)): ?>
                        <img class="product-image-photo hover_image" src="<?php echo $productHoverImageUrl; ?>" alt=""/>
                    <?php endif; ?>
                <?php endif; ?>
            </a>
            <?php
            $product_label = "";
            if ($_product_label_config['sale_label']) {
                $orgprice = $_product->getPrice();
                $specialprice = $_product->getSpecialPrice();
                $specialfromdate = $_product->getSpecialFromDate();
                $specialtodate = $_product->getSpecialToDate();
                $today = time();
                if (!$specialprice) {
                    $specialprice = $orgprice;
                }
                if ($specialprice < $orgprice) {
                    if ((is_null($specialfromdate) && is_null($specialtodate)) || ($today >= strtotime($specialfromdate) && is_null($specialtodate)) || ($today <= strtotime($specialtodate) && is_null($specialfromdate)) || ($today >= strtotime($specialfromdate) && $today <= strtotime($specialtodate))) {
                        if ($_product_label_config['sale_label_percent']) {
                            $save_percent = 100 - round(($specialprice / $orgprice) * 100);
                            $product_label .= '<div class="product-label sale-label">' . '-' . $save_percent . '%' . '</div>';
                        } else {
                            $product_label .= '<div class="product-label sale-label">' . $_product_label_config['sale_label_text'] . '</div>';
                        }
                    }
                }
            }
            if ($_product_label_config['new_label']) {
                $now = date("Y-m-d");
                $newsFrom = substr($_product->getData('news_from_date'), 0, 10);
                $newsTo = substr($_product->getData('news_to_date'), 0, 10);

                if ($newsTo != '' || $newsFrom != '') {
                    if (($newsTo != '' && $newsFrom != '' && $now >= $newsFrom && $now <= $newsTo) || ($newsTo == '' && $now >= $newsFrom) || ($newsFrom == '' && $now <= $newsTo)) {
                        $product_label .= '<div class="product-label new-label">' . $_product_label_config['new_label_text'] . '</div>';
                    }
                }
            }
            if ($product_label) {
                echo '<div class="product-labels">' . $product_label . '</div>';
            }
            ?>
            <?php if ($product_type == 3 || $product_type == 5 || $product_type == 6 || $product_type == 7 || $product_type == 8 || $product_type == 9): ?>
                <div class="product-item-inner">
                    <div class="product actions product-item-actions">
                        <?php if (!$hideAddCart): ?>
                            <div class="actions-primary">
                                <?php if ($_product->isSaleable()): ?>
                                    <?php $postParams = $block->getAddToCartPostParams($_product); ?>
                                    <form data-role="tocart-form" action="<?php echo $postParams['action']; ?>"
                                          method="post">
                                        <input type="hidden" name="product"
                                               value="<?php echo $postParams['data']['product']; ?>">
                                        <input type="hidden" name="<?php echo Action::PARAM_NAME_URL_ENCODED; ?>"
                                               value="<?php echo $postParams['data'][Action::PARAM_NAME_URL_ENCODED]; ?>">
                                        <?php if (isset($_category_config['qty_field']) && $_category_config['qty_field']): ?>
                                            <div class="qty-box">
                                                <a href="javascript:void(0)" class="qtyminus"><i
                                                        class="porto-icon-minus"></i></a>
                                                <input type="text" name="qty" id="qty" maxlength="12"
                                                       value="<?php /* @escapeNotVerified */
                                                       echo $block->getProductDefaultQty() * 1 ?>"
                                                       title="<?php /* @escapeNotVerified */
                                                       echo __('Qty') ?>" class="input-text qty"
                                                       data-validate="<?php echo $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>"/>
                                                <a href="javascript:void(0)" class="qtyplus"><i
                                                        class="porto-icon-plus"></i></a>
                                            </div>
                                        <?php endif; ?>
                                        <?php echo $block->getBlockHtml('formkey') ?>
                                        <button type="submit"
                                                title="<?php echo $block->escapeHtml(__('Add to Cart')); ?>"
                                                class="action tocart primary">
                                            <span><?php echo __('Add to Cart') ?></span>
                                        </button>

                                        <?= $this->getLayout()
                                            ->createBlock(\MGS\BuyNow\Block\Product\ListProduct::class)
                                            ->setProduct($_product)
                                            ->setButtonTitle('Buy Now')
                                            ->setTemplate('MGS_BuyNow::buynow.phtml')
                                            ->toHtml();
                                        ?>
                                    </form>
                                <?php else: ?>
                                    <?php if ($_product->getIsSalable()): ?>
                                        <div class="stock available"><span><?php echo __('In stock') ?></span></div>
                                    <?php else: ?>
                                        <div class="stock unavailable"><span><?php echo __('Out of stock') ?></span>
                                        </div>
                                    <?php endif; ?>
                                <?php endif; ?>
                            </div>
                        <?php endif ?>

                        <?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow() && !$hideAddWishlist): ?>
                            <a href="#"
                               class="action towishlist actions-secondary"
                               title="<?php echo $block->escapeHtml(__('Add to Wish List')); ?>"
                               aria-label="<?php echo $block->escapeHtml(__('Add to Wish List')); ?>"
                               data-post='<?php echo $block->getAddToWishlistParams($_product); ?>'
                               data-action="add-to-wishlist"
                               role="button">
                                <span><?php echo __('Add to Wish List') ?></span>
                            </a>
                        <?php endif; ?>

                        <?php if (!$hideAddCompare): ?>
                            <?php
                            $compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare');
                            ?>
                            <a href="#"
                               class="action tocompare actions-secondary"
                               title="<?php echo $block->escapeHtml(__('Add to Compare')); ?>"
                               aria-label="<?php echo $block->escapeHtml(__('Add to Compare')); ?>"
                               data-post='<?php echo $compareHelper->getPostDataParams($_product); ?>'
                               role="button">
                                <span><?php echo __('Add to Compare') ?></span>
                            </a>
                        <?php endif; ?>
                    </div>
                </div>
            <?php endif; ?>

        </div>
        <div class="product details product-item-details">
            <?php
            $_productNameStripped = $block->stripTags($_product->getName(), null, true);
            ?>
            <?php if (!$hideName): ?>
                <strong class="product name product-item-name">
                    <a class="product-item-link"
                       href="<?php echo $_product->getProductUrl() ?>">
                        <?php echo $_helper->productAttribute($_product, $_product->getName(), 'name'); ?>
                    </a>
                </strong>
            <?php endif ?>
            <?php if (!$hideReview): ?>
                <?php
                $review_html = $block->getReviewsSummaryHtml($_product, $templateType);
                ?>
                <?php if ($review_html): ?>
                    <?php echo $block->getReviewsSummaryHtml($_product, $templateType); ?>
                <?php else: ?>
                    <div class="product-reviews-summary short">
                        <div class="rating-summary">
                            <span class="label"><span>Rating:</span></span>
                            <div class="rating-result" title="0%">
                                <span style="width:0"><span>0%</span></span>
                            </div>
                        </div>
                    </div>
                <?php endif; ?>
            <?php endif; ?>

            <?php if ($showDescription): ?>
                <div class="product description product-item-description">
                    <?php echo $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?>
                    <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productNameStripped ?>"
                       class="action more"><?php echo __('Learn More') ?></a>
                </div>
            <?php endif; ?>
            <?php if (!$hidePrice): ?>
                <?php echo $block->getProductPrice($_product) ?>
            <?php endif; ?>
            <?php echo $block->getProductDetailsHtml($_product); ?>

            <?php if ($product_type != 3 && $product_type != 5 && $product_type != 6 && $product_type != 7 && $product_type != 8 && $product_type != 9): ?>
                <div class="product-item-inner">
                    <div class="product actions product-item-actions">

                        <?php if (!$hideAddWishlist && $product_type != 4): ?>
                            <?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow()): ?>
                                <a href="#"
                                   class="action towishlist actions-secondary <?php if (isset($_category_config['qty_field']) && $_category_config['qty_field']): ?>has-qty<?php endif; ?>"
                                   title="<?php echo $block->escapeHtml(__('Add to Wish List')); ?>"
                                   aria-label="<?php echo $block->escapeHtml(__('Add to Wish List')); ?>"
                                   data-post='<?php echo $block->getAddToWishlistParams($_product); ?>'
                                   data-action="add-to-wishlist"
                                   role="button">
                                    <span><?php echo __('Add to Wish List') ?></span>
                                </a>
                            <?php endif; ?>
                        <?php endif; ?>

                        <?php if (!$hideAddCart): ?>
                            <div class="actions-primary">
                                <?php if ($_product->isSaleable()): ?>
                                    <?php $postParams = $block->getAddToCartPostParams($_product); ?>
                                    <form data-role="tocart-form" action="<?php echo $postParams['action']; ?>"
                                          method="post">
                                        <input type="hidden" name="product"
                                               value="<?php echo $postParams['data']['product']; ?>">
                                        <input type="hidden" name="<?php echo Action::PARAM_NAME_URL_ENCODED; ?>"
                                               value="<?php echo $postParams['data'][Action::PARAM_NAME_URL_ENCODED]; ?>">
                                        <?php if (isset($_category_config['qty_field']) && $_category_config['qty_field']): ?>
                                            <div class="qty-box">
                                                <a href="javascript:void(0)" class="qtyminus"><i
                                                        class="porto-icon-minus"></i></a>
                                                <input type="text" name="qty" id="qty" maxlength="12"
                                                       value="<?php /* @escapeNotVerified */
                                                       echo $block->getProductDefaultQty() * 1 ?>"
                                                       title="<?php /* @escapeNotVerified */
                                                       echo __('Qty') ?>" class="input-text qty"
                                                       data-validate="<?php echo $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>"/>
                                                <a href="javascript:void(0)" class="qtyplus"><i
                                                        class="porto-icon-plus"></i></a>
                                            </div>
                                        <?php endif; ?>
                                        <?php echo $block->getBlockHtml('formkey') ?>
                                        <button type="submit"
                                                title="<?php echo $block->escapeHtml(__('Add to Cart')); ?>"
                                                class="action tocart primary">
                                            <span><?php echo __('Add to Cart') ?></span>
                                        </button>
                                        <?= $this->getLayout()
                                            ->createBlock(\MGS\BuyNow\Block\Product\ListProduct::class)
                                            ->setProduct($_product)
                                            ->setButtonTitle('Buy Now')
                                            ->setTemplate('MGS_BuyNow::buynow.phtml')
                                            ->toHtml();
                                        ?>
                                    </form>
                                <?php else: ?>
                                    <?php if ($_product->getIsSalable()): ?>
                                        <div class="stock available"><span><?php echo __('In stock') ?></span></div>
                                    <?php else: ?>
                                        <div class="stock unavailable"><span><?php echo __('Out of stock') ?></span>
                                        </div>
                                    <?php endif; ?>
                                <?php endif; ?>
                            </div>
                        <?php endif ?>

                        <?php if (!$hideAddWishlist && $product_type == 4): ?>
                            <?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow()): ?>
                                <a href="#"
                                   class="action towishlist actions-secondary <?php if (isset($_category_config['qty_field']) && $_category_config['qty_field']): ?>has-qty<?php endif; ?>"
                                   title="<?php echo $block->escapeHtml(__('Add to Wish List')); ?>"
                                   aria-label="<?php echo $block->escapeHtml(__('Add to Wish List')); ?>"
                                   data-post='<?php echo $block->getAddToWishlistParams($_product); ?>'
                                   data-action="add-to-wishlist"
                                   role="button">
                                    <span><?php echo __('Add to Wish List') ?></span>
                                </a>
                            <?php endif; ?>
                        <?php endif; ?>


                        <?php if (!$hideAddCompare): ?>
                            <?php
                            $compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare');
                            ?>
                            <a href="#"
                               class="action tocompare actions-secondary <?php if (isset($_category_config['qty_field']) && $_category_config['qty_field']): ?>has-qty<?php endif; ?>"
                               title="<?php echo $block->escapeHtml(__('Add to Compare')); ?>"
                               aria-label="<?php echo $block->escapeHtml(__('Add to Compare')); ?>"
                               data-post='<?php echo $compareHelper->getPostDataParams($_product); ?>'
                               role="button">
                                <span><?php echo __('Add to Compare') ?></span>
                            </a>
                        <?php endif; ?>
                    </div>
                </div>
            <?php endif; ?>
        </div>
    </div>
<?php elseif ($generateHelper->getCurrentTheme() == "Sm/market"): ?>
    <?php
    $viewMode = 'grid';
    $image = 'category_page_grid';
    $templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
    $_product = $this->getLoadProduct($this->getProductId());
    $_productNameStripped = $block->stripTags($_product->getName(), null, true);
    $productImage = $block->getImage($_product, $image);
    $_helper = $this->helper('Magento\Catalog\Helper\Output');
    $builderHelper = $this->helper('MGS\Fbuilder\Helper\Data');
    $hideName = $this->getBlockData('hide_name');
    $hideReview = $this->getBlockData('hide_review');
    $hidePrice = $this->getBlockData('hide_price');
    $hideAddCart = $this->getBlockData('hide_addcart');
    $hideAddWishlist = $this->getBlockData('hide_addwishlist');
    $hideAddCompare = $this->getBlockData('hide_addcompare');
    $htmlStructure = $builderHelper->getStoreConfig('fbuilder/html_structure/product_grid');
    ?>
    <div class="product-item-info" data-container="product-grid">
        <div class="item-inner">
            <div class="box-image">
                <a href="<?php echo /* @escapeNotVerified */
                $_product->getProductUrl() ?>" class="product photo product-item-photo" tabindex="-1">
                    <?php echo $productImage->toHtml() ?>
                </a>
            </div>

            <div class="product details product-item-details box-info">
                <?php if ($hideName != 1): ?>
                    <h2 class="product name product-item-name product-name">
                        <a class="product-item-link"
                           href="<?php echo $_product->getProductUrl() ?>">
                            <?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?>
                        </a>
                    </h2>
                <?php endif ?>
                <?php if ($hideReview != 1): ?>
                    <?php echo $block->getReviewsSummaryHtml($_product, $templateType) ?>
                <?php endif ?>

                <?php if ($hidePrice != 1): ?>
                    <?php echo $block->getProductPrice($_product) ?>
                <?php endif ?>

                <?php echo $this->getLayout()->createBlock('Magento\Swatches\Block\Product\Renderer\Listing\Configurable')->setProduct($_product)->setTemplate('Magento_Swatches::product/listing/renderer.phtml')->toHtml() ?>

                <?php //echo $block->getProductDetailsHtml($_product) ?>

                <?php if (($hideAddCart != 1) || ($hideAddWishlist != 1) || ($hideAddCompare != 1)): ?>
                    <div class="bottom-action">

                        <?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow() && ($hideAddWishlist != 1)): ?>
                            <a href="#" class="action towishlist btn-action link-wishlist"
                               title="<?php echo $block->escapeHtmlAttr(__('Add to Wish List')) ?>"
                               aria-label="<?php echo $block->escapeHtmlAttr(__('Add to Wish List')) ?>"
                               data-post='<?php echo /* @noEscape */
                               $block->getAddToWishlistParams($block->getProduct()) ?>' data-action="add-to-wishlist"
                               role="button">
                                <span><?php echo $block->escapeHtml(__('Add to Wish List')) ?></span>
                            </a>
                        <?php endif ?>

                        <?php if ($hideAddCart != 1 && $_product->isSaleable()): ?>
                            <?php $postParams = $block->getAddToCartPostParams($_product); ?>
                            <form data-role="tocart-form" data-product-sku="<?php echo /* @NoEscape */
                            $_product->getSku() ?>" action="<?php echo /* @NoEscape */
                            $postParams['action'] ?>" method="post">
                                <input type="hidden" name="product" value="<?php echo /* @escapeNotVerified */
                                $postParams['data']['product'] ?>">
                                <input type="hidden" name="<?php echo /* @escapeNotVerified */
                                Action::PARAM_NAME_URL_ENCODED ?>" value="<?php echo /* @escapeNotVerified */
                                $postParams['data'][Action::PARAM_NAME_URL_ENCODED] ?>">
                                <?php echo $block->getBlockHtml('formkey') ?>
                                <button type="submit" title="<?php echo $block->escapeHtml(__('Add to Cart')) ?>"
                                        class="action tocart primary btn-action btn-cart">
                                    <span><?php echo /* @escapeNotVerified */
                                        __('Add to Cart') ?></span>
                                </button>
                            </form>
                        <?php endif ?>

                        <?php if ($hideAddCompare != 1): ?>
                            <?php $compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare'); ?>
                            <a href="#" class="action tocompare btn-action link-compare"
                               title="<?php echo $block->escapeHtml(__('Add to Compare')) ?>"
                               aria-label="<?php echo $block->escapeHtml(__('Add to Compare')) ?>"
                               data-post='<?php echo /* @escapeNotVerified */
                               $compareHelper->getPostDataParams($_product) ?>' role="button">
                                <span><?php echo /* @escapeNotVerified */
                                    __('Add to Compare') ?></span>
                            </a>
                        <?php endif ?>
                    </div>
                <?php endif ?>
            </div>
        </div>
    </div>
<?php else: ?>
    <?php
    $viewMode = 'grid';
    $image = 'category_page_grid';
    $templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
    $_product = $this->getLoadProduct($this->getProductId());
    $_productNameStripped = $block->stripTags($_product->getName(), null, true);
    $productImage = $block->getImage($_product, $image);
    $_helper = $this->helper('Magento\Catalog\Helper\Output');
    $builderHelper = $this->helper('MGS\Fbuilder\Helper\Data');
    $hideName = $this->getBlockData('hide_name');
    $hideReview = $this->getBlockData('hide_review');
    $hidePrice = $this->getBlockData('hide_price');
    $hideAddCart = $this->getBlockData('hide_addcart');
    $hideAddWishlist = $this->getBlockData('hide_addwishlist');
    $hideAddCompare = $this->getBlockData('hide_addcompare');
    $themeSettingConfig = $this->helper('MGS\ThemeSettings\Helper\Config');
    $_imagehelper = $this->helper('MGS\ThemeSettings\Helper\Image');
    $lazyLoad = $themeSettingConfig->getStoreConfig('themesettings/general/lazy_load');
    $useSlider = $this->getBlockData('use_slider');
    $htmlStructure = $builderHelper->getStoreConfig('fbuilder/html_structure/product_grid');
    $defaultTabs = $builderHelper->getStoreConfig('themesettings/product_image_dimention/default_tabs');
    $baseImage = $baseImageHover = $this->getViewFileUrl('MGS_ThemeSettings::images/blank.png');
    $baseImageHover = $this->getViewFileUrl('MGS_ThemeSettings::images/blank.png');
    ?>
    <div class="product-item-info" data-container="product-grid">
        <div class="product-top">
            <?php // Product Image ?>
            <?php
            $ratio = $defaultTabs ? $defaultTabs : null;
            $size = $themeSettingConfig->getImageSize($ratio);
            $padding = $themeSettingConfig->getImagePadding();
            $productRatio = $themeSettingConfig->getProductRatio($ratio);
            if ($productRatio == 1) {
                $padding = '100%';
            }
            ?>

            <?php
            $productImage = $_imagehelper->init($_product, $image)->setImageFile($_product->getData('small_image'))->resize($size['width'], $size['height'])->getUrl();
            $productImageHover = $_imagehelper->init($_product, $image)->setImageFile($_product->getData('thumbnail'))->resize($size['width'], $size['height'])->getUrl();
            ?>
            <?php if(!$lazyLoad): ?>
                <?php $baseImage = $productImage ?>
                <?php $baseImageHover = $productImageHover ?>
            <?php endif ?>

            <!-- Product Image-->
            <a href="<?php echo $_product->getProductUrl() ?>"
               class="product photo product-item-photo <?php if ((basename($_product->getData('thumbnail') ?? '') != 'no_selection') && (basename($_product->getData('thumbnail') ?? '') != basename($_product->getData('small_image') ?? ''))): ?> has-hover-image<?php endif ?>"
               style="padding-bottom: <?php echo $padding ?>;" tabindex="-1">

                <img src="<?php echo $baseImage ?>" alt="<?php echo $_productNameStripped ?>"
                     class="img-responsive product-image-photo img-thumbnail <?php if ($lazyLoad): ?>arrow-lazy<?php endif ?>"
                     loading="lazy"
                     data-src="<?php echo $productImage ?>"/>

                <?php if (basename($_product->getData('thumbnail') ?? '') != 'no_selection'): ?>
                    <?php if (basename($_product->getData('thumbnail') ?? '') != basename($_product->getData('small_image') ?? '')): ?>
                        <img src="<?php echo $baseImageHover; ?>" alt="<?php echo $_productNameStripped ?>"
                             class="img-responsive img-hover-show <?php if ($lazyLoad): ?>arrow-lazy<?php endif ?>"
                             loading="lazy"
                             data-src="<?php echo $productImageHover; ?>"/>
                    <?php endif ?>
                <?php endif ?>
                <span class="product-image-photo"></span>
            </a>

            <!-- Product label-->
            <?php echo $themeSettingConfig->getProductLabel($_product); ?>

            <!-- Product actions-->
            <ul class="actions-link actions-secondary">
                <?php if ($hideAddCompare != 1): ?>
                    <?php $compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare'); ?>
                    <li>
                        <button class="action tocompare"
                                title="<?php echo $block->escapeHtml(__('Add to Compare')); ?>"
                                data-title="<?php echo __('Add to Compare') ?>"
                                aria-label="<?php echo $block->escapeHtml(__('Add to Compare')); ?>"
                                data-post='<?php /* @escapeNotVerified */
                                echo $compareHelper->getPostDataParams($_product); ?>'
                                role="button">
                            <i class="pe-7s-graph3"></i>
                        </button>
                    </li>
                <?php endif ?>

                <?php if (($hideAddWishlist != 1)): ?>
                    <?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow() && ($hideAddWishlist != 1)): ?>
                        <li>
                            <button class="action towishlist"
                                    title="<?php echo $block->escapeHtml(__('Add to Wish List')); ?>"
                                    data-title="<?php echo __('Add to Wish List') ?>"
                                    aria-label="<?php echo $block->escapeHtml(__('Add to Wish List')); ?>"
                                    data-post='<?php /* @escapeNotVerified */
                                    echo $block->getAddToWishlistParams($_product); ?>'
                                    data-action="add-to-wishlist"
                                    role="button">
                                <i class="pe-7s-like"></i>
                            </button>
                        </li>
                    <?php endif ?>
                <?php endif ?>
                <li>
                    <a data-productid="<?= $_product->getId(); ?>" class="action quickview" aria-label="Quickview" title="Quickview" href="<?= $this->getUrl().'aquickview/index/index/catalog/product/id/'.$_product->getId(); ?>">
                        <span><?= __('Quickview'); ?></span>
                    </a>
                </li>
            </ul>
            <div class="action-mobile">
                <?php if ($hideAddCart != 1): ?>
                    <?php if ($_product->isSaleable()): ?>
                        <?php $postParams = $block->getAddToCartPostParams($_product); ?>
                        <form data-role="tocart-form" data-product-sku="<?php echo /* @NoEscape */
                        $_product->getSku() ?>" action="<?php echo /* @NoEscape */
                        $postParams['action'] ?>" method="post">
                            <input type="hidden" name="product" value="<?php echo /* @escapeNotVerified */
                            $postParams['data']['product'] ?>">
                            <input type="hidden" name="<?php echo /* @escapeNotVerified */
                            Action::PARAM_NAME_URL_ENCODED ?>" value="<?php echo /* @escapeNotVerified */
                            $postParams['data'][Action::PARAM_NAME_URL_ENCODED] ?>">
                            <?php echo $block->getBlockHtml('formkey') ?>
                            <?php if($_product->getTypeId() == 'simple'): ?>
                                <button type="submit"
                                        title="<?= $block->escapeHtmlAttr(__('Add to Cart')) ?>"
                                        class="action tocart btn-cart primary">
                                    <span class="icon pe-7s-shopbag"></span>
                                    <span class="text"><?= /* @escapeNotVerified */
                                        __('Add to Cart') ?></span>
                                </button>
                            <?php else: ?>
                                <button type="submit"
                                        title="<?= $block->escapeHtmlAttr(__('Add to Cart')) ?>"
                                        class="action tocart btn-cart primary"
                                        onclick="window.location.href = '<?php echo $block->getProductUrl($_product)?>'">
                                    <span class="icon pe-7s-shopbag"></span>
                                    <span class="text"><?= /* @escapeNotVerified */
                                        __('Add to Cart') ?></span>
                                </button>
                            <?php endif; ?>
                            <?php  ?>
                            <?php
                            if ($callHelper->getConfig('buynow/general/enable_widget_buider')){
                                echo  $this->getLayout()
                                    ->createBlock(\MGS\BuyNow\Block\Product\ListProduct::class)
                                    ->setProduct($_product)
                                    ->setButtonTitle('Buy Now')
                                    ->setTemplate('MGS_BuyNow::buynow.phtml')
                                    ->toHtml();
                            }

                            ?>
                        </form>
                    <?php endif; ?>
                <?php endif ?>
            </div>

        </div>
        <div class="product details product-item-details">
            <?php if ($hideName != 1): ?>
                <h5 class="product name product-item-name">
                    <a class="product-item-link"
                       href="<?php echo $_product->getProductUrl() ?>">
                        <?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?>
                    </a>
                </h5>
            <?php endif ?>
            <?php if ($hideReview != 1): ?>
                <?php echo $block->getReviewsSummaryHtml($_product, $templateType) ?>
            <?php endif ?>

            <?php if ($hidePrice != 1): ?>

                <?php if (!$callHelper->getConfig('mgscallforprice/general/isenabled')) : ?>
                    <?= /* @noEscape */$priceHtml ?>
                <?php else: ?>
                    <?php if ($callHelper->getConfig('mgscallforprice/general/choosetype') == '1') : ?>
                        <a href="tel: <?php echo $callHelper->getConfig('mgscallforprice/general/vendorphonenumber') ?>"
                           class="action primary tocart callforprice"><span><i
                                    class="pe-7s-call"></i><?php echo $callHelper->getConfig('mgscallforprice/general/callforpricetextbutton') ?></span></a>
                    <?php elseif ($callHelper->getConfig('mgscallforprice/general/choosetype') == '2'): ?>
                        <button type="button" class="action primary tocart request-quote-<?php echo
                        $block->getProduct()->getId(); ?>">
                            <span><?php echo $callHelper->getConfig('mgscallforprice/general/requestquote') ?></span></button>
                        <form class="form quote-request test" action="<?php echo $test; ?>"
                              id="quote-request-form-<?php echo $block->getProduct()->getId() ?>" method="post"
                              data-hasrequired="<?= $block->escapeHtmlAttr(__('* Required Fields')) ?>"
                              data-mage-init='{"validation":{}}' style="display: none;">
                            <fieldset class="fieldset">
                                <legend class="legend"><span><?= $block->escapeHtml(__('Write Us')) ?></span></legend>
                                <br/>
                                <div class="field note no-label">
                                    <?= $block->escapeHtml(__('Jot us a note and we’ll get back to you as quickly as possible.')) ?>
                                </div>
                                <div class="field name required">
                                    <label class="label" for="name"><span><?= $block->escapeHtml(__('Name')) ?></span></label>
                                    <div class="control">
                                        <input name="name" id="name-<?php echo $block->getProduct()->getId(); ?>"
                                               title="<?= $block->escapeHtmlAttr(__('Name')) ?>" value="" class="input-text"
                                               type="text" data-validate="{required:true}"/>
                                    </div>
                                </div>
                                <div class="field telephone">
                                    <label class="label"
                                           for="telephone"><span><?= $block->escapeHtml(__('Phone Number')) ?></span></label>
                                    <div class="control">
                                        <input name="telephone" id="telephone-<?php echo $_product->getId(); ?>"
                                               title="<?= $block->escapeHtmlAttr(__('Phone Number')) ?>" value=""
                                               class="input-text" type="text"/>
                                    </div>
                                </div>
                                <div class="field email required">
                                    <label class="label" for="email"><span><?= $block->escapeHtml(__('Email')) ?></span></label>
                                    <div class="control">
                                        <input name="email" id="email-<?php echo $_product->getId(); ?>"
                                               title="<?= $block->escapeHtmlAttr(__('Email')) ?>" value=""
                                               class="input-text" type="email" data-validate="{required:true, 'validate-email':true}"/>
                                    </div>
                                </div>

                                <div class="field productId">
                                    <label class="label productId"
                                           for="productId"><span><?= $block->escapeHtml(__('Product ID')) ?></span></label>
                                    <div class="control">
                                        <input name="productId" id="productId-<?php echo $_product->getId(); ?>"
                                               title="<?= $block->escapeHtmlAttr(__('Product ID')) ?>"
                                               value="<?php echo $_product->getId(); ?>" class="input-text" type="hidden"
                                               readonly="readonly"/>
                                    </div>
                                </div>
                                <div class="field productSku">
                                    <label class="label productSku"
                                           for="productSku"><span><?= $block->escapeHtml(__('Product SKU')) ?></span></label>
                                    <div class="control">
                                        <input name="productSku" id="productSku-<?php echo $_product->getId(); ?>"
                                               title="<?= $block->escapeHtmlAttr(__('Product SKU')) ?>"
                                               value="<?php echo $_product->getSku(); ?>" class="input-text" type="hidden"
                                               readonly="readonly"/>
                                    </div>
                                </div>
                                <div class="field productName">
                                    <label class="label productName"
                                           for="productName"><span><?= $block->escapeHtml(__('Product Name')) ?></span></label>
                                    <div class="control">
                                        <input name="productName" id="productName-<?php echo $_product->getId(); ?>"
                                               title="<?= $block->escapeHtmlAttr(__('Product Name')) ?>"
                                               value="<?php echo $_product->getName(); ?>" class="input-text" type="hidden"
                                               readonly="readonly"/>
                                    </div>
                                </div>
                                <div class="field comment">
                                    <label class="label" for="comment">
                                        <span><?= $block->escapeHtml(__('Comment')) ?></span>
                                    </label>
                                    <div class="control">
															<textarea name="comment"
                                                                      id="comment-<?php echo $_product->getId(); ?>"
                                                                      title="<?= $block->escapeHtmlAttr(__('Comment')) ?>"
                                                                      class="input-text" cols="5" rows="3"></textarea>
                                    </div>
                                </div>
                                <?= $block->getChildHtml('form.additional.info') ?>
                            </fieldset>
                            <div class="actions-toolbar">
                                <div class="primary">
                                    <input type="hidden" name="hideit" id="hideit" value=""/>
                                    <button type="submit" title="<?= $block->escapeHtmlAttr(__('Submit')) ?>"
                                            class="action submit primary">
                                        <span><?= $block->escapeHtml(__('Submit')) ?></span>
                                    </button>
                                </div>
                            </div>
                        </form>
                    <?php else: ?>
                        <?php if (!$customerSession->isLoggedIn()):?>
                            <a href="<?= $UrlInterface->getUrl('customer/account/login') ?>"
                               alt="Login to see price" class="logintoseeprice">
                                <span><?= __('Login to see price') ?></span>
                            </a>
                        <?php else: ?>
                            <?= /* @noEscape */$priceHtml ?>
                        <?php endif;?>
                    <?php endif; ?>
                <?php endif; ?>
            <?php endif ?>

            <?php echo $this->getLayout()->createBlock('Magento\Swatches\Block\Product\Renderer\Listing\Configurable')->setProduct($_product)->setTemplate('MGS_Fbuilder::products/swatches/renderer.phtml')->toHtml() ?>
        </div>
    </div>
<?php endif; ?>
<script type="text/javascript">
    require(["jquery", "Magento_Ui/js/modal/modal"],function($, modal) {
			var options = {
            type: 'popup', // popup or slide
			responsive: true, // true = on smaller screens the modal slides in from the right
			modalClass: 'see-detail-modal',
			};
			$(".request-quote-<?php echo $block->getProduct()->getId() ?>").on('click',function() {
				$('#quote-request-form-<?php echo $block->getProduct()->getId() ?>').modal(options).modal('openModal');
			});

    });
     document.addEventListener('DOMContentLoaded', () => {

             require([
        'jquery',
        'Magento_Ui/js/modal/alert',
        'Magento_Customer/js/customer-data',
        'Magento_Catalog/js/catalog-add-to-cart'
        ], function($, alert, customerData) {
        $(document).ready(function() {
            $('.mageprince-buy-now-btn').on('click', function(event) {
                event.preventDefault();
                var form = $('#product_addtocart_form');
                var formData = form.serializeArray();
                formData.push({name: 'isAjax', value: 1});

                $.ajax({
                    url: form.attr('action'),
                    data: $.param(formData),
                    type: 'post',
                    dataType: 'json',
                    success: function(response) {
                        if (response.backUrl) {
                            window.location.href = response.backUrl;
                        } else if (response.redirectUrl) {
                            window.location.href = response.redirectUrl;
                        } else {
                            window.location.href = '/checkout';
                        }
                    },
                    error: function() {
                        alert({
                            content: 'An error occurred while processing your request. Please try again later.'
                        });
                    }
                });
            });
        });
    });

     })

</script>
