!function(){"use strict";var t=window.ctFrontend;const s=function(t,s,e){const i=t.querySelectorAll(".ct-waitlist-users");i.length&&i.forEach(function(t){t.dataset.count=s,t.innerHTML=e})},e=function(t,e){if(!e||e.blocksy_stock_quantity>0||e.is_in_stock&&!e.backorders_allowed||e.backorders_allowed&&"no"===ct_localizations.blc_ext_waitlist.waitlist_allow_backorders)t.dataset.state="hidden";else{if(e.blocksy_waitlist.subscription_id||ct_localizations.blc_ext_waitlist.list.includes(e.variation_id)){t.dataset.state="subscribed";const i=t.querySelector(".unsubscribe");return i&&(i.dataset.token=e.blocksy_waitlist.unsubscribe_token,i.dataset.id=e.variation_id),void s(t,e.blocksy_waitlist.waitlist_users,e.blocksy_waitlist.waitlist_users_message)}s(t,e.blocksy_waitlist.waitlist_users,e.blocksy_waitlist.waitlist_users_message),t.dataset.state="visible"}},i=function(t,s=!1){const{blc_ext_waitlist:{user_logged_in:e,list:i}}=ct_localizations;if("no"!==e)return;const a=s?i.filter(function(s){return s!==t}):[...i,t];ct_localizations.blc_ext_waitlist.list=a;const o=new Date(Date.now()+31536e6).toGMTString();document.cookie=`blc_products_waitlist=${JSON.stringify(a)}; expires=${o}; path=/`},a=function(t){const e=new FormData;e.append("action","blc_waitlist_unsubscribe"),e.append("token",t.dataset.token);const a=t.closest(".waitlist-product-actions, .waitlist-product-mobile-actions")||t.closest(".ct-product-waitlist");a.dataset.loading="";const o=t.closest(".product");let c="";if(o){c=o.className.match(/post-(\d+)/)?.[1];const t=o.querySelector('[name="variation_id"]');t&&t.value&&(c=t.value)}e.append("product_id",c),fetch(ct_localizations.ajax_url,{method:"POST",body:e}).then(function(t){return t.json()}).then(function({success:e,data:o}){e?(a.dataset.state="",s(a,o.waitlist_users,o.waitlist_users_message),i(t.dataset.id,!0),function(t){const s=t.closest(".ct-woocommerce-waitlist-table-row");if(!s)return;1===document.querySelectorAll(".ct-woocommerce-waitlist-table-row").length?window.location.reload():s.remove()}(t)):alert(o.message)}).finally(function(){a.removeAttribute("data-loading")})};(0,t.registerDynamicChunk)("blocksy_ext_woo_extra_waitlist",{mount:function(t,o){if(!o)return void function(t){const s=t.closest(".product");let i=s.className.match(/post-(\d+)/)?.[1];const a=s.querySelector('[name="variation_id"]');a&&a.value&&(i=a.value);const o=new FormData;o.append("action","blc_waitlist_sync"),o.append("product_id",i),fetch(ct_localizations.ajax_url,{method:"POST",body:o}).then(function(t){return t.json()}).then(function({success:s,data:i}){i.subscription_id&&s&&e(t.closest(".ct-product-waitlist"),{blocksy_waitlist:{...i}})})}(t);const{event:c,eventData:n}=o;"submit"!==c.type?"click"===c.type&&t.classList.contains("unsubscribe")?a(t):"reset_data"!==c.type&&"found_variation"!==c.type||e(t,n):function(t){const e=new FormData(t);e.append("action","blc_subcribe_to_waitlist");const a=t.closest(".ct-product-waitlist");a.dataset.loading="";const o=t.closest(".product");let c=o.className.match(/post-(\d+)/)?.[1];const n=o.querySelector('[name="variation_id"]');n&&n.value&&(c=n.value),e.append("product_id",c),fetch(ct_localizations.ajax_url,{method:"POST",body:e}).then(function(t){return t.json()}).then(function({success:e,data:o}){e?(a.dataset.state="subscribed",s(a,o.waitlist_users,o.waitlist_users_message),i(o.subscription_id),function(t,s){const e=t.closest(".ct-product-waitlist").querySelector(".unsubscribe");e&&(e.dataset.token=s.token,e.dataset.id=s.productId)}(t,{token:o.unsubscribe_token,productId:c})):alert(o.message)}).finally(function(){a.removeAttribute("data-loading")})}(t)}})}();