<?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\Product\Create */
$helper = $this->helper(\Webkul\Marketplace\Helper\Data::class);
$allowedSets = $helper->getAllowedSets();
$allowedProducts = $helper->getAllowedProductTypes();
$totalSets = count($allowedSets);
$totalProductTypes = count($allowedProducts);
?>
<?php if (!$helper->isProfileCompleted() && $helper->getSellerProfileDisplayFlag()): ?>
    <div class="wk-profile-alert">
        <strong><?= $block->escapeHtml(__('Warning'))?>!</strong><span><?= $block->escapeHtml(__('Please Complete'))?></span>
        <a href="<?= $block->escapeUrl($block->getUrl('marketplace/account/editprofile', ['_secure' => $this->getRequest()->isSecure()]))?>" style="color: inherit;">
            <?= $block->escapeHtml(__('Your Profile'))?>
        </a>
        <span class="wk-close">X</span>
    </div>
<?php endif; ?>
<form action="<?= $block->escapeUrl($block->getUrl('marketplace/product/create', ['_secure' => $this->getRequest()->isSecure()])) ?>" enctype="multipart/form-data" method="post" id="form-customer-product-new" data-mage-init='{"validation":{}}'>
    <div class="wk-mp-design">
        <fieldset class="fieldset info wk-mp-fieldset">
            <legend class="legend">
                <span><?= $block->escapeHtml(__('Add New Product')) ?></span>
                <button class="button wk-mp-btn" title="Continue" type="submit">
                    <span><span><?= $block->escapeHtml(__('Continue')) ?></span></span>
                </button>
            </legend>
            <?= $block->getBlockHtml('formkey')?>
            <?= $block->getBlockHtml('seller.formkey')?>
            <?php if ($totalSets > 0): ?>
                <?php if ($totalSets > 1): ?>
                    <div class="field required">
                        <label class="label"><?= $block->escapeHtml(__('Attribute Set')) ?>:</label>
                        <div class="control">
                            <select name="set" class="required-entry">
                            <?php foreach ($allowedSets as $set): ?>
                                <option value="<?= $block->escapeHtml($set['value']) ?>"><?= $block->escapeHtml($set['label'])?></option>
                            <?php endforeach; ?>
                            </select>
                        </div>
                    </div>
                <?php else: ?>
                    <input type="hidden" name="set" value="<?= /* @noEscape */ $allowedSets[0]['value'] ?>" />
                <?php endif; ?>
            <?php endif; ?>
            <?php if ($totalProductTypes > 0): ?>
                <?php if ($totalProductTypes > 1): ?>
                    <div class="field required">
                        <label class="label"><?= $block->escapeHtml(__('Product Type')) ?>:</label>
                        <div class="control">
                            <select name="type" class="required-entry">
                            <?php foreach ($allowedProducts as $type): ?>
                                <option value="<?= $block->escapeHtml($type['value']) ?>"><?= $block->escapeHtml($type['label'])?></option>
                            <?php endforeach; ?>
                            </select>
                        </div>
                    </div>
                <?php else: ?>
                    <input type="hidden" name="type" value="<?= /* @noEscape */ $allowedProducts[0]['value'] ?>" />
                <?php endif; ?>
            <?php endif; ?>
            <?= $block->getChildHtml(); ?>
        </fieldset>
    </div>
</form>
<div class="buttons-set">
    <p class="required">* <?= $block->escapeHtml(__('Required Fields')) ?></p>
    <p class="back-link">
        <a href="javascript:;" onclick="javascript: window.history.back();" class="left">&laquo; <?= $block->escapeHtml(__('Back')) ?></a>
    </p>
</div>
<script type='text/javascript'>
    require(['jquery'], function($) {
      $('.wk-close').click(function(e) {
        $('.wk-profile-alert').hide();
      });
    })
</script>
