(()=>{class t{constructor(t){this.wrapper=t,this.expirationDateWrapper=this.wrapper.querySelector(".wpcd-coupon-expiration-date"),this.copyButton=this.wrapper.querySelector(".wpcd-coupon-button:not(.wpcd-popup-button)"),this.showCodeButton=this.wrapper.querySelector(".wpcd-coupon-button.wpcd-popup-button"),this.expirationDate=new Date(this.wrapper.dataset.expiration_date).getTime(),this.expiredDateText=this.wrapper.dataset.expired_date_text,this.couponCode=this.wrapper.dataset.coupon_code,this.couponId=this.wrapper.getAttribute("data-coupon_id"),this.init()}init(){this.checkExpirationDate(),this.setupCopyButton(),this.handleTemplateTwoExpirationDate(),this.wrapper.classList.contains("wpcd-coupon-hidden")&&this.showCodeButton&&(this.wasRecentlyRevealed()?this.revealCouponInline(!1):this.handleShowCode())}handleTemplateTwoExpirationDate(){if(!this.wrapper.classList.contains("wpcd-coupon-template-two")&&!this.wrapper.classList.contains("wpcd-coupon-template-seven")&&!this.wrapper.classList.contains("wpcd-coupon-template-six"))return;if(this.expirationDateWrapper.classList.contains("wpcd-coupon-does-not-expire"))return;const t=this.expirationDateWrapper.querySelectorAll("span")[1];if(!t)return;const e=()=>{const e=(new Date).getTime(),o=this.expirationDate-e;if(o<0)return void(t.textContent=this.expiredDateText);const n=Math.floor(o/6048e5),i=Math.floor(o%6048e5/864e5),p=Math.floor(o%864e5/36e5),s=Math.floor(o%36e5/6e4),a=Math.floor(o%6e4/1e3);t.textContent=`${n} weeks ${i} days ${p} hours ${s} minutes ${a} seconds`};e(),setInterval(e,1e3)}wasRecentlyRevealed(){try{const t=JSON.parse(localStorage.getItem("wpcd_revealed")||"{}")[this.couponId];return!!t&&Date.now()-t<18e5}catch(t){return!1}}markCouponAsRevealed(){try{const t=JSON.parse(localStorage.getItem("wpcd_revealed")||"{}");t[this.couponId]=Date.now(),localStorage.setItem("wpcd_revealed",JSON.stringify(t))}catch(t){}}handleShowCode(){this.showCodeButton.addEventListener("click",(t=>{t.preventDefault();const e=this.showCodeButton.getAttribute("href");if(this.copyToClipboard(),this.markCouponAsRevealed(),this.revealCouponInline(!0),e){const t=document.createElement("a");t.href=e,t.rel="nofollow noopener",t.target="_blank",document.body.appendChild(t),t.click(),document.body.removeChild(t)}}),{once:!0})}revealCouponInline(t){this.wrapper.classList.remove("wpcd-coupon-hidden"),this.showCodeButton.classList.remove("wpcd-popup-button"),this.showCodeButton.setAttribute("rel","nofollow noopener"),this.showCodeButton.setAttribute("target","_blank"),this.copyButton=this.showCodeButton,this.showCodeButton=null,t?(this.copyButton.innerText="Copied!",setTimeout((()=>{this.copyButton.innerText=this.couponCode,this.setupCopyButton()}),1e3)):this.setupCopyButton()}checkExpirationDate(){this.expirationDateWrapper.classList.contains("wpcd-coupon-does-not-expire")||Date.now()>this.expirationDate&&(this.expirationDateWrapper.textContent=this.expiredDateText,this.expirationDateWrapper.classList.add("wpcd-coupon-expired"))}setupCopyButton(){if(!this.copyButton)return;const t=this.copyButton.innerText;this.copyButton.addEventListener("click",(()=>{this.copyButton.innerText="Copied!",this.copyToClipboard(),setTimeout((()=>{this.copyButton.innerText=t.trim()}),1e3)}))}async copyToClipboard(){const t=document.createElement("input");t.value=this.couponCode,t.type="text",document.body.appendChild(t),t.select(),document.execCommand("Copy"),document.body.removeChild(t)}}window.addEventListener("DOMContentLoaded",(()=>{document.querySelectorAll(".wpcd-coupon-wrapper:not(.wpcd-coupon-type-deal)").forEach((e=>{new t(e)}))}))})();