<?php

namespace Magetop\Agency\Block\Adminhtml\Product\Edit\Tab;

class Details extends \Magento\Backend\Block\Template
{
    protected $_coreRegistry = null;
    /**
     * @param \Magento\Backend\Block\Template\Context $context
     * @param \Magento\Backend\Helper\Data $backendHelper
     * @param \Magento\Framework\Registry $coreRegistry
     * @param array $data
     */
    public function __construct(
        \Magento\Backend\Block\Template\Context $context,
        \Magento\Backend\Helper\Data $backendHelper,
        \Magento\Framework\Registry $coreRegistry,
        \Magetop\Agency\Helper\Data $agencyHelper,
        array $data = []
    ) {
        $this->_coreRegistry = $coreRegistry;
        $this->_agencyHelper = $agencyHelper;
        parent::__construct($context, $data);
    }

    public function getDetails()
    {
        return $this->_coreRegistry->registry('assign_product');
    }

    public function getProduct($productId)
    {
        return $this->_agencyHelper->getProduct($productId);
    }

    public function getAgencyDetails($sellerId, $productId = 0)
    {
        $admin = "Admin";
        $details = [];
        if ($productId > 0) {
            $sellerId = $this->_agencyHelper->getAgencyIdByProductId($productId);
        }
        if ($sellerId > 0) {
            $sellerInfo = $this->_agencyHelper->getAgencyInfo($sellerId);
            $shopTitle = $sellerInfo->getShopTitle();
            if (!$shopTitle) {
                $shopTitle = $sellerInfo->getShopUrl();
            }
            $details['shop_title'] = $shopTitle;
            $details['agency_id'] = $sellerId;
        } else {
            $details['shop_title'] = $admin;
            $details['agency_id'] = 0;
        }
        return $details;
    }

    public function getBaseCurrencyCode()
    {
        return $this->_agencyHelper->getBaseCurrencyCode();
    }

    public function getHelper()
    {
        return $this->_agencyHelper;
    }
}
