!function(){"use strict";function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t(e)}function e(e){var o=function(e,o){if("object"!=t(e)||!e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var s=i.call(e,o||"default");if("object"!=t(s))return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===o?String:Number)(e)}(e,"string");return"symbol"==t(o)?o:o+""}function o(t,o,i){return(o=e(o))in t?Object.defineProperty(t,o,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[o]=i,t}var i=window.ctFrontend;function s(t,e){var o=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),o.push.apply(o,i)}return o}function n(t){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?s(Object(i),!0).forEach(function(e){o(t,e,i[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):s(Object(i)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))})}return t}const a=function(t,e,o){const i=t.querySelectorAll(".ct-waitlist-users");i.length&&i.forEach(function(t){t.dataset.count=e,t.innerHTML=o})},c=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 o=t.querySelector(".unsubscribe");return o&&(o.dataset.token=e.blocksy_waitlist.unsubscribe_token,o.dataset.id=e.variation_id),void a(t,e.blocksy_waitlist.waitlist_users,e.blocksy_waitlist.waitlist_users_message)}a(t,e.blocksy_waitlist.waitlist_users,e.blocksy_waitlist.waitlist_users_message),t.dataset.state="visible"}},r=function(t,e=!1){const{blc_ext_waitlist:{user_logged_in:o,list:i}}=ct_localizations;if("no"!==o)return;const s=e?i.filter(function(e){return e!==t}):[...i,t];ct_localizations.blc_ext_waitlist.list=s;const n=new Date(Date.now()+31536e6).toGMTString();document.cookie=`blc_products_waitlist=${JSON.stringify(s)}; expires=${n}; path=/`},l=function(t){const e=new FormData;e.append("action","blc_waitlist_unsubscribe"),e.append("token",t.dataset.token);const o=t.closest(".waitlist-product-actions, .waitlist-product-mobile-actions")||t.closest(".ct-product-waitlist");o.dataset.loading="";const i=t.closest(".product");let s="";if(i){var n;s=null===(n=i.className.match(/post-(\d+)/))||void 0===n?void 0:n[1];const t=i.querySelector('[name="variation_id"]');t&&t.value&&(s=t.value)}e.append("product_id",s),fetch(ct_localizations.ajax_url,{method:"POST",body:e}).then(function(t){return t.json()}).then(function({success:e,data:i}){e?(o.dataset.state="",a(o,i.waitlist_users,i.waitlist_users_message),r(t.dataset.id,!0),function(t){const e=t.closest(".ct-woocommerce-waitlist-table-row");if(!e)return;1===document.querySelectorAll(".ct-woocommerce-waitlist-table-row").length?window.location.reload():e.remove()}(t)):alert(i.message)}).finally(function(){o.removeAttribute("data-loading")})};(0,i.registerDynamicChunk)("blocksy_ext_woo_extra_waitlist",{mount:function(t,e){if(!e)return void function(t){var e;const o=t.closest(".product");let i=null===(e=o.className.match(/post-(\d+)/))||void 0===e?void 0:e[1];const s=o.querySelector('[name="variation_id"]');s&&s.value&&(i=s.value);const a=new FormData;a.append("action","blc_waitlist_sync"),a.append("product_id",i),fetch(ct_localizations.ajax_url,{method:"POST",body:a}).then(function(t){return t.json()}).then(function({success:e,data:o}){o.subscription_id&&e&&c(t.closest(".ct-product-waitlist"),{blocksy_waitlist:n({},o)})})}(t);const{event:o,eventData:i}=e;"submit"!==o.type?"click"===o.type&&t.classList.contains("unsubscribe")?l(t):"reset_data"!==o.type&&"found_variation"!==o.type||c(t,i):function(t){var e;const o=new FormData(t);o.append("action","blc_subcribe_to_waitlist");const i=t.closest(".ct-product-waitlist");i.dataset.loading="";const s=t.closest(".product");let n=null===(e=s.className.match(/post-(\d+)/))||void 0===e?void 0:e[1];const c=s.querySelector('[name="variation_id"]');c&&c.value&&(n=c.value),o.append("product_id",n),fetch(ct_localizations.ajax_url,{method:"POST",body:o}).then(function(t){return t.json()}).then(function({success:e,data:o}){e?(i.dataset.state="subscribed",a(i,o.waitlist_users,o.waitlist_users_message),r(o.subscription_id),function(t,e){const o=t.closest(".ct-product-waitlist").querySelector(".unsubscribe");o&&(o.dataset.token=e.token,o.dataset.id=e.productId)}(t,{token:o.unsubscribe_token,productId:n})):alert(o.message)}).finally(function(){i.removeAttribute("data-loading")})}(t)}})}();