<?php
/**
 * Webkul Software.
 *
 * @category  Webkul
 * @package   Webkul_Marketplace
 * @author    Webkul
 * @copyright Copyright (c) Webkul Software Private Limited (https://webkul.com)
 * @license   https://store.webkul.com/license.html
 */
$helper = $block->getMpHelper();
if (!$helper->getIsSeparatePanel()) {
    $isPartner= $helper->isSeller();
    $sellerId= $helper->getCustomerId();
    $magentoCurrentUrl = $block->escapeUrl($block->getCurrentUrl());
    $allow_pro_type=$helper->getAllowedProductType();
    $isSellerGroup = $helper->isSellerGroupModuleInstalled();
    $productNotificationCount = $block->getProductNotificationCount();
    $orderNotificationCount = $block->getOrderNotificationCount();
    $transactionCount = $block->getTransactionNotificationCount();
    ?>
    <style type="text/css">
        @media only screen and (max-width: 767px){

            .block-collapsible-nav.wk-mp-main{
                top: 20px;
            }
        }
    </style>
    <div class="block account-nav block-collapsible-nav wk-mp-main">
        <div class="title block-collapsible-nav-title" data-mage-init='{"toggleAdvanced": {"toggleContainers": "#block-collapsible-nav-seller", "selectorsToggleClass": "active"}}'>
            <strong><?= /* @noEscape */__('Marketplace'); ?></strong>
        </div>
        <div class="content block-collapsible-nav-content" id="block-collapsible-nav-seller">
            <nav class="account-nav">
                <ul class="nav items">
                    <?php
                    if ($isPartner) { ?>
                        <?php if (($isSellerGroup && $helper->isAllowedAction('marketplace/account/dashboard')) || !$isSellerGroup) { ?>
                            <li class="nav item <?= /* @noEscape */ strpos($magentoCurrentUrl, 'marketplace/account/dashboard')? "current":"";?>">
                                <?php
                                if (strpos($magentoCurrentUrl, 'marketplace/account/dashboard') !== false) { ?>      
                                    <strong><?=/* @noEscape */ __('Marketplace Dashboard') ?></strong>              
                                    <?php
                                } else { ?>        
                                    <a href="<?= $block->escapeUrl($block->getUrl('marketplace/account/dashboard', ['_secure' => $this->getRequest()->isSecure()])); ?>">
                                        <?= /* @noEscape */ __('Marketplace Dashboard') ?>
                                    </a>
                                    <?php
                                } ?>
                            </li>
                            <?php
                        } ?>
                        <?php if (($isSellerGroup && $helper->isAllowedAction('marketplace/account/editprofile')) || !$isSellerGroup) { ?>
                            <?php if ($helper->getSellerProfileDisplayFlag()) { ?>
                                <li class="nav item <?= /* @noEscape */ strpos($magentoCurrentUrl,'marketplace/account/editprofile')? "current":"";?>">     
                                    <?php if (strpos($magentoCurrentUrl, 'marketplace/account/editprofile') !== false) { ?>
                                        <strong><?= /* @noEscape */ __('Seller Profile') ?></strong>
                                        <?php
                                    } else { ?>
                                        <a href="<?= $block->escapeUrl($block->getUrl('marketplace/account/editprofile', ['_secure' => $this->getRequest()->isSecure()])); ?>">
                                            <?= /* @noEscape */ __('Seller Profile') ?>
                                        </a>
                                        <?php
                                    } ?>
                                </li>
                            <?php } ?>
                        <?php } ?>
                        <?php if (($isSellerGroup && $helper->isAllowedAction('marketplace/product_attribute/new')) || !$isSellerGroup) {
                            if (strpos($allow_pro_type, 'configurable') !== false) { ?>
                                <li class="nav item <?= /* @noEscape */ strpos($magentoCurrentUrl, 'marketplace/product_attribute/new')? "current":"";?>">       
                                <?php if (strpos($magentoCurrentUrl, 'marketplace/product_attribute/new') !== false) { ?>
                                    <strong><?= /* @noEscape */ __('Create Attribute') ?></strong>  
                                    <?php } else { ?>        
                                        <a href="<?= $block->escapeUrl($block->getUrl('marketplace/product_attribute/new', ['_secure' => $this->getRequest()->isSecure()])); ?>">
                                            <?= /* @noEscape */ __('Create Attribute') ?></a>
                                    <?php } ?>              
                                </li>
                                <?php
                            }
                        } ?>
                        <?php if (($isSellerGroup && $helper->isAllowedAction('marketplace/product/add')) || !$isSellerGroup) { ?>
                            <li class="nav item <?= /* @noEscape */ (strpos($magentoCurrentUrl, 'marketplace/product/add')||strpos($magentoCurrentUrl, 'marketplace/product/create'))? "current":"";?>">           
                                <?php
                                if (strpos($magentoCurrentUrl, 'marketplace/product/add') !== false || strpos($magentoCurrentUrl, 'marketplace/product/create') !== false) { ?>
                                    <strong><?= /* @noEscape */ __('New Products') ?></strong>  
                                    <?php
                                } else { ?>                    
                                    <a href="<?= $block->escapeUrl($block->getUrl('marketplace/product/create', ['_secure' => $this->getRequest()->isSecure()])); ?>">
                                        <?= /* @noEscape */ __('New Products') ?>
                                    </a>
                                    <?php
                                } ?>
                            </li>
                        <?php } ?>
                        <?php if (($isSellerGroup && $helper->isAllowedAction('marketplace/product/productlist')) || !$isSellerGroup) { ?>
                            <li class="nav item notification-link <?= /* @noEscape */ strpos($magentoCurrentUrl, 'marketplace/product/productlist')? "current":"";?>">         
                            <?php if (strpos($magentoCurrentUrl, 'marketplace/product/productlist') !== false) { ?>
                                <strong><?= /* @noEscape */ __('My Products List') ?></strong>  
                                <?php } else { ?>
                                    <a href="<?= $block->escapeUrl($block->getUrl('marketplace/product/productlist', ['_secure' => $this->getRequest()->isSecure()])); ?>">
                                        <?= /* @noEscape */ __('My Products List') ?>
                                    </a>
                                    <!-- Product Notification -->
                                    <?php if ($block->getProductCollection()->getSize()) { ?>
                                    <div class="notification-block">
                                        <a href="" class="notifications-action marketplace-dropdown">
                                            <img height="20" width="20" src="<?= $block->escapeUrl($block->getViewFileUrl('Webkul_Marketplace::images/icons_notifications.png')); ?>" class="notifications-img" />
                                            <?php if ($productNotificationCount > 5): ?>
                                                <span class="notification-count">5+</span>
                                            <?php else: ?>
                                                <span class="notification-count"><?= $block->escapeHtml($productNotificationCount); ?></span>
                                            <?php endif; ?>
                                        </a>
                                        <ul class="marketplace-dropdown-menu">
                                            <span class="notify-point"></span>
                                            <?php
                                            $productDisplayCount = 1;
                                            foreach ($block->getProductCollection() as $product):
                                                if ($productDisplayCount <= 5):
                                                    ?>
                                                    <li class="notifications-entry">
                                                        <strong class="notifications-entry-title">
                                                            <?= $block->escapeHtml($block->getProductNotificationTitle($product->getMageproductId(), $product->getStatus())); ?> 
                                                        </strong>
                                                        <p class="notifications-entry-description _cutted">
                                                            <a href="<?= $block->escapeUrl($block->getUrl('marketplace/product/productlist', ['_secure' => $this->getRequest()->isSecure()]))?>" class="notifications-entry-description-start">
                                                                <span >
                                                                    <?= /* @noEscape */ $block->getProductNotificationDesc($product->getMageproductId(), $product->getStatus()); ?>
                                                                </span>
                                                            </a>
                                                        </p>
                                                        <time class="notifications-entry-time">
                                                            <?= /* @noEscape */ $block->getProductNotifyDateTime($product->getUpdatedAt()); ?>
                                                        </time>
                                                    </li>
                                                    <?php  $productDisplayCount++;
                                                endif;
                                            endforeach; ?>
                                            <?php
                                            if ($productDisplayCount > 5):
                                                ?>    
                                                    <li class="notifications-entry notifications-entry-last">
                                                        <a href="<?= $block->escapeUrl($block->getUrl('marketplace/product/productlist', ['_secure' => $this->getRequest()->isSecure()])); ?>">
                                                            <?= /* @noEscape */ __('Click here to view product list'); ?>
                                                        </a>
                                                    </li>
                                            <?php endif; ?>
                                        </ul>
                                    </div>
                                    <?php } ?>
                                    <!-- Product Notification End -->
                                <?php } ?>
                            </li>
                        <?php } ?>
                        <?php if (($isSellerGroup && $helper->isAllowedAction('marketplace/transaction/history')) || !$isSellerGroup) { ?>
                            <li class="nav item notification-link <?= /* @noEscape */ strpos($magentoCurrentUrl, 'marketplace/transaction/history')? "current":"";?>">
                                <?php
                                if (strpos($magentoCurrentUrl, 'marketplace/transaction/history') !== false) { ?>
                                    <strong><?= /* @noEscape */ __('My Transaction List') ?></strong>
                                    <?php
                                } else { ?>
                                    <a href="<?= $block->escapeUrl($block->getUrl('marketplace/transaction/history', ['_secure' => $this->getRequest()->isSecure()])); ?>"><?= /* @noEscape */ __('My Transaction List') ?></a>
                                    <!-- Transaction Notification -->
                                    <?php if ($block->getTransactionCollection()->getSize()) { ?>
                                    <div class="notification-block">
                                        <a href="" class="notifications-action marketplace-dropdown">
                                            <img height="20" width="20" src="<?= $block->escapeUrl($block->getViewFileUrl('Webkul_Marketplace::images/icons_notifications.png')); ?>" class="notifications-img" />
                                        <?php if ($transactionCount > 5): ?>
                                            <span class="notification-count">5+</span>
                                        <?php else: ?>
                                            <span class="notification-count"><?= $block->escapeHtml($transactionCount); ?></span>
                                        <?php endif; ?>
                                        </a>
                                        <ul class="marketplace-dropdown-menu">
                                        <span class="notify-point"></span>
                                        <?php
                                        $trnDisplayCount = 1;
                                        foreach ($block->getTransactionCollection() as $transaction):
                                            if ($trnDisplayCount <= 5):
                                                ?>
                                                <li class="notifications-entry">
                                                    <strong class="notifications-entry-title">
                                                        <?= $block->escapeHtml($block->getTransactionNotifyTitle($transaction->getEntityId())); ?>
                                                    </strong>
                                                    <p class="notifications-entry-description _cutted">
                                                        <a href="<?= $block->escapeUrl($block->getUrl('marketplace/transaction/view', ['id'=>$transaction->getId(), 'n' => 1, '_secure' => $this->getRequest()->isSecure()]))?>" class="notifications-entry-description-start">
                                                            <span>
                                                                <?= /* @noEscape */ $block->getTransactionNotifyDesc($transaction->getEntityId()); ?>
                                                            </span>
                                                        </a>
                                                    </p>
                                                    <time class="notifications-entry-time">
                                                        <?= /* @noEscape */ $block->getTransactionDate($transaction->getUpdatedAt()); ?>
                                                    </time>
                                                </li>
                                                <?php $trnDisplayCount++;
                                            endif;
                                        endforeach; ?>
                                            
                                        <?php
                                        if ($trnDisplayCount > 5):
                                            ?> 
                                                <li class="notifications-entry notifications-entry-last">
                                                <a href="<?= $block->escapeUrl($block->getUrl('marketplace/transaction/history', ['_secure' => $this->getRequest()->isSecure()])); ?>">
                                                        <?= /* @noEscape */ __('Click here to view transaction history'); ?>
                                                    </a>
                                                </li>
                                        <?php endif; ?>
                                        </ul>
                                    </div>
                                    <?php } ?>
                                    <!-- Transaction Notification End -->
                                    <?php
                                } ?>
                            </li>
                        <?php } ?>
                        <?php if (($isSellerGroup && $helper->isAllowedAction('marketplace/account/earning')) || !$isSellerGroup) { ?>
                            <li class="nav item <?= /* @noEscape */ strpos($magentoCurrentUrl, 'marketplace/account/earning')? "current":"";?>">
                                <?php
                                if (strpos($magentoCurrentUrl, 'marketplace/account/earning') !== false) { ?>
                                    <strong><?= /* @noEscape */ __('Earnings') ?></strong>
                                    <?php
                                } else { ?>
                                    <a href="<?= $block->escapeUrl($block->getUrl('marketplace/account/earning', ['_secure' => $this->getRequest()->isSecure()])); ?>">
                                        <?=/* @noEscape */__('Earnings') ?>
                                    </a>
                                    <?php
                                } ?>
                            </li>
                            <?php
                        } ?>
                        <?php if (($isSellerGroup && $helper->isAllowedAction('marketplace/order/shipping')) || !$isSellerGroup) { ?>
                            <?php if ($helper->getIsOrderManage()=="1") {?>
                            <li class="nav item <?= /* @noEscape */ strpos($magentoCurrentUrl, 'marketplace/order/shipping/')? "current":"";?>">
                                <?php if (strpos($magentoCurrentUrl, 'marketplace/order/shipping') !== false) { ?>
                                    <strong><?= /* @noEscape */ __('Manage Print PDF Header Info') ?></strong>
                                    <?php
                                } else { ?>
                                    <a href="<?= $block->escapeUrl($block->getUrl('marketplace/order/shipping', ['_secure' => $this->getRequest()->isSecure()])); ?>"><?= /* @noEscape */ __('Manage Print PDF Header Info') ?></a>
                                    <?php
                                } ?>
                            </li>
                                <?php
                            } ?>
                        <?php } ?>    
                        <?= $block->getChildHtml();?>
                        <?php if (($isSellerGroup && $helper->isAllowedAction('marketplace/order/history')) || !$isSellerGroup) { ?>
                            <li class="nav item notification-link  <?= /* @noEscape */ strpos($magentoCurrentUrl, 'marketplace/order') && (!strpos($magentoCurrentUrl, 'marketplace/order/shipping/'))? "current":"";?>">
                                <?php
                                if (strpos($magentoCurrentUrl, 'marketplace/order/history') !== false) { ?>
                                    <strong><?= /* @noEscape */ __('My Order History') ?></strong>  
                                    <?php
                                } else { ?>
                                    <a href="<?= $block->escapeUrl($block->getUrl('marketplace/order/history', ['_secure' => $this->getRequest()->isSecure()])); ?>">
                                        <?= /* @noEscape */ __('My Order History') ?>
                                    </a>
                                    <?php if ($block->getMarketplaceOrderCollection()->getSize()) { ?>
                                        <!-- Orders Notification -->
                                        <div class="notification-block">
                                            <a href="" class="notifications-action marketplace-dropdown">
                                                <img height="20" width="20" src="<?= /* @noEscape */ $block->getViewFileUrl('Webkul_Marketplace::images/icons_notifications.png'); ?>" class="notifications-img" />
                                                <?php if ($orderNotificationCount > 5): ?>
                                                <span class="notification-count">5+</span>
                                                <?php else: ?>
                                                    <span class="notification-count"><?= $block->escapeHtml($orderNotificationCount); ?></span>
                                                <?php endif; ?>
                                            </a>
                                            <ul class="marketplace-dropdown-menu">
                                            <span class="notify-point"></span>
                                            <?php
                                            $orderDisplayCount = 1;
                                            foreach ($block->getMarketplaceOrderCollection() as $order):
                                                if ($orderDisplayCount <= 5):
                                                    ?>
                                                    <li class="notifications-entry">
                                                        <strong class="notifications-entry-title">
                                                            <?= $block->escapeHtml($block->getOrderNotificationTitle($order->getOrderId())); ?>
                                                        </strong>
                                                        <p class="notifications-entry-description _cutted">
                                                            <a href="<?= $block->escapeUrl($block->getUrl('marketplace/order/view', ['id'=>$order->getOrderId(), 'n' => 1,'_secure' => $this->getRequest()->isSecure()]))?>" class="notifications-entry-description-start">
                                                                <span>
                                                                    <?= /* @noEscape */ $block->getOrderNotificationDesc($order->getOrderId()); ?>
                                                                </span>
                                                            </a>
                                                        </p>
                                                        <time class="notifications-entry-time">
                                                            <?= /* @noEscape */ $block->getOrderCreatedDate($order->getOrderId()); ?>
                                                        </time>
                                                    </li>
                                                    <?php
                                                    $orderDisplayCount++;
                                                endif;
                                            endforeach; ?>
                                            <?php
                                            if ($orderDisplayCount > 5):
                                                ?>    
                                                <li class="notifications-entry notifications-entry-last">
                                                    <a href="<?= $block->escapeUrl($block->getUrl('marketplace/order/history', ['_secure' => $this->getRequest()->isSecure()])); ?>">
                                                        <?= /* @noEscape */ __('Click here to view order history'); ?>
                                                    </a>
                                                </li>
                                            <?php endif; ?>
                                            </ul>
                                        </div>
                                    <?php } ?>
                                    <!-- Orders Notification End -->
                                    <?php
                                } ?> 
                            </li>
                        <?php } ?>
                        <?php if (($isSellerGroup && $helper->isAllowedAction('marketplace/account/customer')) || !$isSellerGroup) { ?>
                            <?php if ($helper->getSellerProfileDisplayFlag()) { ?>
                                <li class="nav item notification-link <?= /* @noEscape */ strpos($magentoCurrentUrl, 'marketplace/account/customer')? "current":"";?>">
                                    <?php if (strpos($magentoCurrentUrl, 'marketplace/account/customer') !== false) { ?>
                                        <strong><?= /* @noEscape */ __('Customers') ?></strong>  
                                    <?php } else { ?>
                                        <a href="<?= $block->escapeUrl($block->getUrl('marketplace/account/customer', ['_secure' => $this->getRequest()->isSecure()])); ?>">
                                            <?= /* @noEscape */ __('Customers') ?>
                                        </a>
                                    <?php } ?>
                                </li>
                            <?php } ?>
                        <?php } ?>
                        <?php if (($isSellerGroup && $helper->isAllowedAction('marketplace/account/review')) || !$isSellerGroup) { ?>
                            <?php if ($helper->getSellerProfileDisplayFlag()) { ?>
                                <li class="nav item notification-link <?= /* @noEscape */ strpos($magentoCurrentUrl, 'marketplace/account/review')? "current":"";?>">
                                    <?php if (strpos($magentoCurrentUrl, 'marketplace/account/review') !== false) { ?>
                                        <strong><?= /* @noEscape */ __('Review') ?></strong>
                                    <?php } else { ?>
                                        <a href="<?= $block->escapeUrl($block->getUrl('marketplace/account/review', ['_secure' => $this->getRequest()->isSecure()])); ?>">
                                            <?= /* @noEscape */ __('Review') ?>
                                        </a>
                                        <?php
                                        $nHelper = $this->helper(\Webkul\Marketplace\Helper\Notification::class);
                                        $notificationCount = $nHelper->getAllReviewNotificationCount($sellerId);
                                        $reviewNotificationColl = $nHelper->getAllReviewNotification($sellerId);
                                        if ($reviewNotificationColl->getSize()) { ?>
                                        <!-- Review Notification -->
                                        <div class="notification-block">
                                            <a href="" class="notifications-action marketplace-dropdown">
                                                <img height="20" width="20" src="<?= /* @noEscape */ $block->getViewFileUrl('Webkul_Marketplace::images/icons_notifications.png'); ?>" class="notifications-img" />
                                                <?php if ($notificationCount > 5): ?>
                                                <span class="notification-count">5+</span>
                                                <?php else: ?>
                                                    <span class="notification-count"><?= $block->escapeHtml($notificationCount); ?></span>
                                                <?php endif; ?>
                                            </a>
                                            <ul class="marketplace-dropdown-menu">
                                                <span class="notify-point"></span>
                                                <?php
                                                $reviewDisplayCount = 1;
                                                foreach ($reviewNotificationColl as $review):
                                                    if ($reviewDisplayCount <= 5):
                                                        ?>
                                                        <li class="notifications-entry">
                                                            <strong class="notifications-entry-title">
                                                                <?= /* @noEscape */ __('Review Notification'); ?> 
                                                            </strong>
                                                            <?php
                                                            $url = $block->getUrl('marketplace/account/review', ['_secure' => $this->getRequest()->isSecure()]);
                                                            /* @noEscape */ echo $nHelper->getReviewNotificationDetails($review, $url);
                                                            ?>
                                                        </li>
                                                        <?php
                                                        $reviewDisplayCount++;
                                                    endif;
                                                endforeach; ?>
                                                <?php if ($reviewDisplayCount > 5): ?>
                                                    <li class="notifications-entry notifications-entry-last">
                                                        <a href="<?= $block->escapeUrl($block->getUrl('marketplace/account/review', ['_secure' => $this->getRequest()->isSecure()])); ?>">
                                                            <?= /* @noEscape */ __('Click here to view all reviews'); ?>
                                                        </a>
                                                    </li>
                                                <?php endif; ?>
                                            </ul>
                                        </div>
                                        <?php } ?>
                                        <!-- Review Notification End -->
                                    <?php } ?>
                                </li>
                            <?php } ?>
                        <?php } ?>
                        <div id="marketplace-notification-component" data-bind="scope:'notification-content'">
                            <script type="text/x-magento-init">
                            {
                                "#marketplace-notification-component": {
                                    "Magento_Ui/js/core/app":  <?= /* @escapeNotVerified */ $block->getJsLayout();?>
                                }
                            }
                            </script>
                            <?= $block->getChildHtml('reply_template'); ?>
                        </div>
                        <?php
                    } else { ?>    
                        <?= $block->getChildHtml();?>
                        <li class="nav item <?= /* @noEscape */ strpos($magentoCurrentUrl, 'marketplace/account/becomepartner')? "current":"";?>">
                            <?php if (strpos($magentoCurrentUrl, 'marketplace/account/becomeseller') !== false) { ?> 
                                <strong><?= /* @noEscape */ __('Become Seller') ?></strong>    
                            <?php } else { ?>    
                                <a href="<?= $block->escapeUrl($block->getUrl('marketplace/account/becomeseller', ['_secure' => $this->getRequest()->isSecure()])); ?>">
                                    <?= /* @noEscape */ __('Become Seller') ?>
                                </a>
                            <?php } ?>
                        </li>
                        <?php
                    } ?>
                </ul>
            </nav>
        </div>
    </div>
    <?php
} ?>
