<?php
/**
 * Magetop
 *
 * @category  Magetop Extensions
 * @package   Magetop_Quotesystem
 * @author    Magetop Developer
 * @copyright Copyright (c) Magetop (https://www.magetop.com)
 * @license   https://www.magetop.com/license.html
 */

namespace Magetop\Quotesystem\Plugin\Catalog\Block\Product\View\Options;

class AbstractOptions
{

    /**
     * @var \Magetop\Quotesystem\Helper\Data
     */
    protected $quoteHelper;

    /**
     * @param \Magetop\Quotesystem\Helper\Data $quoteHelper
     */
    public function __construct(
        \Magetop\Quotesystem\Helper\Data $quoteHelper
    ) {
        $this->quoteHelper = $quoteHelper;
    }
    
    /**
     * Plugin to update format price string
     *
     * @param  \Magento\Catalog\Block\Product\View\Options\AbstractOptions $subject
     * @param  [string]                                                    $result
     * @return string
     */
    public function afterGetFormatedPrice(
        \Magento\Catalog\Block\Product\View\Options\AbstractOptions $subject,
        $result
    ) {
        $showPrice = (int)$this->quoteHelper->getConfigShowPrice();
        $product = $subject->getProduct();
        $quoteStatus = $product->getQuoteStatus();
        if (!$showPrice && ($quoteStatus == 1)) {
            return '';
        }
        return $result;
    }
}
