<?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
 */
/** @var $block \Webkul\Marketplace\Block\Account\Dashboard */

$helper = $this->helper(\Webkul\Marketplace\Helper\Data::class);
$captchaEnableStatus = $helper->getCaptchaEnable();
$orderHelper = $this->helper(\Webkul\Marketplace\Helper\Orders::class);
$getDateDetail = $block->getDateDetail();
$total_sale_coll = $block->getTotalSaleColl();
$total_sale = 0;
$total_remain_sale = 0;
foreach ($total_sale_coll as $value) {
    $total_sale = $value->getAmountReceived();
    $total_remain_sale = $value->getAmountRemain();
}
$getTopSaleProducts = $block->getTopSaleProducts();
$block->getTopSaleCategories();
?>
<style type="text/css">
    .wk-dashboard-sales-value {
        color: #eb5202;
    }
    .wk-dashboard-sales-font {
        font-size: 25px;
    }
    .button {
        padding: 4px 15px;
    }
</style>
<div class="wk-mp-page-title page-title">
    <button class="button askque" id="askque"><span><?= /* @noEscape */ __('Ask Question to Admin') ?></span></button>
</div>
<div class="wk-mp-design" style="width: 100%;display: inline-block;">
    <div class="mp-widgets">
        <div class="cotainer">
            <div style="border:1px solid #cccccc;">
                <div style="border-bottom: 1px solid #ccc;display: inline-block;width: 100%;">
                    <div style="float:left;">
                        <div style="padding:5px;">
                            <?= /* @noEscape */ __('Sales By Locations') ?>
                        </div>
                    </div>
                    <div style="float:right;padding: 2px;">
                        <button class="button" id="wk-location-chart-year">
                            <span><?= /* @noEscape */ __('Year') ?></span>
                        </button>
                        <button class="button" id="wk-location-chart-month">
                            <span><?= /* @noEscape */ __('Month') ?></span>
                        </button>
                        <button class="button" id="wk-location-chart-week">
                            <span><?= /* @noEscape */ __('Week') ?></span>
                        </button>
                        <button class="button" id="wk-location-chart-day">
                            <span><?= /* @noEscape */ __('Day') ?></span>
                        </button>
                    </div>
                </div>
                <div style="padding:5px;">
                    <center><?= $block->getChildHtml('locationChart')?></center>
                </div>
            </div>
        </div>
        <div class="cotainer">
            <div style="border:1px solid #cccccc;">
                <div style="border-bottom: 1px solid #ccc;display: inline-block;width: 100%;">
                    <div style="float:left;">
                        <div style="padding:5px;">
                            <?= /* @noEscape */ __('Sales Stats') ?>
                        </div>
                    </div>
                    <div style="float:right;padding: 2px;">
                        <button class="button" id="wk-diagram-chart-year">
                            <span><?= /* @noEscape */ __('Year') ?></span>
                        </button>
                        <button class="button" id="wk-diagram-chart-month">
                            <span><?= /* @noEscape */ __('Month') ?></span>
                        </button>
                        <button class="button" id="wk-diagram-chart-week">
                            <span><?= /* @noEscape */ __('Week') ?></span>
                        </button>
                        <button class="button" id="wk-diagram-chart-day">
                            <span><?= /* @noEscape */ __('Day') ?></span>
                        </button>
                    </div>
                </div>
                <div style="padding:5px;">
                    <center><?= $block->getChildHtml('diagrams')?></center>
                </div>
            </div>
        </div>
        <?= $block->getChildHtml('dashboard_additional_chart_block')?>
    </div>
    <div class="mp-sales-widgets" style="">
        <div class="sales" >
            <div class="sales" style="border:1px solid #cccccc;">
                <div style="border-bottom: 1px solid #ccc;padding:5px;">
                    <?= /* @noEscape */ __('Lifetime Sales') ?>
                </div>
                <div style="padding:5px;">
                    <strong class="wk-dashboard-sales-value wk-dashboard-sales-font">
                        <span class="price">
                        <?= /* @noEscape */ $helper->getFormatedPrice($total_sale+$total_remain_sale); ?>
                        </span>
                    </strong>
                </div>
            </div>
        </div>
        <div class="sales" >
            <div style="border:1px solid #cccccc;">
                <div style="border-bottom: 1px solid #ccc;padding:5px;">
                    <?= /* @noEscape */ __(' Total Payout ') ?>
                </div>
                <div style="padding:5px;">
                    <strong class="wk-dashboard-sales-font">
                        <span class="price">
                            <?= /* @noEscape */ $helper->getFormatedPrice($total_sale); ?>
                        </span>
                    </strong>
                </div>
            </div>
        </div>
        <div class="sales" >
            <div style="border:1px solid #cccccc;">
                <div style="border-bottom: 1px solid #ccc;padding:5px;">
                    <?= /* @noEscape */ __(' Remaining Amount ') ?>
                </div>
                <div style="padding:5px;">
                    <strong class="wk-dashboard-sales-font">
                        <span class="price">
                            <?= /* @noEscape */ $helper->getFormatedPrice($total_remain_sale); ?>
                        </span>
                    </strong>
                </div>
            </div>
        </div>
        <?= $block->getChildHtml('dashboard_additional_total_block')?>
        <div class="sales" >
            <div style="border:1px solid #cccccc;">
                <div style="border-bottom: 1px solid #ccc;padding:5px;">
                    <?= /* @noEscape */ __('Top Selling Products') ?>
                </div>
                <?php
                foreach ($getTopSaleProducts as $key => $value) {
                    ?>
                    <div style="border-bottom: 1px solid #ccc;padding:5px;">
                        <div style="color: green;font-weight: 600;">
                            <?= /* @noEscape */ __('%1 Sales', $value['qty']) ?>
                        </div>
                        <div><a href="<?= $block->escapeUrl($value['url'])?>"><?= $block->escapeHtml($value['name'])?></a></div>
                    </div>
                    <?php
                } ?>
            </div>
        </div>
        <div class="sales">
            <div style="border:1px solid #cccccc;">
                <div style="border-bottom: 1px solid #ccc;padding:5px;">
                    <?= /* @noEscape */ __('Top Selling Category') ?>
                </div>
                <div style="padding:5px;">
                    <center><?= $block->getChildHtml('categoryChart') ?></center>
                </div>
            </div>
        </div>
    </div>
</div>
<?= $block->getChildHtml('dashboard_additional_content_block')?>
<div class="wk-mp-design wk-mp-design2">
    <fieldset class="fieldset info wk-mp-fieldset">
        <legend class="legend"><span><?= /* @noEscape */ __('Latest Order') ?></span></legend>
        <div class="grid">
            <div class="hor-scroll">
                <?php
                if (count($block->getCollection())==0) { ?>
                    <div class="fieldset wk-mp-fieldset">
                        <div class="wk-emptymsg">
                            <?= /* @noEscape */ __('No Order Available') ?>
                        </div>
                    </div>
                    <?php
                } else { ?>
                    <?php $i=0;
                    foreach ($block->getCollection() as $res) {
                        $order = $block->getMainOrder($res['order_id']);
                        $state=$order->getState();
                        $status=$order->getStatus();
                        $name=$order->getCustomerName();
                        $tracking=$orderHelper->getOrderinfo($res['order_id']);
                        if ($tracking->getIsCanceled()) {
                            $state='canceled';
                            $status='Canceled';
                        }

                        if ($res['order_id']>0 && $i<6) {
                            $i++;?>
                            <div class="wk-orderbox <?php if ($i==1) { echo "wk-first-order"; }?>">
                                <div style="padding:7px 7px 0px 7px;">
                                    <div class="wk-orderbox-content1">
                                        <div class="wk-orderbox-details">
                                            <div class="color">
                                                <span class="wk-ordertitle-label"><?= /* @noEscape */ __('Order') ?></span> <strong>#<?= $block->escapeHtml($res['magerealorder_id']); ?></strong>
                                            </div>
                                            <div class="name">
                                                <?= /* @noEscape */ $block->getpronamebyorder($res['order_id'])?>
                                            </div>
                                            <a href="<?= $block->escapeUrl($block->getUrl('marketplace/order/view', ['id'=>$res['order_id'], '_secure' => $this->getRequest()->isSecure()]))?>">
                                                    <button class="button" title="<?= /* @noEscape */ __('View Order') ?>" type="button">
                                                        <span><span><span><?= /* @noEscape */ __('View Order') ?></span></span></span>
                                                    </button>
                                                </a>
                                        </div>
                                        <div class="wk-dash-orderstatus">
                                            <label for="name" class="wk-dash-label">
                                                    <div class="status <?= $block->escapeHtml(strtolower($state)); ?>"><?= $block->escapeHtml(strtoupper($status)); ?> </div>
                                            </label>
                                        </div>
                                    </div>
                                    <div class="wk-orderbox-content2">
                                        <div class="wk-orderbox-details">
                                            <?php if ($helper->getSellerProfileDisplayFlag()) { ?>
                                                <span class="wk-title-label"><?= /* @noEscape */ __('Customer: ');?></span>
                                                <span class="wk-label"><?= $block->escapeHtml($name);?></span>&nbsp;&nbsp;
                                            <?php } ?>
                                            <span class="wk-title-label"><?= /* @noEscape */ __('Date: ');?></span>
                                            <span class="wk-label"><?= /* @noEscape */ $block->formatDate($res['created_at'])?></span>
                                        </div>
                                        <div class="wk-orderbox-total">
                                            <span class="wk-title-label"><?= /* @noEscape */ __('Order Total (Base)- ');?></span>
                                            <span class="wk-label">
                                                <strong>
                                                    <?php
                                                    $orderPrice = $block->getPricebyorder($res['order_id']);
                                                  /* @noEscape */ echo $order->formatBasePrice($orderPrice);
                                                    ?>
                                                </strong>
                                            </span>
                                            <span class="wk-title-label"><?= /* @noEscape */ __('Order Total (Purchased)- ');?></span>
                                            <span class="wk-label">
                                                <strong>
                                                    <?= /* @noEscape */ $order->formatPrice($block->getOrderedPricebyorder($res['currency_rate'], $orderPrice));
                                                    ?>
                                                </strong>
                                            </span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="wk-clear"></div>
                        <?php }
                    }     ?>
                    <?php
                }?>
            </div>
        </div>
    </fieldset>
</div>
<?php if ($helper->getSellerProfileDisplayFlag()) { ?>
    <div class="wk-mp-design wk-mp-design2">
        <fieldset class="fieldset info wk-mp-fieldset">
            <legend class="legend"><span><?= /* @noEscape */ __('Latest Comments & Reviews') ?></span></legend>
            <div class="grid">
                <div class="hor-scroll">
                    <?php
                    $ratings=[];
                    $products=[];
                    $rate=[];
                    $reviewcollection=$block->getReviewcollection();
                    if (count($reviewcollection)==0) { ?>
                        <div class="wk-emptymsg">
                            <?= /* @noEscape */ __('no comment & review available'); ?>
                        </div>
                        <?php
                    } else {
                        $i=0;
                        foreach ($reviewcollection as $keyed) {
                            $name=$block->getCustomer()->load($keyed->getBuyerId())->getName();
                            $i++; ?>
                            <div class="wk-orderbox <?php if ($i==1) { echo "wk-first-order"; }?>">
                                <div style="padding:7px 7px 0px 7px;">
                                    <div class="wk-orderbox-content1">
                                        <div class="wk-feedback-details">
                                            <div class="mpfeedback">
                                                <div class="price">
                                                    <span class="wk-ordertitle-label wk-span"><?= /* @noEscape */ __('Price') ?> </span><span class="wk-ordertitle-label">:</span>
                                                    <div class="ratingslider-box">
                                                        <div class="rating" style="width:<?= /* @noEscape */ ceil($keyed['feed_price']);?>%;"></div>
                                                    </div>
                                                    <div class="clear"></div>
                                                </div>
                                                <div class="value">
                                                    <span class="wk-ordertitle-label wk-span"><?= /* @noEscape */ __('Value') ?> </span><span class="wk-ordertitle-label">:</span>
                                                    <div class="ratingslider-box" >
                                                        <div class="rating" style="width:<?= /* @noEscape */ ceil($keyed['feed_value']);?>%;"></div>
                                                    </div>
                                                    <div class="clear"></div>
                                                </div>
                                                <div class="quality">
                                                    <span class="wk-ordertitle-label wk-span"><?= /* @noEscape */ __('Quality') ?> </span><span class="wk-ordertitle-label">:</span>
                                                    <div class="ratingslider-box">
                                                        <div class="rating" style="width:<?= /* @noEscape */ ceil($keyed['feed_quality']);?>%;"></div>
                                                    </div>
                                                    <div class="wk-clear"></div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="wk-feedback-desc">
                                            <div class="comment"><?= $block->escapeHtml($keyed['feed_review']); ?> </div>
                                        </div>
                                    </div>
                                    <div class="wk-orderbox-content2">
                                        <div class="wk-orderbox-details">
                                            <span class="wk-title-label"><?= /* @noEscape */ __('Customer: ');?></span>
                                            <span class="wk-label"><?= $block->escapeHtml($name);?></span>&nbsp;&nbsp;
                                            <span class="wk-title-label"><?= /* @noEscape */ __('Date: ');?></span>
                                            <span class="wk-label"><?= $block->escapeHtml($keyed['created_at']) ?></span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="wk-clear"></div>
                            <?php
                        }     ?>
                        <?php
                    } ?>
                </div>
            </div>
        </fieldset>
    </div>
<?php } ?>
<div class="ask-que">
    <div id="wk-mp-ask-data">
        <div class="wk-mp-modals-wrapper">
            <aside tabindex="0" data-type="popup" data-role="modal" class="modal-popup modal-slide _inner-scroll wk-mp-model-popup">
                <div tabindex="0" data-role="focusable-start"></div>
                <div data-role="focusable-scope" class="modal-inner-wrap">
                    <header class="modal-header">
                        <h4 class="modal-title"><?= /* @noEscape */ __('Ask Question to Admin') ?></h4>
                        <button type="button" data-role="closeBtn" class="action-close wk-close">
                            <span><?= /* @noEscape */ __('Close') ?></span>
                        </button>
                        <span  class="wk-clear" ></span>
                    </header>
                    <form id="ask-form" method="post" action="#" class="fieldset" data-role="ask-form" data-mage-init='{"validation":{}}'>
                        <div class="modal-body form-list field required">
                            <label class="label"><?= /* @noEscape */ __('Subject') ?> :</label>
                            <input type="text" name="subject" class="wk-contact_input_fields required-entry"/>
                            <label class="label"><?= /* @noEscape */ __('Your Query') ?> :</label>
                            <textarea  name="ask" class="queryquestion wk-contact_input_fields required-entry" style="width:100%;"></textarea>
                            <input type="hidden" name="seller-id" value="<?= $block->escapeHtml($block->getCustomerId());?>"/>
                            <?php
                            if ($captchaEnableStatus) {?>
                                <div>
                                    <span>
                                        <label for="wk-mp-captcha"><span id="wk-mp-captchalable1"><?= /* @noEscape */ rand(1, 20)?></span> + <span id="wk-mp-captchalable2"><?= /* @noEscape */ rand(1, 20)?></span> =</label>
                                    </span>
                                    <input type="text" class="required-entry wk-contact_input_fields" name="wk-mp-captcha" id="wk-mp-captcha" />
                                </div>
                                <?php
                            }?>
                        </div>
                        <div class="modal-footer">
                            <span class="error"></span>
                            <span class="errormail"></span>
                            <input type="reset" value="<?= /* @noEscape */ __('Reset') ?>" id="resetbtn" class="wk-btn wk-btn_default"/>
                            <input type="submit" value="<?= /* @noEscape */ __('Submit') ?>" id="askbtn" class="wk-btn wk-btn-primary clickask"/>
                            <span class="wk-clear"></span>
                        </div>
                    </form>
                </div>
                <div tabindex="0" data-role="focusable-end"></div>
            </aside>
        </div>
    </div>
</div>
<div class="buttons-set">
    <p class="back-link">
        <a href="javascript:;" onclick="javascript: window.history.back();" class="left">&laquo; <?=/* @noEscape */ __('Back') ?></a>
    </p>
</div>
<?php
$formData = [
    'loader'                =>  $this->getViewFileUrl('images/loader-2.gif'),
    'mpLocationChartSelector'   =>  '#wk-location-chart',
    'mpYearLocationChartSelector'   =>  '#wk-location-chart-year',
    'mpAskDataSelector'     =>  '#wk-mp-ask-data',
    'askQueSelector'        =>  '#askque',
    'askFormSelector'       => '#ask-form',
    'askFormInputSelector'  =>  '#ask-form input',
    'askFormTextareaSelector' =>    '#ask-form textarea',
    'pageWrapperSelector'   =>  '.page-wrapper',
    'mpModelPopupSelector'  =>  '.wk-mp-model-popup',
    'showClass'             =>  '_show',
    'mageErrorClass'        =>  'mage-error',
    'resetBtnSelector'      =>  '#resetbtn',
    'wkCloseSelector'       =>  '.wk-close',
    'validationFailedSelector'  =>  '.validation-failed',
    'askFormValidationFailedSelector'   =>  '#ask-form .validation-failed',
    'askFormValidationAdviceSelector'   =>  '#ask-form .validation-advice',
    'askFormErrorMailSelector'          =>  '#ask-form .errormail',
    'askBtnSelector'        =>  '#askbtn',
    'mpCaptcha1Selector'    =>  '#wk-mp-captchalable1',
    'mpCaptcha2Selector'    =>  '#wk-mp-captchalable2',
    'mpCaptchaSelector'     =>  '#wk-mp-captcha',
    'mailProcssClass'       =>  'mail-procss',
    'captchaEnableStatus'   =>  $captchaEnableStatus,
    'ajaxMailSendUrl'       =>  $block->getUrl("marketplace/account/askquestion", ["_secure" => $this->getRequest()->isSecure()]),
    'ajaxChartUrl'      =>     $block->getUrl("marketplace/account/chart", ["_secure" => $this->getRequest()->isSecure()])
];
$serializedFormData = $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($formData);
?>
<script type="text/x-magento-init">
    {
        "*": {
            "sellerDashboard": <?= /* @noEscape */ $serializedFormData; ?>
        }
    }
</script>
