<?php
    $objectManager =   \Magento\Framework\App\ObjectManager::getInstance();
    $connection = $objectManager->get('Magento\Framework\App\ResourceConnection')->getConnection('\Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION');
    $customer_id = $objectManager->get('Magento\Customer\Model\Session')->getCustomer()->getId();
    $seller_offer = $connection->fetchAll("SELECT * FROM multivendor_seller_offer where seller_id = ".$customer_id);
?>
<div class="block content-messages mgt-theme-div">
    <legend class="legend">
        <span><?php echo __('Store offer'); ?></span>
    </legend>
    <div class="table-wrapper">
        <form method="post" id="massDeleteCoupon" class="" action="<?php echo $block->getUrl('sellercoupon/index/massDelete') ?>">
            <table id="my-orders-table" class="data table table-order-items history">
                <caption class="table-caption"><?php echo __('Orders') ?></caption>
                <thead>
                    <tr>
                        <th class="col" scope="col"><?php echo __('ID'); ?>#</th>
                        <th class="col" scope="col"><?php echo __('Product Image'); ?></th>
                        <th class="col" scope="col"><?php echo __('Product Name'); ?></th>
                        <th class="col" scope="col"><?php echo __('Qty'); ?></th>
                        <th class="col" scope="col"><?php echo __('Added Time'); ?></th>
                        <th class="col" scope="col"><?php echo __('Status'); ?></th>
                        <th class="col" scope="col">&nbsp;</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach($seller_offer as $offer){ ?>
                        <?php
                            $wishlist = $objectManager->create('\Magento\Wishlist\Model\Item')->load($offer['wishlist_id'])->getData();
                            $product = $objectManager->create('Magento\Catalog\Model\Product')->load($wishlist['product_id']);
                            $helperImport = $objectManager->get('\Magento\Catalog\Helper\Image');
                            $imageUrl = $helperImport->init($product, 'product_page_image_small')->setImageFile($product->getSmallImage())->resize(50)->getUrl();
                        ?>
                            <tr class="">
                                <td class="col" data-th="#"><?php echo $wishlist['wishlist_item_id'] ?></td>
                                <td class="col" data-th="#"><?php echo $product->getName() ?></td>
                                <td class="col" data-th="#"><img src="<?php echo $imageUrl ?>" /></td>
                                <td class="col" data-th="#"><?php echo $wishlist['qty'] ?></td>
                                <td class="col" data-th="#"><?php echo $wishlist['added_at'] ?></td>
                                <td class="col" data-th="#">Approved</td>
                            </tr>
                    <?php } ?>
                </tbody>
            </table>
        </form>
    </div>
    <?php if ($block->getPagerHtml()): ?>
    	<div class="toolbar bottom"><?php echo $block->getPagerHtml();?></div>
    <?php endif ?>
</div>
<script>
    require([
        "jquery",
        'Magento_Ui/js/modal/confirm',
        'Magento_Ui/js/modal/alert',
        "mage/calendar"
    ], function($,confirmation,alert){
        $('input[type=checkbox][name=selecteallcoupon]').on('click',function(){
            if(this.checked==true){
                $('input[type=checkbox][name^=coupon_selected]').each(function(){
                    this.checked=true;
                });		
            }else{
                $('input[type=checkbox][name^=coupon_selected]').each(function(){
                    this.checked=false;
                });			
            }
        });
        $('button#delete-allcoupon').on('click',function(){
            var _flag=0;
            $('input[type=checkbox][name^=coupon_selected]').each(function(){
                if(this.checked==true){
                    _flag=1;
                    return false;
                }
            });
            if(!_flag){
                alert({
                    title:'<?php echo __('Attention') ?>',
                    content:"<?php echo __("You haven't selected any items!") ?>",
                    actions:{
                        always: function(){}
                    }
                });
            }else{
                confirmation({
                    title:'<?php echo __('Delete Coupon') ?>',
                    content:'<?php echo __("Delete selected items?") ?>',
                    actions:{
                        confirm:function(){
                            $('form#massDeleteCoupon').submit();
                        },
                        cancel: function(){},
                        always: function(){}
                    }
                });		
            }	
        });	
        $('.seller_coupon').addClass('current');
    });
</script>