<?php


namespace Magetop\Advancepreview\Block;

use Magento\Framework\View\Element\Template;

/**
 * Class AdvancePreviewAbstract
 * @package Magetop\Advancepreview\Block
 */
class AdvancePreviewAbstract extends Template
{
    /**
     * @var \Magento\Framework\Pricing\Helper\Data
     */
    protected $priceHelper;
    protected $filesystem;
    /**
     * @var \Magetop\Advancepreview\Helper\Data
     */
    protected $advancePreviewHelper;

    /**
     * AdvancePreviewAbstract constructor.
     * @param Template\Context $context
     * @param \Magento\Framework\Pricing\Helper\Data $priceHelper
     * @param \Magetop\Advancepreview\Helper\Data $advancePreviewHelper
     * @param array $data
     */
    public function __construct(
        Template\Context $context,
        \Magento\Framework\Pricing\Helper\Data $priceHelper,
        \Magetop\Advancepreview\Helper\Data $advancePreviewHelper,
        array $data = []
    )
    {
        parent::__construct($context, $data);
        $this->priceHelper = $priceHelper;
        $this->advancePreviewHelper = $advancePreviewHelper;
    }


    /**
     * @param string $url
     * @return string
     */
    function formatAjaxUrl($url = '') {
        return $this->advancePreviewHelper->formatOpdAjaxUrl($url);
    }

    /**
     * @param array $items
     * @return string
     */
    function convertJsonEncode($items = array()) {
        return $this->advancePreviewHelper->convertOpdJsonEncode($items);
    }

    /**
     * @param string $json
     * @return array|mixed
     */
    function convertJsonDecode($json = '') {
        return $this->advancePreviewHelper->convertOpdJsonDecode($json);
    }

    /**
     * @param $price
     * @return float|string
     */
    function convertNumberToPrice($price) {
        return $this->priceHelper->currency($price,true,false);
    }

    /**
     * @return string
     */
    function getMediaUrl() {
        $mediaUrl = '';
        try {
            $mediaUrl = $this ->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA );
        }
        catch (\Exception $exception) {

        }
        return $mediaUrl;
    }
    public function getMediaPath() {
        return $this->getMediaDirectory()->getAbsolutePath();
    }
    /**
     * @return int
     */
    function getOpdStoreId() {
        $storeId = 0;
        try{
            $storeId = $this->_storeManager->getStore()->getId();
        }
        catch (\Exception $exception) {

        }
        return $storeId;
    }


    /**
     * @return \Magetop\Advancepreview\Helper\Data
     */
    function getOpdHelper() {
        return $this->advancePreviewHelper;
    }

    /**
     * @return string
     */
    function getOpdStaticImages() {
        $url = '';
        try {
            $url = $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_STATIC);
        }
        catch (\Exception $exception) {

        }
        return $url;

    }
}
