(()=>{"use strict";!function(o){function t(t,n,a){t.toggleClass("dokan-follow-store-button-working"),o.ajax({url:dokan.ajaxurl,method:"post",dataType:"json",data:{action:"dokan_follow_store_toggle_status",_nonce:a||dokanFollowStore._nonce,vendor_id:n}}).fail((function(o){var t=o.responseJSON.data.pop();dokan_sweetalert(t.message,{icon:"error"})})).always((function(){t.toggleClass("dokan-follow-store-button-working")})).done((function(a){a.data&&a.data.status&&("following"===a.data.status?t.attr("data-status","following").children(".dokan-follow-store-button-label-current").html(dokanFollowStore.button_labels.following):t.attr("data-status","").children(".dokan-follow-store-button-label-current").html(dokanFollowStore.button_labels.follow)),o("body").trigger("dokan:follow_store:changed_follow_status",{vendor_id:n,button:t,status:a.data.status})}))}o(".dokan-follow-store-button","body").on("click",(function(n){n.preventDefault();var a=o(this),l=parseInt(a.data("vendor-id"));if(!parseInt(a.data("is-logged-in")))return o("body").on("dokan:login_form_popup:fetching_form dokan:login_form_popup:fetched_form",(function(){a.toggleClass("dokan-follow-store-button-working")})),o("body").on("dokan:login_form_popup:logged_in",(function(){!function(t){o.ajax({url:dokan.ajaxurl,method:"get",dataType:"json",data:{action:"dokan_follow_store_get_current_status",vendor_id:t}}).done((function(n){o("body").trigger("dokan:follow_store:current_status",{vendor_id:t,is_following:n.data.is_following,nonce:n.data.nonce})}))}(l)})),o("body").on("dokan:follow_store:current_status",(function(o,n){n.is_following?window.location.href=window.location.href:t(a,l,n.nonce)})),o("body").on("dokan:follow_store:changed_follow_status",(function(){window.location.href=window.location.href})),void o("body").trigger("dokan:login_form_popup:show");t(a,l)}))}(jQuery)})();