<?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
 */
?>
<div id="messages" class="success_profile_msg" style="display:none;margin-bottom:0px;margin-top:2px;">
    <div class="messages">
        <div class="message message-success success">
            <div data-ui-id="messages-message-success">
                <?= $block->escapeHtml(__("Shop name is available.")); ?>
            </div>
        </div>
    </div>
</div>
<div id="messages" class="error_profile_msg" style="display:none;margin-bottom:0px;margin-top:2px;">
    <div class="messages">
        <div class="message message-error error">
            <div data-ui-id="messages-message-error">
                <?= $block->escapeHtml(__("Shop name is already exists.")); ?>
            </div>
        </div>
    </div>
</div>
<script>
    require([
        "jquery",
        "mage/mage",
        "prototype"
    ], function($){
        $("input[type='file']").attr('form','customer_form');
        $("#marketplace_profileurl").keyup(function(){
            $(this).val($(this).val().replace(/[^a-z^A-Z^0-9\.\-]/g,""));
        });
        $("#marketplace_profileurl").on('change',function(){
            $('.success_profile_msg').hide();
            $('.error_profile_msg').hide();
            var profileurl = $(this).val();
            var self = $(this);
            if(profileurl != ''){
                new Ajax.Request('<?= $block->escapeUrl($block->getAjaxCheckUrl()) ?>', {
                    method: 'post',
                    parameters:{profileurl:profileurl},
                    onSuccess: function(transport){
                        console.log(transport.responseJSON);
                        if(transport.responseJSON == 0){
                            self.after($('.success_profile_msg').show());
                        }else{
                            self.after($('.error_profile_msg').show());
                        }
                    }
                });
            }
        });
    });
</script>
