!function(){"use strict";var e;document.querySelectorAll(".js-app-store").forEach(function(e){e.setAttribute("href","https://apps.apple.com/us/app/wellypal-ai-calorie-counter/id6759787106")}),e=(window.location.pathname||"").replace(/\\/g,"/"),/faq\.html$/i.test(e)&&document.querySelectorAll(".site-footer.site-footer--desktop a").forEach(function(e){var t=(e.getAttribute("href")||"").trim();("faq.html"===t||/(^|\/)faq\.html(\?.*)?$/i.test(t))&&e.addEventListener("click",function(e){e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||0!==e.button||(e.preventDefault(),window.scrollTo({top:0,left:0,behavior:"smooth"}))})});var t=document.querySelector("[data-menu-toggle]"),n=document.querySelector("[data-mobile-menu]"),a=document.querySelector("[data-menu-scrim]"),r=document.querySelector("[data-mobile-header]");function i(){if(a&&r){var e=r.getBoundingClientRect().bottom;a.style.top=Math.max(0,Math.round(e))+"px"}}function o(e){document.body.classList.toggle("menu-open",e),t&&t.setAttribute("aria-expanded",e?"true":"false"),n&&n.setAttribute("aria-hidden",e?"false":"true"),e?i():a&&(a.style.top="")}function c(){document.body.classList.contains("menu-open")&&i()}t&&n&&t.addEventListener("click",function(){o(!document.body.classList.contains("menu-open"))}),a&&a.addEventListener("click",function(){o(!1)}),window.addEventListener("resize",c),window.addEventListener("scroll",c,!0),document.addEventListener("keydown",function(e){"Escape"===e.key&&document.body.classList.contains("menu-open")&&o(!1)}),document.querySelectorAll("[data-mobile-nav]").forEach(function(e){e.addEventListener("click",function(){o(!1)})});var s=document.querySelector("[data-faq-page]");if(s){var l=s.querySelectorAll("[data-faq-panel]"),u=s.querySelector("[data-faq-dropdown]"),d=u?u.querySelector(".faq-dropdown__toggle"):null,f=u?u.querySelector(".faq-dropdown__list"):null,m=u?u.querySelector(".faq-dropdown__current"):null,v=s.querySelector("[data-faq-sticky]");function _(){u&&d&&f&&(u.classList.remove("is-open"),f.hidden=!0,d.setAttribute("aria-expanded","false"))}function I(e){var t=s.querySelector('.faq-sidebar-desktop__btn[data-faq-cat="'+e+'"] .faq-sidebar-desktop__label');return t?t.textContent.trim():""}function k(e){if(l.forEach(function(t){parseInt(t.getAttribute("data-faq-panel"),10)===e?t.removeAttribute("hidden"):t.setAttribute("hidden","")}),s.querySelectorAll(".faq-sidebar-desktop__btn[data-faq-cat]").forEach(function(t){var n=parseInt(t.getAttribute("data-faq-cat"),10)===e;t.classList.toggle("faq-sidebar-desktop__btn--active",n),n?t.setAttribute("aria-current","true"):t.removeAttribute("aria-current")}),s.querySelectorAll(".faq-pill[data-faq-cat]").forEach(function(t){var n=parseInt(t.getAttribute("data-faq-cat"),10);t.classList.toggle("faq-pill--active",n===e)}),s.querySelectorAll(".faq-dropdown__option[data-faq-cat]").forEach(function(t){var n=parseInt(t.getAttribute("data-faq-cat"),10)===e;t.classList.toggle("faq-dropdown__option--active",n),t.setAttribute("aria-selected",n?"true":"false")}),m){var t=I(e);t&&(m.textContent=t)}window.scrollTo({top:0,left:0,behavior:"smooth"}),_()}function j(){v&&v.classList.toggle("is-scrolled",window.scrollY>8)}s.addEventListener("click",function(e){var t=e.target.closest("[data-faq-cat]");if(t&&s.contains(t)){var n=parseInt(t.getAttribute("data-faq-cat"),10);Number.isNaN(n)||(e.preventDefault(),k(n))}}),d&&d.addEventListener("click",function(e){e.preventDefault(),e.stopPropagation(),f&&(f.hidden?u&&d&&f&&(u.classList.add("is-open"),f.hidden=!1,d.setAttribute("aria-expanded","true")):_())}),document.addEventListener("pointerdown",function(e){u&&u.classList.contains("is-open")&&(u.contains(e.target)||_())}),document.addEventListener("keydown",function(e){"Escape"===e.key&&u&&u.classList.contains("is-open")&&_()}),j(),window.addEventListener("scroll",j,{passive:!0}),window.addEventListener("resize",function(){_()})}var p=document.querySelectorAll(".reveal");if(p.length&&"IntersectionObserver"in window){var b=new IntersectionObserver(function(e){e.forEach(function(e){e.isIntersecting&&(e.target.classList.add("is-visible"),b.unobserve(e.target))})},{root:null,threshold:.12,rootMargin:"0px 0px -40px 0px"});p.forEach(function(e){b.observe(e)})}else p.forEach(function(e){e.classList.add("is-visible")});var h=/^(features|reviews|contact)$/;function y(e,t){var n=function(e){var t=window.matchMedia("(max-width: 1199.98px)").matches;return"features"===e?document.getElementById(t?"features-mobile":"features")||document.getElementById("features")||document.getElementById("features-mobile"):"reviews"===e?document.getElementById(t?"reviews-mobile":"reviews")||document.getElementById("reviews")||document.getElementById("reviews-mobile"):"contact"===e?document.getElementById(t?"contact-mobile":"contact")||document.getElementById("contact")||document.getElementById("contact-mobile"):document.getElementById(e)}(e);if(!n)return!1;var a=!1!==t,r=window.matchMedia("(min-width: 1200px)").matches,i=r?88:72,o="features"===e?r?-24:-50:20,c=window.scrollY+n.getBoundingClientRect().top-i+o;return window.scrollTo({top:Math.max(0,c),behavior:a?"smooth":"auto"}),!0}function g(){var e=function(){var e=(window.location.hash||"").replace(/^#/,""),t=e.split("?")[0]||"";if(h.test(t))return t;if(0===e.indexOf("/")){var n=e.indexOf("?");if(n>=0){var a=(new URLSearchParams(e.slice(n+1)).get("section")||"").toLowerCase();if(h.test(a))return a}}return""}();e&&h.test(e)&&requestAnimationFrame(function(){requestAnimationFrame(function(){y(e,!0)})})}document.body.classList.contains("page-home")&&(g(),window.addEventListener("hashchange",g));var q=/^[a-zA-Z0-9](?:[a-zA-Z0-9._+-]*[a-zA-Z0-9])?$/;function w(e){return!(0===e.length||e.length>63)&&(!!/^[a-zA-Z]+$/.test(e)||(!!/^[0-9]+$/.test(e)||/^(?=.*[a-zA-Z])(?=.*[0-9])[a-zA-Z0-9]+$/.test(e)))}function E(e){var t=e.trim();return t?function(e){if(e.length>254)return!1;if(!/^[\x21-\x7E]+$/.test(e))return!1;if(e.split("@").length-1!=1)return!1;var t=e.indexOf("@"),n=e.slice(0,t),a=e.slice(t+1);if(!n.length||!a.length||a.startsWith(".")||a.endsWith("."))return!1;if(!q.test(n))return!1;if(n.length>64||n.includes("..")||n.startsWith(".")||n.endsWith("."))return!1;var r=a.split(".");if(r.length<2)return!1;for(var i=0;i=2}(t)?"":"Enter a valid or alternate email address.":"Please enter your email address."}function L(e){return e.trim()?"":"Enter a subject"}function A(e){return e.trim()?"":"Enter a comment."}function S(e,t,n){var a=e.querySelector('[name="'+t+'"]'),r=a?a.closest(".contact-field-wrap"):null,i=r?r.querySelector('[data-error-for="'+t+'"]'):null;if(a&&i){var o=i.querySelector(".contact-error__text");n?("TEXTAREA"===a.tagName?a.classList.add("contact-textarea--error"):a.classList.add("contact-input--error"),a.setAttribute("aria-invalid","true"),i.id&&a.setAttribute("aria-describedby",i.id),o&&(o.textContent=n),i.hidden=!1):(a.classList.remove("contact-input--error","contact-textarea--error"),a.removeAttribute("aria-invalid"),a.removeAttribute("aria-describedby"),o&&(o.textContent=""),i.hidden=!0)}}function x(e){if(e){var t=e.querySelector("[data-contact-success]"),n=e.querySelector('[name="email"]'),a=e.querySelector('[name="subject"]'),r=e.querySelector('[name="message"]'),i=e.querySelector('button[type="submit"]'),o=!1;["email","subject","message"].forEach(function(t){var n=e.querySelector('[name="'+t+'"]');n&&n.addEventListener("input",function(){!function(t){S(e,t,"")}(t)})}),n&&n.addEventListener("blur",function(){S(e,"email",E(n.value)||"")}),a&&a.addEventListener("blur",function(){S(e,"subject",L(a.value)||"")}),r&&r.addEventListener("blur",function(){S(e,"message",A(r.value)||"")}),e.addEventListener("submit",async function(c){if(c.preventDefault(),!o){var s=n?n.value:"",l=a?a.value:"",u=r?r.value:"",d=function(e,t,n){var a={},r=E(e);return r&&(a.email=r),(r=L(t))&&(a.subject=r),(r=A(n))&&(a.message=r),a}(s,l,u);if(S(e,"email",d.email||""),S(e,"subject",d.subject||""),S(e,"message",d.message||""),!Object.keys(d).length){t&&(t.hidden=!0),o=!0;var f=i?i.innerText:"";i&&(i.disabled=!0,i.innerText="Sending...");try{var m=await fetch("https://api.wellypal.com/api/app/contact/submit",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:s,subject:l,content:u,name:"test"})}),v=await m.json();v&&0===v.code?(e.reset(),t&&(t.hidden=!1)):alert("The server is busy, please try again later")}catch(e){console.error("Error:",e),alert("The server is busy, please try again later")}finally{o=!1,i&&(i.disabled=!1,i.innerText=f)}}}})}}x(document.querySelector("[data-contact-form]")),x(document.querySelector("[data-contact-form-mobile]"))}();