File: /home/lgooir/public_html/wp-content/themes/woodmart/js/scripts/wc/ptSubscribeForm.min.js
woodmartThemeModule.ptSubscribeForm=function(){var a=[],s=[];function c(e){var t=w();t.variationId&&s.includes(t.variationId)&&e.classList.remove("wd-hide")}function u(e,t){var r=f(),n=y();r&&(n&&m(t.variation_id),d(t.variation_id),t.is_in_stock?r.classList.remove("wd-hide"):r.classList.add("wd-hide"),L())}function l(e){f().classList.add("wd-hide"),L()}function p(e){var t,r;this.classList.contains("wd-pt-remove")||(e.preventDefault(),y()&&!function(){var e=y();if(!e)return;var t=e.querySelector('[name="wd-pt-policy-check"]'),r=e.querySelector('[name="wd-pt-desired-price-check"]'),e=e.querySelector('[name="wd-pt-user-desired-price"]'),n=h();if(t&&!t.checked&&n)return void _(n,woodmart_settings.pt_policy_check_msg,"warning");if(r&&e&&r.checked&&!parseInt(e.value))return void _(n,woodmart_settings.pt_desired_price_check_msg,"warning");return 1}())||(e=w(),t=function(){var e="",t=document.querySelector('[name="wd-pt-user-subscribe-email"]');t&&(e=t.value);return e}(),r=function(){var e="",t=document.querySelector('[name="wd-pt-user-desired-price"]');t&&(e=t.value);return e}(),n({action:"woodmart_add_to_price_tracker",security:woodmart_settings.pt_add_button_nonce,user_email:t,product_id:e.productId,variation_id:e.variationId,desired_price:r}))}function v(e){var t;this.classList.contains("wd-pt-remove")&&(e.preventDefault(),e=w(),t=parseInt(e.productId),e=parseInt(e.variationId),n({action:"woodmart_remove_from_price_tracker",security:woodmart_settings.pt_remove_button_nonce,product_id:t,variation_id:e}))}function d(e){var t=f(),r=y(),n=t.querySelector("a"),o=n.querySelector(".wd-action-text");s.includes(e)?(o.innerText=woodmart_settings.pt_button_text_stop_tracking,n.href="#",n.classList.remove("added"),t.classList.add("wd-pt-remove"),t.classList.remove("wd-pt-add"),t.addEventListener("click",v),n.classList.remove("wd-open-popup")):a.includes(e)?(o.innerText=woodmart_settings.pt_button_text_watch_tracking,n.href=woodmart_settings.pt_endpoint_url,n.classList.add("added"),t.classList.remove("wd-pt-remove"),t.classList.remove("wd-pt-add"),t.removeEventListener("click",p),n.classList.remove("wd-open-popup")):(o.innerText=woodmart_settings.pt_button_text_not_tracking,t.classList.remove("wd-pt-remove"),n.classList.remove("wd-open-popup"),n.classList.remove("added"),r?(n.href="#wd-popup-pt",n.classList.add("wd-open-popup")):(n.href="#",t.classList.add("wd-pt-add"),t.addEventListener("click",p)))}function m(e){var t=y();a.includes(e)?(t.querySelector(".wd-pt-signed").classList.remove("wd-hide"),t.querySelector(".wd-pt-not-signed").classList.add("wd-hide")):(t.querySelector(".wd-pt-signed").classList.add("wd-hide"),t.querySelector(".wd-pt-not-signed").classList.remove("wd-hide"))}function n(e){var n=y(),o=h(),t=f().querySelector("a"),r=w(),i=r.variationId||r.productId;L(),n&&n.querySelector(".wd-loader-overlay").classList.add("wd-loading"),t.classList.add("loading"),jQuery.ajax({url:woodmart_settings.ajaxurl,data:e,method:"POST",success:function(e){var t,r;e&&e.hasOwnProperty("data")&&(e.data.notice&&o&&(t=e.data.success?"success":"warning",_(o,e.data.notice,t)),e.data.state&&(t=e.data.state,r=i,"signed"===t?a.includes(r)||a.push(r):"not-signed"===t&&(a.includes(r)&&(a=a.filter(function(e){return e!==r})),s.includes(r))&&(s=s.filter(function(e){return e!==r}))),n&&m(i),d(i))},error:function(){console.error("ajax adding to price tracker error")},complete:function(){n&&n.querySelector(".wd-loader-overlay").classList.remove("wd-loading"),t.classList.remove("loading")}})}function w(){var t=!1,e=(document.querySelector('body[class*="postid-"]').classList.forEach(function(e){e.includes("postid-")&&(t=e.replace("postid-",""))}),g()),r=0;return e&&(r=(e=e.querySelector("input.variation_id")).value?parseInt(e.value):0),{productId:parseInt(t),variationId:parseInt(r)}}function _(e,t,r){var n;e&&(L(),(n=document.createElement("div")).classList.add("wd-notice","wd-"+r),n.append(t),e.append(n))}function f(){return document.querySelector(".wd-pt-btn")}function y(){return document.querySelector("#wd-popup-pt")}function g(){return document.querySelector(".variations_form")}function h(){var e=y();return e&&e.closest(".mfp-ready")?e:document.querySelector(".woocommerce-notices-wrapper")}function L(t=""){var e=h();e&&0!==(e=e.querySelectorAll(".wd-notice")).length&&e.forEach(e=>{t&&!e.innerText.includes(t)||e.remove()})}!async function(){var e,t,r,n,o,i,d=f();d&&("yes"===woodmart_settings.pt_fragments_enable?(o=await async function(e){try{return await jQuery.ajax({url:woodmart_settings.ajaxurl,data:{action:"woodmart_update_price_tracker_form",product_id:e},dataType:"json",method:"GET"})}catch(e){console.error("Error updating form data:",e)}}((i=w()).productId))&&(o.signed_variations&&0<o.signed_variations.length?s=o.signed_variations:o.is_signed&&(s.push(i.productId),a.push(i.productId)),d.classList.remove("wd-disabled")):g()&&(s=JSON.parse(d.dataset.signedVariations||"[]")),c(d),o=f(),i=y(),d=g(),o)&&(o.classList.contains("wd-pt-remove")&&o.addEventListener("click",v),i?(e=i.querySelector(".wd-pt-add"),t=i.querySelector('[name="wd-pt-policy-check"]'),r=i.querySelector('[name="wd-pt-desired-price-check"]'),n=i.querySelector('[name="wd-pt-user-desired-price"]'),i=i.querySelector(".wd-close-popup"),e.addEventListener("click",p),jQuery(document).one("mfpClose",function(){L()}),t&&t.addEventListener("change",function(){t.checked&&L(woodmart_settings.pt_policy_check_msg)}),r&&n&&(n.addEventListener("click",function(e){r.checked=!0}),r.addEventListener("change",function(){r.checked?n.focus():n.value=""})),i.addEventListener("click",function(e){e.preventDefault(),jQuery.magnificPopup.close()})):o.classList.contains("wd-pt-add")&&o.addEventListener("click",p),d)&&jQuery(".variations_form").off("show_variation",u).on("show_variation",u).off("click",".reset_variations",l).on("click",".reset_variations",l)}()},window.addEventListener("load",function(){woodmartThemeModule.ptSubscribeForm()});