<?php
/**
 * Webkul Software.
 *
 * @category   Webkul
 * @package    Webkul_Agorae
 * @author     Webkul Software Private Limited
 * @copyright  Copyright (c) Webkul Software Private Limited (https://webkul.com)
 * @license    https://store.webkul.com/license.html
 */

// @codingStandardsIgnoreFile

/**
 * Display seller details at product view page
 *
 * @var $block \Webkul\Agorae\Block\Sellerblock
 */
$viewModel = $block->getData('viewModel');
$moduleManager = $viewModel->getModuleManager();
if ($moduleManager->isOutputEnabled('Webkul_Marketplace')) {
$helper = $this->helper('Webkul\Agorae\Helper\Data');
$mpHelper = $this->helper('Webkul\Marketplace\Helper\Data');
$marketplaceModuleEnabled = $helper->isModuleEnabled('Webkul_Marketplace');
$marketplaceModuleOutputEnabled = $helper->isOutputEnabled('Webkul_Marketplace');

if($marketplaceModuleEnabled && $marketplaceModuleOutputEnabled && $mpHelper->getSellerProfileDisplayFlag()) {
    $_product = $block->getProduct();
    $sellerData = $block->getSellerDetailsByProductId($_product->getId());
?>
    <div class="block block-list block-viewed">
        <div class="wk-agorae-seller-block-container">
            <div class="block-title">
                <div class="wk-agorae-seller-block-head">
                    <strong>
                        <span><?php echo __('About Seller') ?></span>
                    </strong>
                </div>
            </div>
            <div class="block-content">
                <div class="wk-agorae-seller-block-body">
                    <div class="seller-info">
                        <?php
                        if($sellerData) {
                            $ratings = $mpHelper->getSelleRating($sellerData->getSellerId());
                            if($sellerData->getLogoPic()) {
                                $logoPic = $sellerData->getLogoPic();
                            }else{
                                $logoPic = 'noimage.png';
                            } ?>
                            <div class="sd-left">
                                <a href="<?php echo $mpHelper->getRewriteUrl(
                                        'marketplace/seller/collection/shop/'
                                        .$sellerData->getShopUrl()); ?>">
                                    <div class="sellerlogo">
                                        <img src="<?php echo $helper->getMediaUrl()
                                                    .'avatar/'
                                                    .$logoPic; ?>" />
                                    </div>
                                </a>
                            </div>
                            <div class="sd-right">
                                <div class="shoptitle">
                                    <a href="<?php echo $mpHelper->getRewriteUrl(
                                            'marketplace/seller/collection/shop/'
                                            .$sellerData->getShopUrl()); ?>"
                                        title="<?php echo $sellerData->getShopTitle(); ?>">
                                        <?php
                                        if($sellerData->getShopTitle()){
                                            echo substr($sellerData->getShopTitle(),0,20);
                                            if(strlen($sellerData->getShopTitle()) > 20) {
                                                echo " ...";
                                            }
                                        }else{
                                            echo substr(
                                                $helper->getCustomerData(
                                                    $sellerData->getSellerId()
                                                )->getName().__("'s shop"),
                                                0,
                                                20
                                            );
                                            if(strlen($helper->getCustomerData($sellerData->getSellerId())->getName().__("'s shop")) > 20) {
                                                echo " ...";
                                            }
                                        }
                                        ?>
                                    </a>
                                </div>
                                <?php
                                if($sellerData->getCountryPic()){ ?>
                                    <div class="sellercountry">
                                        <i><?php echo __('from ') ?></i>
                                        <span>
                                            <?php echo $sellerData->getCountryPic(); ?>
                                        </span>
                                    </div>
                                <?php
                                } ?>
                                <div class="ratings">
                                    <div class="rating-box">
                                        <div style="width:<?php echo (($ratings*100)/5); ?>%"
                                            class="rating">
                                        </div>
                                    </div>
                                </div>
                            </div>
                        <?php
                        } else { ?>
                            <strong><?php echo __('Admin Product') ?></strong>
                        <?php
                        } ?>
                    </div>
                    <?php if($sellerData) {
                        $addFavouriteSellerBlock = $block->getLayout()->createBlock(
                            'Webkul\Agorae\Block\AddFavouriteSeller'
                        );
                        $favouriteSellerLink = $addFavouriteSellerBlock->getFavouriteSellerLink(); ?>
                        <div class="wk-agorae-seller-block-foot">
                            <div class="btn btn-follow">
                                <div class="wk_profile_links">
                                    <?php if($addFavouriteSellerBlock->isSellerFollowed()) : ?>
                                        <div class="btn_primary">
                                            <?php /* @escapeNotVerified */ echo __('Followed')?>
                                        </div>
                                    <?php else: ?>
                                        <a href="<?php if($favouriteSellerLink) {
                                                echo $favouriteSellerLink;
                                            } ?>"
                                            class="btn_primary" >
                                            <?php /* @escapeNotVerified */ echo __('Follow')?>
                                        </a>
                                    <?php endif; ?>
                                </div>
                            </div>
                            <a href="<?php echo $mpHelper->getRewriteUrl(
                                        'marketplace/seller/profile/shop/'
                                        .$sellerData->getShopUrl()) ?>"
                                title="Seller Profile">
                                <div class="btn btn-profile">
                                    <?php echo __('Seller Profile')?>
                                </div>
                            </a>
                        </div>
                    <?php
                    } ?>
                </div>
            </div>
        </div>
    </div>
<?php
}
} ?>
