$(function(){if($(document).on("click","input[name=is_vendor]",function(e){var a=$(e.currentTarget);1==a.val()?$('[data-bb-toggle="vendor-info"]').slideDown():($('[data-bb-toggle="vendor-info"]').slideUp(),a.closest("form").find("button[type=submit]").prop("disabled",!1))}),$('form.js-base-form input[name="shop_url"]').on("change",function(e){var a=$(e.currentTarget),t=a.closest("form"),n=a.val();if(n){var i=t.find("[data-slug-value]");$.ajax({url:a.data("url"),type:"POST",data:{url:n},beforeSend:function(){a.prop("disabled",!0),t.find("button[type=submit]").prop("disabled",!0)},success:function(e){var n=e.error,s=e.message,o=e.data;n?(a.addClass("is-invalid").removeClass("is-valid"),$(".shop-url-status").removeClass("text-success").addClass("text-danger").text(s)):(a.removeClass("is-invalid").addClass("is-valid"),$(".shop-url-status").removeClass("text-danger").addClass("text-success").text(s),t.find("button[type=submit]").prop("disabled",!1)),null!=o&&o.slug&&i.html("".concat(i.data("base-url"),"/<strong>").concat(o.slug.substring(0,100).toLowerCase(),"</strong>"))},complete:function(){return a.prop("disabled",!1)}})}}),$(".become-vendor-form").length){var e=null,a=null;$("#certificate-dropzone").length&&(e=new Dropzone("#certificate-dropzone",{url:"#",autoProcessQueue:!1,paramName:"certificate_file",maxFiles:1,acceptedFiles:".pdf,.jpg,.jpeg,.png,.webp",addRemoveLinks:!0,dictDefaultMessage:$("#certificate-dropzone").data("placeholder"),maxfilesexceeded:function(e){this.removeFile(e)}})),$("#government-id-dropzone").length&&(a=new Dropzone("#government-id-dropzone",{url:"#",autoProcessQueue:!1,paramName:"government_id_file",maxFiles:1,acceptedFiles:".pdf,.jpg,.jpeg,.png,.webp",addRemoveLinks:!0,dictDefaultMessage:$("#government-id-dropzone").data("placeholder"),maxfilesexceeded:function(e){this.removeFile(e)}})),$("form.become-vendor-form").on("submit",function(t){t.preventDefault();var n=$(t.currentTarget),i=new FormData(n.get(0));e&&e.getQueuedFiles().length>0&&i.append("certificate_file",e.getQueuedFiles()[0]),a&&a.getQueuedFiles().length>0&&i.append("government_id_file",a.getQueuedFiles()[0]),$.ajax({url:n.prop("action"),type:"POST",data:i,processData:!1,contentType:!1,success:function(e){var a=e.data;null!=a&&a.redirect_url&&(window.location.href=a.redirect_url)},error:function(e){var a=e.responseJSON.errors;n.find("input").removeClass("is-invalid").removeClass("is-valid"),n.find(".invalid-feedback").remove(),a&&Object.keys(a).forEach(function(e){var t=n.find('input[name="'.concat(e,'"]')),i=a[e];if(["certificate_file","government_id_file"].includes(e)){var s=n.find('[data-field-name="'.concat(e,'"]'));s.find(".invalid-feedback").remove(),s.append('<div class="invalid-feedback" style="display: block">'.concat(i,"</div>"))}else t.addClass("is-invalid").removeClass("is-valid"),t.is(":checkbox")||t.parent().append('<div class="invalid-feedback">'.concat(i,"</div>"))})}})})}});