<?php
/**
 * @author      Magetop Developer (Hau)
 * @package     Magento Multi Vendor Marketplace
 * @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
/**
 * Create account form template
 *
 * @var $block \Magento\Customer\Block\Form\Register
 */
?>
<?php echo $block->getChildHtml('form_fields_before')?>
<?php /* Extensions placeholder */ ?>
<?php echo $block->getChildHtml('customer.form.register.extra')?>
<form class="form create account form-create-account" action="<?php /* @escapeNotVerified */ echo $block->getPostActionUrl() ?>" method="post" id="form-validate" enctype="multipart/form-data" autocomplete="off">
    <?= /* @noEscape */ $block->getBlockHtml('formkey'); ?>
    <fieldset class="fieldset create info">
        <legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Personal Information') ?></span></legend><br>
        <input type="hidden" name="success_url" value="<?php /* @escapeNotVerified */ echo $block->getSuccessUrl() ?>">
        <input type="hidden" name="error_url" value="<?php /* @escapeNotVerified */ echo $block->getErrorUrl() ?>">
        <?php echo $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Name')->setObject($block->getFormData())->setForceUseCustomerAttributes(true)->toHtml() ?>
		<div id="want-vendor" class="field required choice">
			<input type="checkbox" <?php if($this->getRequest()->getParam('seller') == 'register')echo "checked='checked'" ?> id="wantvendor" class="wantvendor" name="is_seller" value="1" title="<?php echo __('Agree as Seller') ?>" aria-required="true">        
			<label for="wantvendor" class="label">
				<span><?php echo __('Do You Want To Become Seller / Vendor?') ?></span>
			</label>
			<!--<div class="control">
				<input type="radio" id="wantvendor" class="wantvendor" name="is_seller" value="1" title="<?php echo __('Agree as Seller') ?>" aria-required="true"><?php echo __('Yes') ?>&nbsp;&nbsp;
				<input type="radio" id="wantvendor" class="wantvendor" name="is_seller" value="0" title="<?php echo __('Disagree as Seller') ?>" checked="" aria-required="true"> <?php echo __('No') ?>
			</div>-->
		</div>	
        <div id="shop-name" class="field field-shop-name required" style="display: none;">
            <label for="storetitle" class="label">
                <span><?php echo __('Shop Name') ?></span>
            </label>
            <div class="control">
                <input type="text" data-validate="{required:true}" class="input-text required-entry" title="<?php echo __('Shop Name') ?>" value="" name="storetitle" id="storetitle" autocomplete="off" aria-required="true">
            </div>
        </div>
        <div id="contact-number" class="field field-contact-number required" style="display: none;">
            <label for="contactnumber" class="label">
                <span><?php echo __('Contact Number') ?></span>
            </label>
            <div class="control">
                <input type="text" data-validate="{required:true}" class="input-text required-entry" title="<?php echo __('Contact Number') ?>" value="" name="contactnumber" id="contactnumber" autocomplete="off" aria-required="true">
            </div>
        </div>
        <div id="shopurl" class="shopurl field field-shopurl required" style="display: none;">
            <label class="label">
                <span><?php echo __('Shop URL For Your Marketplace Shop') ?></span>
            </label>
            <div class="control">
				<div id="mb-ajaxloading">
                    <img width="20px" height="20px" src="<?php echo $block->getViewFileUrl('images/loader-1.gif') ?>">
                </div>			
                <input type="text" data-validate="{required:true}" class="input-text required-entry shopurl" title="<?php echo __('Shop URL For Your Marketplace Shop') ?>" value="" name="shopurl" id="shopurl" autocomplete="off" aria-required="true">
                <span name="shopurl" type="text" class="required-entry"> 
					 <?php echo __('(This will be used to display your public profile. Example: fashion-store)') ?>
                </span>
            </div>
            <div class="messages">
                <div class="message-notice notice message shopurl_false" data-ui-id="message-notice" style="display: none;">
                    <div><?php echo __('This URL is not available.') ?></div>
                </div>
                <div class="message-success success message shopurl_true" data-ui-id="message-success" style="display: none;">
                    <div><?php echo __('This URL is available.') ?></div>
                </div>
            </div>
        </div>	
        <?php if ($block->isNewsletterEnabled()): ?>
            <div class="field choice newsletter">
                <input type="checkbox" name="is_subscribed" title="<?php /* @escapeNotVerified */ echo __('Sign Up for Newsletter') ?>" value="1" id="is_subscribed"<?php if ($block->getFormData()->getIsSubscribed()): ?> checked="checked"<?php endif; ?> class="checkbox">
                <label for="is_subscribed" class="label"><span><?php /* @escapeNotVerified */ echo __('Sign Up for Newsletter') ?></span></label>
            </div>
            <?php /* Extensions placeholder */ ?>
            <?php echo $block->getChildHtml('customer.form.register.newsletter')?>
        <?php endif ?>

        <?php $_dob = $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Dob') ?>
        <?php if ($_dob->isEnabled()): ?>
            <?php echo $_dob->setDate($block->getFormData()->getDob())->toHtml() ?>
        <?php endif ?>

        <?php $_taxvat = $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Taxvat') ?>
        <?php if ($_taxvat->isEnabled()): ?>
            <?php echo $_taxvat->setTaxvat($block->getFormData()->getTaxvat())->toHtml() ?>
        <?php endif ?>

        <?php $_gender = $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Gender') ?>
        <?php if ($_gender->isEnabled()): ?>
            <?php echo $_gender->setGender($block->getFormData()->getGender())->toHtml() ?>
        <?php endif ?>
    </fieldset>
    <?php if ($block->getShowAddressFields()): ?>
        <fieldset class="fieldset address">
            <legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Address Information') ?></span></legend><br>
            <input type="hidden" name="create_address" value="1" />
            <div class="field company">
                <label for="company" class="label"><span><?php /* @escapeNotVerified */ echo __('Company') ?></span></label>
                <div class="control">
                    <input type="text" name="company" id="company" value="<?php echo $block->escapeHtml($block->getFormData()->getCompany()) ?>" title="<?php /* @escapeNotVerified */ echo __('Company') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('company') ?>">
                </div>
            </div>
            <div class="field telephone">
                <label for="telephone" class="label"><span><?php /* @escapeNotVerified */ echo __('Phone Number') ?></span></label>
                <div class="control">
                    <input type="text" name="telephone" id="telephone" value="<?php echo $block->escapeHtml($block->getFormData()->getTelephone()) ?>" title="<?php /* @escapeNotVerified */ echo __('Phone Number') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('telephone') ?>">
                </div>
            </div>

            <?php $_streetValidationClass = $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('street'); ?>

            <div class="field street required">
                <label for="street_1" class="label"><span><?php /* @escapeNotVerified */ echo __('Street Address') ?></span></label>
                <div class="control">
                    <input type="text" name="street[]" value="<?php echo $block->escapeHtml($block->getFormData()->getStreet(0)) ?>" title="<?php /* @escapeNotVerified */ echo __('Street Address') ?>" id="street_1" class="input-text <?php /* @escapeNotVerified */ echo $_streetValidationClass ?>">
                    <div class="nested">
                        <?php $_streetValidationClass = trim(str_replace('required-entry', '', $_streetValidationClass)); ?>
                        <?php for ($_i = 2, $_n = $this->helper('Magento\Customer\Helper\Address')->getStreetLines(); $_i <= $_n; $_i++): ?>
                            <div class="field additional">
                                <label class="label" for="street_<?php /* @escapeNotVerified */ echo $_i ?>">
                                    <span><?php /* @escapeNotVerified */ echo __('Address') ?></span>
                                </label>
                                <div class="control">
                                    <input type="text" name="street[]" value="<?php echo $block->escapeHtml($block->getFormData()->getStreetLine($_i - 1)) ?>" title="<?php /* @escapeNotVerified */ echo __('Street Address %1', $_i) ?>" id="street_<?php /* @escapeNotVerified */ echo $_i ?>" class="input-text <?php /* @escapeNotVerified */ echo $_streetValidationClass ?>">
                                </div>
                            </div>
                        <?php endfor; ?>
                    </div>
                </div>
            </div>

            <div class="field required">
                <label for="city" class="label"><span><?php /* @escapeNotVerified */ echo __('City') ?></span></label>
                <div class="control">
                    <input type="text" name="city" value="<?php echo $block->escapeHtml($block->getFormData()->getCity()) ?>" title="<?php /* @escapeNotVerified */ echo __('City') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('city') ?>" id="city">
                </div>
            </div>

            <div class="field region required">
                <label for="region_id" class="label"><span><?php /* @escapeNotVerified */ echo __('State/Province') ?></span></label>
                <div class="control">
                    <select id="region_id" name="region_id" title="<?php /* @escapeNotVerified */ echo __('State/Province') ?>" class="validate-select" style="display:none;">
                        <option value=""><?php /* @escapeNotVerified */ echo __('Please select a region, state or province.') ?></option>
                    </select>
                    <input type="text" id="region" name="region" value="<?php echo $block->escapeHtml($block->getRegion()) ?>" title="<?php /* @escapeNotVerified */ echo __('State/Province') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('region') ?>" style="display:none;">
                </div>
            </div>

            <div class="field zip required">
                <label for="zip" class="label"><span><?php /* @escapeNotVerified */ echo __('Zip/Postal Code') ?></span></label>
                <div class="control">
                    <input type="text" name="postcode" value="<?php echo $block->escapeHtml($block->getFormData()->getPostcode()) ?>" title="<?php /* @escapeNotVerified */ echo __('Zip/Postal Code') ?>" id="zip" class="input-text validate-zip-international <?php /* @escapeNotVerified */ echo $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('postcode') ?>">
                </div>
            </div>

            <div class="field country required">
                <label for="country" class="label"><span><?php /* @escapeNotVerified */ echo __('Country') ?></span></label>
                <div class="control">
                    <?php echo $block->getCountryHtmlSelect() ?>
                </div>
            </div>
            <?php $addressAttributes = $block->getChildBlock('customer_form_address_user_attributes');?>
            <?php if ($addressAttributes): ?>
                <?php $addressAttributes->setEntityType('customer_address'); ?>
                <?php $addressAttributes->setFieldIdFormat('address:%1$s')->setFieldNameFormat('address[%1$s]');?>
                <?php $block->restoreSessionData($addressAttributes->getMetadataForm(), 'address');?>
                <?php echo $addressAttributes->setShowContainer(false)->toHtml()?>
            <?php endif;?>
            <input type="hidden" name="default_billing" value="1">
            <input type="hidden" name="default_shipping" value="1">
        </fieldset>

    <?php endif; ?>
    <fieldset class="fieldset create account" data-hasrequired="<?php /* @escapeNotVerified */ echo __('* Required Fields') ?>">
        <legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Sign-in Information') ?></span></legend><br>
        <div class="field required">
            <label for="email_address" class="label"><span><?php /* @escapeNotVerified */ echo __('Email') ?></span></label>
            <div class="control">
                <input type="email" name="email" autocomplete="email" id="email_address" value="<?php echo $block->escapeHtml($block->getFormData()->getEmail()) ?>" title="<?php /* @escapeNotVerified */ echo __('Email') ?>" class="input-text" data-validate="{required:true, 'validate-email':true}">
            </div>
        </div>
        <div class="field password required" data-mage-init='{"passwordStrengthIndicator": {}}'>
            <label for="password" class="label"><span><?php /* @escapeNotVerified */ echo __('Password') ?></span></label>
            <div class="control">
                <input type="password" name="password" id="password"
                       title="<?php /* @escapeNotVerified */ echo __('Password') ?>"
                       class="input-text"
                       data-password-min-length="<?php echo $block->escapeHtml($block->getMinimumPasswordLength()) ?>"
                       data-password-min-character-sets="<?php echo $block->escapeHtml($block->getRequiredCharacterClassesNumber()) ?>"
                       data-validate="{required:true, 'validate-customer-password':true}"
                       autocomplete="off">
                <div id="password-strength-meter-container" data-role="password-strength-meter">
                    <div id="password-strength-meter" class="password-strength-meter">
                        <?php /* @escapeNotVerified */ echo __('Password Strength'); ?>:
                        <span id="password-strength-meter-label" data-role="password-strength-meter-label">
                            <?php /* @escapeNotVerified */ echo __('No Password'); ?>
                        </span>
                    </div>
                </div>
            </div>

        </div>
        <div class="field confirmation required">
            <label for="password-confirmation" class="label"><span><?php /* @escapeNotVerified */ echo __('Confirm Password') ?></span></label>
            <div class="control">
                <input type="password" name="password_confirmation" title="<?php /* @escapeNotVerified */ echo __('Confirm Password') ?>" id="password-confirmation" class="input-text" data-validate="{required:true, equalTo:'#password'}" autocomplete="off">
            </div>
        </div>
        <?php echo $block->getChildHtml('form_additional_info'); ?>
    </fieldset>
    <div class="actions-toolbar">
        <div class="primary">
            <button type="submit" class="action submit primary" title="<?php /* @escapeNotVerified */ echo __('Create an Account') ?>"><span><?php /* @escapeNotVerified */ echo __('Create an Account') ?></span></button>
        </div>
        <div class="secondary">
            <a class="action back" href="<?php echo $block->escapeUrl($block->getBackUrl()) ?>"><span><?php /* @escapeNotVerified */ echo __('Back') ?></span></a>
        </div>
    </div>
</form>
<script>
    require([
        'jquery',
    	'mage/template',
        'mage/mage'
    ], function($,mageTemplate,alert){
    
        var dataForm = $('#form-validate');
        var ignore = <?php /* @escapeNotVerified */ echo $_dob->isEnabled() ? '\'input[id$="full"]\'' : 'null'; ?>;
        
        dataForm.mage('validation', {
        <?php if ($_dob->isEnabled()): ?>
            errorPlacement: function(error, element) {
                if (element.prop('id').search('full') !== -1) {
                    var dobElement = $(element).parents('.customer-dob'),
                        errorClass = error.prop('class');
                    error.insertAfter(element.parent());
                    dobElement.find('.validate-custom').addClass(errorClass)
                        .after('<div class="' + errorClass + '"></div>');
                }
                else {
                    error.insertAfter(element);
                }
            },
            ignore: ':hidden:not(' + ignore + ')'
        <?php else: ?>
            ignore: ignore ? ':hidden:not(' + ignore + ')' : ':hidden'
        <?php endif ?>
        }).find('input:text').attr('autocomplete', 'off');	
    
    	$('.shopurl').keyup(function(){
    		$(this).val($(this).val().replace(/[^a-z^A-Z^0-9\.\-]/g,''));
    	});
                
    	$('#form-validate').delegate('.shopurl input','change', function(){
    		$('.shopurl_false,.shopurl_true').hide();
            $('#form-validate').find('button.submit').addClass('disabled');
    		var shopurl=$('.shopurl input').val();
    		if(shopurl!=''){			
    			$.ajax({
    				url:'<?php echo $block->getUrl('marketplace/seller/verifyUrl') ?>',
    				type:'POST',
    				data:{shopurl:shopurl},
    				dataType:'text',
    				beforeSend:function(){
    					$('#mb-ajaxloading').show();
    				},
    				success:function(data){	
    					data=JSON.parse(data);
    					$('#mb-ajaxloading').hide();
    					if(data.status){
                            $('#form-validate').find('button.submit').removeClass('disabled');
    						$('.shopurl_true').show();
    					}else{
    						$('.shopurl input').val('');
    						$('.shopurl_false').show();
    					}
    				}
    			});
    		}
    	});	
        <?php if($this->getRequest()->getParam('seller') == 'register'){ ?>
            $('#shop-name').show();
            $('#contact-number').show();
    		$('#shopurl').show();
        <?php } ?>
    	$('.wantvendor').click(function(){
    		if($(this).is(':checked')){	
    			$('#shop-name').show();
                $('#contact-number').show();
    			$('#shopurl').show();			
    		}else{
                $('#shop-name').hide();
                $('#contact-number').hide();
    			$('#shopurl').hide();
    		}
    	});	
    });
</script>
<?php if ($block->getShowAddressFields()): ?>
    <script type="text/x-magento-init">
        {
            "#country": {
                "regionUpdater": {
                    "optionalRegionAllowed": <?php /* @escapeNotVerified */ echo($block->getConfig('general/region/display_all') ? 'true' : 'false'); ?>,
                    "regionListId": "#region_id",
                    "regionInputId": "#region",
                    "postcodeId": "#zip",
                    "form": "#form-validate",
                    "regionJson": <?php /* @escapeNotVerified */ echo $this->helper('Magento\Directory\Helper\Data')->getRegionJson() ?>,
                    "defaultRegion": "<?php /* @escapeNotVerified */ echo $block->getFormData()->getRegionId() ?>",
                    "countriesWithOptionalZip": <?php /* @escapeNotVerified */ echo $this->helper('Magento\Directory\Helper\Data')->getCountriesWithOptionalZip(true) ?>
                }
            }
        }
    </script>
<?php endif; ?>