jQuery(document).ready(function(t){!function c(o){o(".wcwl_variation_tab").on("click",".wcwl_header_wrap",function(){o(this).next(o(".wcwl_body_wrap")).slideToggle()});o("ul.wcwl_tabs").on("click","li",function(){o(".wcwl_notice").remove();var t=o(this).closest(".wcwl_body_wrap");o(t).find("ul.wcwl_tabs li, .wcwl_tab_content").removeClass("current");var i=o(this).data("tab");o(this).addClass("current"),o(t).find(".wcwl_tab_content."+i).addClass("current")});function a(t){var i=o(t).find("tr.wcwl_user_row");return 0<i.length}function i(t){o(t).find(".wcwl_actions").hide(),o(t).find(".wcwl_waitlist_table").hide(),o(t).find(".wcwl_no_users_text ").show(),"archive"==o(t).data("panel")&&o(t).find(".wcwl_add_user_wrap").hide()}function e(t){o(t).find(".wcwl_waitlist_table").show(),o(t).find(".wcwl_no_users_text ").hide(),o(t).find("button.wcwl_email_add_user").is(":visible")||o(t).find(".wcwl_actions").show(),"archive"==o(t).data("panel")&&o(t).find(".wcwl_add_user_wrap ").show()}function n(t){(a(t)?e:i)(t),I()}o(".wcwl_tab_content").each(function(){n(this),I()});o(".wcwl_add_user_wrap").on("click",".wcwl_add",function(){var t=o(this).closest(".wcwl_tab_content");o(".wcwl_notice").remove(),o(this).hide(),t.find(".wcwl_no_users").hide(),t.find(".wcwl_add_user_content").show(),t.find(".wcwl_actions").hide()});o(".wcwl_add_user_wrap").on("click",".wcwl_back",function(t){o(".wcwl_notice").remove(),w(this)});function w(t){var i=o(t).closest(".wcwl_tab_content");i.find(".wcwl_add_user_content").hide(),i.find(".wcwl_add").show(),i.find(".wcwl_email").val(""),a(i)?(i.find(".wcwl_actions").show(),i.find(".wcwl_no_users").hide()):i.find(".wcwl_no_users").show()}o(".wcwl_add_user_wrap").on("click",".wcwl_email_add_user",function(){var t=o(this).closest(".wcwl_tab_content").find("input.wcwl_email").val().split(","),a=j(this),i=o(this).data("nonce"),e=o('.wcwl_email_add_user[data-product-id="'+a+'"]'),c=o(this).closest(".wcwl_tab_content").data("panel"),n=!1;if(x(e),o.isArray(t))o.each(t,function(t,i){if(!g(i=i.replace(/ /g,"")))return f("error",wcwl_tab.invalid_email,a,c),n=!0,y(c,"add_user",wcwl_tab.add_text),!1}),n||l(t,a,i,c);else{if(!g(t))return f("error",wcwl_tab.invalid_email,a,c),n=!0,y(c,"add_user",wcwl_tab.add_text),!1;l(t,a,i,c)}});o(".wcwl_waitlist_table").on("click",'input[name="wcwl_select_all"]',function(){var t=o(this).closest("tbody").find(".wcwl_user_checkbox"),i=o(this).prop("checked");o(t).each(function(){o(this).prop("checked",i)})});function l(t,a,i,e){var c={action:"wcwl_add_user_to_waitlist",emails:t,product_id:a,wcwl_add_user_nonce:i};o.post(ajaxurl,c,function(t){o(".wcwl_notice").remove();var i=o('.wcwl_body_wrap[data-product-id="'+a+'"] .'+e+" .wcwl_waitlist_table");d(t.data.users,a,i,e),o("#wcwl_variation_"+a).length&&_(a),f(t.data.type,t.data.message,a,e),C(e=o('.wcwl_body_wrap[data-product-id="'+a+'"]').find("."+e),".wcwl_email_add_user"),w(e.find(".wcwl_waitlist_table"))})}function s(t,i,a,e){var c=t.join_date;"archive"==e&&(c=t.date);var n='<tr class="wcwl_user_row" data-user-id="'+t.email+'">';n+='<td><input class="wcwl_user_checkbox" type="checkbox" name="wcwl_user_checkbox" value="'+t.email+'" data-user-email="'+t.email+'" data-date-added="'+c+'"/></td>',1<t.link.length?n+='<td><strong><a title="'+wcwl_tab.view_profile_text+'" href="'+t.link+'">'+t.email+"</a></strong></td>":n+="<td><strong>"+t.email+"</strong></td>",n+="<td>"+t.join_date+"</td></tr>",a.append(n)}function d(t,e,c,n){o.each(t,function(t,i){var a;0==c.find('input[data-user-email="'+i.email+'"]').length&&(s(i,e,c,n),0<(a=o("#wcwl_variation_"+e)).length&&(_(e),a.removeClass("wcwl_hidden")))})}function _(t){var i=o("#wcwl_variation_"+t+" .wcwl_count"),a=o('.wcwl_body_wrap[data-product-id="'+t+'"] .waitlist tr.wcwl_user_row').length;i.text(parseInt(a))}o(".wcwl_actions").on("click","button.wcwl_action",function(){var t,i,a,e,c=o(this).prev("select.wcwl_action").val(),n=o(this).closest(".wcwl_tab_content").data("panel"),w=j(this);c?(t=o('.wcwl_body_wrap[data-product-id="'+w+'"] .'+n+" .wcwl_user_checkbox:checkbox:checked"),i="","wcwl_email_custom"==c?0<(i=r(t)).length?window.location="mailto:"+wcwl_tab.admin_email+"?bcc="+i:f("error",wcwl_tab.no_users_text,w,n):"wcwl_export"==c?0<(i=r(t)).length?(x(this),A(i,w,n)):f("error",wcwl_tab.no_users_text,w,n):(a=u(t),e=o(this).data("nonce"),x(this),p(c,w,a,e,n))):f("error",wcwl_tab.no_action_text,w,n)});function r(t){var i="";return o(t).each(function(){i+=o(this).data("user-email")+","}),i}function u(t){var i=[];return o(t).each(function(){var t={date:o(this).data("date-added"),email:o(this).val()};i.push(t)}),i}function p(e,c,t,i,n){var a={action:e,product_id:c,users:t,wcwl_action_nonce:i};o.post(ajaxurl,a,function(t){o(".wcwl_notice").remove();var i="";"success"==t.data.type&&("wcwl_remove_waitlist"==e?(i=o('.wcwl_body_wrap[data-product-id="'+c+'"] .waitlist .wcwl_waitlist_table'),h(t.data.users,c,n,i),i.find("input").prop("checked",!1),"yes"==t.data.archive&&(i=o('.wcwl_body_wrap[data-product-id="'+c+'"] .archive .wcwl_waitlist_table'),d(t.data.users,c,i,"archive"),archive_panel=o('.wcwl_body_wrap[data-product-id="'+c+'"]').find(".archive"),C(archive_panel,".wcwl_action"))):"wcwl_remove_archive"==e?(i=o('.wcwl_body_wrap[data-product-id="'+c+'"] .archive .wcwl_waitlist_table'),h(t.data.users,c,n,i),i.find("input").prop("checked",!1)):"wcwl_return_to_waitlist"==e&&(i=o('.wcwl_body_wrap[data-product-id="'+c+'"] .waitlist .wcwl_waitlist_table'),d(t.data.users,c,i,"waitlist"),C(o('.wcwl_body_wrap[data-product-id="'+c+'"] .waitlist'),".wcwl_action"))),f(t.data.type,t.data.message,c,n);var a=o('.wcwl_body_wrap[data-product-id="'+c+'"]').find("."+n);C(a,".wcwl_action")})}function h(t,a,e,c){o.each(t,function(t,i){c.find('tr[data-user-id="'+i.email+'"]').first().remove(),i.id&&c.find('tr[data-user-id="'+i.id+'"]').first().remove(),"waitlist"==e&&o("#wcwl_variation_"+a).length&&_(a)}),0==c.find("tr.wcwl_user_row").length&&(c.hide(),c.closest(".wcwl_tab_content").find(".wcwl_no_users").show(),"archive"==e&&o('.wcwl_body_wrap[data-product-id="'+a+'"] .'+e+" .wcwl_add_user_wrap").hide())}function f(t,i,a,e){o(".wcwl_notice").remove();var c=m(t,i);"options"==e?o(c).insertBefore(o('.wcwl_body_wrap[data-product-id="'+a+'"] .options')):o(c).insertAfter(o('.wcwl_body_wrap[data-product-id="'+a+'"] .'+e+" .wcwl_actions")),"success"==t&&o(".wcwl_notice").delay(3e3).slideToggle(),b()}function m(t,i){var a='<div class="wcwl_notice wcwl_notice_'+t+'">';return a+="<p>"+i+"</p>",a+='<span class="wcwl_dismiss dashicons dashicons-dismiss"></span></div>'}function b(){o(".wcwl_notice").on("click",".wcwl_dismiss",function(){o(this).closest(".wcwl_notice").remove(),o("ul.waitlist-tabs").css("margin-top","0")})}b();{var v;0<o(".wcwl_header_wrap").length&&(v=0,o(document).ajaxSuccess(function(t,i,a,e){"string"==typeof e&&e.substring(0,35).includes("woocommerce_variation")&&(o(".wcwl_notice").remove(),1<++v&&(o("#wcwl_waitlist_data").prepend(m("info",wcwl_tab.update_waitlist_notice)),b()))}))}o(".options").on("change",'input[name="enable_stock_trigger"]',function(){o(this).is(":checked")?(o(this).closest(".options").find('input[name="minimum_stock"]').removeAttr("disabled"),o(this).closest(".options").find('label[for="minimum_stock"]').removeClass("wcwl_disabled")):(o(this).closest(".options").find('input[name="minimum_stock"]').attr("disabled","disabled"),o(this).closest(".options").find('label[for="minimum_stock"]').addClass("wcwl_disabled"))});o(".options").on("click","button",function(){x(this);var t=o(this).closest(".wcwl_tab_content"),i=j(this),a=t.find('input[name="enable_stock_trigger"]').is(":checked"),e={enable_waitlist:t.find('input[name="enable_waitlist"]').is(":checked"),enable_stock_trigger:a},c=t.find('input[name="minimum_stock"]');e.minimum_stock=a?c.val():c.data("default-stock"),c.val(e.minimum_stock),k(t,i,e)});function k(i,a,t){var e=i.find("button"),c={action:"wcwl_update_waitlist_options",product_id:a,options:t,wcwl_update_nonce:e.data("nonce")};o.post(ajaxurl,c,function(t){o(".wcwl_notice").remove(),f(t.data.type,t.data.message,a,"options"),y(i,"update_options",wcwl_tab.update_button_text)})}function g(t){var i=/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;return i.test(t)}function x(t){o(t).text(""),o(t).append('<span class="wcwl_loading spinner is-active"></span>'),o(t).attr("disabled","disabled")}function y(t,i,a){var e="";e="add_user"==i?"button.wcwl_email_add_user":"update_options"==i?".options button":"button.wcwl_action",o(t).find(o(e)).text(a),o(e).removeAttr("disabled"),o(e).find("span.wcwl_loading").remove()}function C(t,i){var a=o(t).find("button"+i),e="";type=".wcwl_email_add_user"==i?(e=wcwl_tab.add_text,"add_user"):(e=wcwl_tab.go_text,"action"),y(t,type,e),o(a).prev(".wcwl_email").val(""),o(a).prev("select.wcwl_action").val("0"),n(t)}function j(t){return o(t).closest(".wcwl_body_wrap").data("product-id")}o("#wcwl_waitlist_data").on("keyup keypress",'input.wcwl_email, input[name="minimum_stock"]',function(t){var i=t.keyCode||t.which;13===i&&(t.preventDefault(),"minimum_stock"==o(this).attr("name")?o(this).closest(".options").find("button").trigger("click"):o(this).next("button").trigger("click"))});function A(t,i,a){var e=a+"-export-"+i+".csv",c="data:text/csv;charset=utf-8,"+t,n=encodeURI(c),w=o('.wcwl_body_wrap[data-product-id="'+i+'"] .'+a),l=document.createElement("a");l.setAttribute("href",n),l.setAttribute("download",e),l.click(),y(w,"action",wcwl_tab.go_text)}var D=null;var z=null;function I(){o(".waitlist .wcwl_user_checkbox").click(function(t){M(o(".waitlist .wcwl_user_checkbox"),this,D,"waitlist",t)}),o(".archive .wcwl_user_checkbox").click(function(t){M(o(".archive .wcwl_user_checkbox"),this,z,"archive",t)})}function M(t,i,a,e,c){var n,w;a&&c.shiftKey&&(n=t.index(i),w=t.index(a),t.slice(Math.min(n,w),Math.max(n,w)+1).prop("checked",a.checked)),"waitlist"==e?D=i:z=i}0<o("#tribe_ticket_list_table").length&&o(document).ajaxSuccess(function(t,i,a,e){"string"==typeof a.data&&a.data.includes("action=tribe-ticket-edit")&&0<o("#ticket_form_table .accordion-header.woocommerce-waitlist").length&&(o("#ticket_form_table").on("click","#wcwl-tab",function(t){t.preventDefault(),o(this).addClass("is-active"),o(this).next("section").addClass("is-active")}),o("#ticket_form_table").on("click","#wcwl-tab.is-active",function(t){t.preventDefault(),o(this).removeClass("is-active"),o(this).next("section").removeClass("is-active")}),c(o))})}(t)});