
<?php
	$helper = $this->helper("Magetop\Agency\Helper\Data");
	$queryString = htmlspecialchars($helper->getQueryString());
	$isAgency = $helper->isAgency();
	$collection = $this->getAllProducts();
	$_imagehelper = $this->helper('Magento\Catalog\Helper\Image');
?>
<?php if ($isAgency == 1): ?>
	<div class="wk-profile-alert">
		<span><?php echo __('Assign product is available for Simple, Configurable and Virtual type products.');?></span>
	</div>
	<form method="get" action="<?php echo $this->getUrl('agency/assignproduct/view'); ?>" id="assignproduct_form" enctype="multipart/form-data" data-mage-init='{"validation":{}}'>
		<fieldset class="fieldset">
			<?php echo $this->getFormKeyBlockHtml(); ?>
			<legend class="legend">
				<span><?php echo __("Assign Product"); ?></span>
			</legend>
			<div class="field required">
				<label for="attribute_set" class="label">
					<span><?php echo __("Search For Product"); ?></span>
				</label>
				<div class="control">
					<input value="<?php echo $queryString; ?>" type="text" data-validate="{required:true}" class="input-text required-entry" title="query" name="query" id="query" aria-required="true">
					<button class="button wk-ap-btn" type="submit">
						<span><span><?php echo __("Search"); ?></span></span>
					</button>
				</div>
			</div>
		</fieldset>
	</form>
	<?php if($collection->getSize()): ?>
		<fieldset class="fieldset wk-ap-fieldset">
			<table class="data table wk-table-product-list">
				<thead>
					<th><?php echo __("Image"); ?></th>
					<th><?php echo __("Name"); ?></th>
					<th><?php echo __("Price"); ?></th>
					<th><?php echo __("Action"); ?></th>
				</thead>
				<?php foreach ($collection as $product): ?>
					<?php
						$image = 'category_page_list';
						$productImage = $_imagehelper->init($product, $image)->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(75)->getUrl();
						$price = $this->helper('Magento\Framework\Pricing\Helper\Data')->currency($product->getFinalPrice(), true, false);
					?>
					<tr>
						<td class="col wk-ap-img-col"><img src="<?php echo $productImage; ?>" /></td>
						<td class="col"><?php echo $product->getName(); ?></td>
						<td class="col"><?php echo $price; ?></td>
						<td class="col wk-ap-btn-col">
							<a href="<?php echo $this->getUrl('agency/assignproduct/add')."id/".$product->getId(); ?>">
								<button class="button wk-ap-btn"><span><span><?php echo __("Sell Yours"); ?></span></span></button>
							</a>
						</td>
					</tr>
				<?php endforeach; ?>
			</table>
		</fieldset>
	<?php elseif ($this->getRequest()->getParam('query')!= ''): ?>
		<br>
		<div>
			<?php echo __("No Product Found"); ?>
		</div>
<?php endif; ?>
	<?php if ($block->getPagerHtml()): ?>
		<div class="order-products-toolbar toolbar bottom"><?php echo $block->getPagerHtml(); ?></div>
	<?php endif ?>
<?php else: ?>
	<h2 class="-msg">
		<?php echo __("To Become Agency Please Contact to Admin."); ?>
	</h2>
<?php endif; ?>
