<?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\Becomeseller */

$helper = $this->helper(\Webkul\Marketplace\Helper\Data::class);
$seller_exist= $helper->isSellerExist();
$sellerStatus = $helper->getSellerStatus();
$allSellerStatus = $helper->getAllowedSellerStatus();
$sellerStatusText  = isset($allSellerStatus[$sellerStatus]) ? $allSellerStatus[$sellerStatus] : '';
?>
<div>
    <?php if ($seller_exist) { ?>
      <div class="fieldset">
          <h4 class="legend"><?= /* @noEscape */ __('Seller Request Panel') ?></h4>
            <?php if ($sellerStatus != 3): ?>
              <div class="wk_emptymsg"><?= /* @noEscape */ __('Waiting for approval from admin, your application current status is %1',$sellerStatusText) ?></div>
            <?php else:?>
              <div class="wk_emptymsg"><?= /* @noEscape */ __('Your account is disapproved by the admin, please contact to admin!') ?></div>
            <?php endif; ?>
      </div>
    <?php } else { ?>
        <form action="<?= $block->escapeUrl($block->getUrl('marketplace/account/becomesellerPost', ["_secure" => $this->getRequest()->isSecure()])) ?>" enctype="multipart/form-data" method="post" id="form-become-seller" data-role="form-become-seller" data-mage-init='{"validation":{}}'>
            <?= $block->getBlockHtml('seller.formkey')?>
            <?= $block->getBlockHtml('formkey')?>
            <div class="wk-mp-design">
                <fieldset class="fieldset info wk-mp-fieldset">
                    <legend class="legend">
                        <span><?= /* @noEscape */ __('Seller Request Panel') ?></span>
                        <button type="reset" class="button wk-mp-btn">
                            <span><span><?= /* @noEscape */ __('Reset') ?></span></span>
                        </button>
                        <button type="submit" title="Save" class="button pay wk-mp-btn">
                            <span>
                                <span><?= /* @noEscape */ __('Save') ?></span>
                            </span>
                        </button>
                    </legend>
                    <div class="field required">
                        <label class="label"><?= /* @noEscape */ __('Shop URL') ?></label>
                        <?php
                        if ($helper->getProfileHintStatus() && $helper->getProfileHintShopurl()) {?>
                            <img src="<?= /* @noEscape */ $this->getViewFileUrl('Webkul_Marketplace::images/quest.png'); ?>" class='questimg' title="<?= /* @noEscape */ $helper->getProfileHintShopurl()?>"/>
                        <?php
                        } ?>
                        <div class="control shop" id="wk-mp-become-seller-box-wrapper" data-role="wk-mp-become-seller-box-wrapper">
                            <input type="text" class="required-entry wk_input_width" name="profileurl" id="profileurl" data-role="shop-url" placeholder="<?= /* @noEscape */ __("Please enter shop URL")?>"/>
                            <div id="wk-load" class="no-display">
                                <img src="<?= /* @noEscape */ $this->getViewFileUrl('Webkul_Marketplace::images/ajax-loader-tr.gif'); ?>" height="16px" width="16px"/>
                            </div>
                        </div>
                    </div>
                    <div class="field required">
                        <input type="checkbox" class="required-entry" name="is_seller" id="is_seller"/>
                        <label class="label"><?= /* @noEscape */ __('Do you want to become a seller / vendor ?') ?></label>
                    </div>
                </fieldset>
            </div>
        </form>
    <?php } ?>
</div>
<?php
$formData = [
    'ajaxSaveUrl' => $block->getUrl("marketplace/seller/usernameverify", ["_secure" => $this->getRequest()->isSecure()]),
    'successMessage' => __("Congratulations! Shop name is available."),
    'errorMessage' => __("Sorry! But this shop name is not available, please set another shop name."),
    'button' => '.button'
];
$serializedFormData = $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($formData);
?>

<script type="text/x-magento-init">
    {
        "[data-role=form-become-seller]": {
            "validation": {},
            "verifySellerShop": <?= /* @noEscape */ $serializedFormData; ?>
        }
    }
</script>
