<!-- 
/**
 * @author      Magetop Developer (Kien)
 * @package     Magento Multi Vendor Marketplace_Seller_Assign_Product
 * @copyright   Copyright (c) Magetop (https://www.magetop.com)
 * @terms       https://www.magetop.com/terms
 * @license     https://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 **/
 -->
<?php 
	$collection = $block->getDataCollection(); 
	$helperMk = $this->helper(\Magetop\Marketplace\Helper\Collection::class);
?>
<?php if ( count($collection) ) { ?>
    <div class="seller_assign_product">
        <table>
            <tbody>
                <tr>
                    <td colspan="7">
                        <?php if(count($block->getCountNewProduct())){ ?>
                            <?php 
                                $price = array();
                                foreach($block->getCountNewProduct() as $data){ 
                                    $price[] = $data->getPrice();
                                }
                            ?>
                            <span class="olp-padding-right">
                                <span class="a-color-condition condition-new"><?php echo count($block->getCountNewProduct()) ?> new</span> from <span class="a-color-price">
                                    <?php echo \Magento\Framework\App\ObjectManager::getInstance()->create('Magento\Framework\Pricing\Helper\Data')->currency(min($price), true, false) ?>
                                </span>
                            </span>
                            <script>
                                require([
                                    "jquery"
                                ], function($){
                                    $('.condition-new').click(function(){
                                        $('.condition-new-product').show();
                                        $('.condition-used-product').hide();
                                    });
                                });
                            </script>
                        <?php } ?>
                        <?php if(count($block->getCountUsedProduct())){ ?>
                            <?php 
                                $price = array();
                                foreach($block->getCountUsedProduct() as $data){ 
                                    $price[] = $data->getPrice();
                                }
                            ?>
                            <span class="olp-padding-right">
                                <span class="a-color-condition condition-used"><?php echo count($block->getCountUsedProduct()) ?> used</span> from <span class="a-color-price">
                                    <?php echo \Magento\Framework\App\ObjectManager::getInstance()->create('Magento\Framework\Pricing\Helper\Data')->currency(min($price), true, false) ?>
                                </span>
                            </span>
                            <script>
                                require([
                                    "jquery"
                                ], function($){
                                    $('.condition-used').click(function(){
                                        $('.condition-new-product').hide();
                                        $('.condition-used-product').show();
                                    });
                                });
                            </script>
                        <?php } ?>
                    </td>
                </tr>
            </tbody>
        </table>
        <?php if(count($block->getCountNewProduct())){ ?>
            <table class="data table condition-new-product">
        		<thead>
        			<tr>
                        <th><?php echo __('Price') ?></th>
                        <th><?php echo __('Condition') ?></th>
                        <th><?php echo __('Product Image') ?></th>
                        <th style="width:30%"><?php echo __('Description') ?></th>
                        <th><?php echo __('Seller Information') ?></th>
            			<th><?php echo __('Buying Options') ?></th>
            		</tr>
                </thead>
                <tbody>
                    <?php foreach($block->getCountNewProduct() as $data){ ?>
                        <?php 
                            $seller = $block->getSellerInfoById($data->getSellerId()); 
                            if($seller[0]['logoimg'] != ''){
                                $logo = $block->getMkBaseMediaUrl().$seller[0]['logoimg'];
                            }else{
                                $logo = $block->getViewFileUrl('Magetop_Marketplace::images/noimage.png');
                            }  
                        ?>
                        <tr>
                            <td class="col"><?php echo \Magento\Framework\App\ObjectManager::getInstance()->create('Magento\Framework\Pricing\Helper\Data')->currency($data->getPrice(), true, false) ?></td>
                            <td class="col"><?php echo $data->getProductCondition() ?></td>
                            <td class="col">
                                <?php 
                                    if($data->getImage()){ 
                                        $_urlImage = $block->getUrlImage($data->getImage());
                                    }else{
                                        $_urlImage = $block->getViewFileUrl('Magetop_SellerAssignProduct::images/noimage.jpg');
                                    }
            					?>                        
                                <img src="<?php echo $_urlImage ?>" style="width: 50px"/>
                            </td>
                            <td class="col"><?php echo $data->getProductDescription() ?></td>
            				<td class="col">
            					<div class="">
                                    <a href="<?php echo  $helperMk->getRewriteUrl('marketplace/seller/view/vendor/'. $seller[0]['storeurl']); ?>" target="_blank" title="<?php echo $seller[0]['storetitle']; ?>" class="">
                                        <?php echo $seller[0]['storetitle'] ?>
                                    </a><br />
            						<a href="<?php echo  $helperMk->getRewriteUrl('marketplace/seller/view/vendor/'. $seller[0]['storeurl']); ?>" target="_blank" title="<?php echo $seller[0]['storetitle']; ?>" class="">
            							<img src="<?php echo $logo; ?>" style="width: 80px"/>
            						</a>
            					</div>
            					<div class="mst_feedback mv-row">
            					   	<?php 
                                        $arKeyReview = array('price','value','quality');
                                        $reviews = $block->getMKsellerReview($data->getSellerId()); 
                                        $totalReview = 0; $i = 0;
                                        if(count($reviews)){
                                            foreach($reviews as $key => $review) {
                                                if(in_array($key, $arKeyReview)) {
                                                    $totalReview += $review;
                                                    $i++;
                                                }
                                            }
                                        }
                                        if($totalReview > 0) {
                                            $totalReview = $totalReview / $i;
                                        }
                                    ?>	
                                    <a href="<?php echo  $this->getUrl()."marketplace/seller/review/vendor/".$seller[0]['storeurl']; ?>" target="_blank">
                                        <div class="wrapp-rating">
                                            <div class="rating" style="width:<?php echo $totalReview; ?>%;"></div>
                                        </div>
                                    </a>
                                    <a href="<?php echo $block->getUrl() ?>marketplace/seller/review/vendor/<?php echo $seller[0]['storeurl']; ?>" class="positive-reviews" target="_blank">
                                        <strong><?php echo round($totalReview,2); ?>% </strong><?php echo __('Positive Reviews'); ?>
                                    </a>							
                                </div>
            				</td>
            				<td class="col">
                                <form id="product_addtocart_form_<?php echo $data->getId() ?>" method="post" action="<?php echo $block->getUrlAddToCart($data->getProductId()) ?>" novalidate="novalidate">
                					<input type="hidden" value="<?php echo $data->getProductId() ?>" name="product"/>
                                    <input type="hidden" value="<?php echo $data->getId() ?>" name="assignproduct_id"/>
                                    <?php echo $block->getBlockHtml('formkey')?>
                                    <div class="fieldset">
                                        <div class="field">
                                            <div class="control">
                                                <input id="" class="input-text qty" type="number" title="<?php echo __('Qty') ?>" value="1" maxlength="12" name="qty" data-validate="{required:true}"/>
                                            </div>
                                        </div>
                                        <div class="actions">
                        					<button type="submit" title="<?php echo __('Add to Cart') ?>" class="action primary tocart">
                        						<span><?php echo __('Add to Cart') ?></span>
                        					</button>
                                        </div>
                                    </div>
                                </form>
                                <script>
                                    require([
                                        "jquery",
                                        "mage/mage"
                                    ], function($){
                                        var dataForm = $('#product_addtocart_form_<?php echo $data->getId() ?>');
                                        dataForm.mage('validation', {});
                                        var _action = dataForm.attr('action');
                                    });
                                </script>
            				</td>
            			</tr>
                    <?php } ?>	
                </tbody>
            </table>
        <?php } ?>	
        <?php if(count($block->getCountUsedProduct())){ ?>
            <table class="data table condition-used-product">
        		<thead>
        			<tr>
                        <th><?php echo __('Price') ?></th>
                        <th><?php echo __('Condition') ?></th>
                        <th><?php echo __('Product Image') ?></th>
                        <th style="width:30%"><?php echo __('Description') ?></th>
                        <th><?php echo __('Seller Information') ?></th>
            			<th><?php echo __('Buying Options') ?></th>
            		</tr>
                </thead>
                <tbody>
                    <?php foreach($block->getCountUsedProduct() as $data){ ?>
                        <?php 
                            $seller = $block->getSellerInfoById($data->getSellerId()); 
                            if($seller[0]['logoimg'] != ''){
                                $logo = $block->getMkBaseMediaUrl().$seller[0]['logoimg'];
                            }else{
                                $logo = $block->getViewFileUrl('Magetop_Marketplace::images/noimage.png');
                            }  
                        ?>
                        <tr>
                            <td class="col"><?php echo \Magento\Framework\App\ObjectManager::getInstance()->create('Magento\Framework\Pricing\Helper\Data')->currency($data->getPrice(), true, false) ?></td>
                            <td class="col"><?php echo $data->getProductCondition() ?></td>
                            <td class="col">
                                <?php 
                                    if($data->getImage()){ 
                                        $_urlImage = $block->getUrlImage($data->getImage());
                                    }else{
                                        $_urlImage = $block->getViewFileUrl('Magetop_SellerAssignProduct::images/noimage.jpg');
                                    }
            					?>                        
                                <img src="<?php echo $_urlImage ?>" style="width: 50px"/>
                            </td>
                            <td class="col"><?php echo $data->getProductDescription() ?></td>
            				<td class="col">
            					<div class="">
                                    <a href="<?php echo  $helperMk->getRewriteUrl('marketplace/seller/view/vendor/'. $seller[0]['storeurl']); ?>" target="_blank" title="<?php echo $seller[0]['storetitle']; ?>" class="">
                                        <?php echo $seller[0]['storetitle'] ?>
                                    </a><br />
            						<a href="<?php echo  $helperMk->getRewriteUrl('marketplace/seller/view/vendor/'. $seller[0]['storeurl']); ?>" target="_blank" title="<?php echo $seller[0]['storetitle']; ?>" class="">
            							<img src="<?php echo $logo; ?>" style="width: 80px"/>
            						</a>
            					</div>
            					<div class="mst_feedback mv-row">
            					   	<?php 
                                        $arKeyReview = array('price','value','quality');
                                        $reviews = $block->getMKsellerReview($data->getSellerId()); 
                                        $totalReview = 0; $i = 0;
                                        if(count($reviews)){
                                            foreach($reviews as $key => $review) {
                                                if(in_array($key, $arKeyReview)) {
                                                    $totalReview += $review;
                                                    $i++;
                                                }
                                            }
                                        }
                                        if($totalReview > 0) {
                                            $totalReview = $totalReview / $i;
                                        }
                                    ?>	
                                    <a href="<?php echo  $this->getUrl()."marketplace/seller/review/vendor/".$seller[0]['storeurl']; ?>" target="_blank">
                                        <div class="wrapp-rating">
                                            <div class="rating" style="width:<?php echo $totalReview; ?>%;"></div>
                                        </div>
                                    </a>
                                    <a href="<?php echo $block->getUrl() ?>marketplace/seller/review/vendor/<?php echo $seller[0]['storeurl']; ?>" class="positive-reviews" target="_blank">
                                        <strong><?php echo round($totalReview,2); ?>% </strong><?php echo __('Positive Reviews'); ?>
                                    </a>							
                                </div>
            				</td>
            				<td class="col">
                                <form id="product_addtocart_form_<?php echo $data->getId() ?>" method="post" action="<?php echo $block->getUrlAddToCart($data->getProductId()) ?>" novalidate="novalidate">
                					<input type="hidden" value="<?php echo $data->getProductId() ?>" name="product"/>
                                    <input type="hidden" value="<?php echo $data->getId() ?>" name="assignproduct_id"/>
                                    <?php echo $block->getBlockHtml('formkey')?>
                                    <div class="fieldset">
                                        <div class="field">
                                            <div class="control">
                                                <input id="" class="input-text qty" type="number" title="Qty" value="1" maxlength="12" name="qty" data-validate="{required:true}"/>
                                            </div>
                                        </div>
                                        <div class="actions">
                        					<button type="submit" title="<?php echo __('Add to Cart') ?>" class="action primary tocart">
                        						<span><?php echo __('Add to Cart') ?></span>
                        					</button>
                                        </div>
                                    </div>
                                </form>
                                <script>
                                    require([
                                        "jquery",
                                        "mage/mage"
                                    ], function($){
                                        var dataForm = $('#product_addtocart_form_<?php echo $data->getId() ?>');
                                        dataForm.mage('validation', {});
                                        var _action = dataForm.attr('action');
                                    });
                                </script>
            				</td>
            			</tr>
                    <?php } ?>	
                </tbody>
            </table>
        <?php } ?>						
    </div>
<?php } ?>
<style>
    .seller_assign_product{
        width:100%;
        float:left;
        border: 1px solid silver;
        margin: 15px 0px;
    }
    .olp-padding-right {
        padding-right: 18px;
    }
    .a-color-condition {
        color: #0066c0;
        text-decoration: none;
        cursor: pointer;
    }
    .a-color-price {
        color: #b12704 !important;
    }
    .seller_assign_product .table{
        display: none;
        border-top: 1px solid silver;
    }
    .seller_assign_product .wrapp-rating {
        margin-left: 0px;
        width: 70px;
        float: none;        
    }    
    .seller_assign_product .qty{
        text-align: center;
        width: 60px;
    }
    .seller_assign_product tbody tr td {
        vertical-align: middle;
    }  
    .seller_assign_product thead tr th,.seller_assign_product tbody tr td.col {
        text-align: left;
    } 
    #qty-error{
        margin-top: 0px;
    }
</style>