document.addEventListener("DOMContentLoaded",()=>{document.querySelectorAll(".fb-animated-heading-main-wrapper").forEach(e=>{const t=e.querySelector(".fb-animated-heading-container");if(!t)return;const a=t.dataset.animationType,n=parseFloat(t.dataset.startDuration)||.5,o=parseFloat(t.dataset.endDuration)||.5,r=t.dataset.animationTransition||"power1.out",s="typing"===a?t.querySelector(".fb-animated-headings"):t.querySelector(".fb-animated-heading-dynamic-wrapper");if(!s)return;const i=Array.from(t.querySelectorAll(".fb-animated-heading-item")).map(e=>e.textContent.trim()).filter(Boolean);if(!i.length)return;if("typing"===a){s.textContent="";let e=0;const a=t.querySelector(".fb-animated-heading-cursor");a&&(a.style.opacity="1",a.style.display="inline",a.style.visibility="visible");const r=()=>{const t=i[e];let a=0;const l=()=>{a<t.length?(s.textContent+=t[a],a++,gsap.delayedCall(n,l)):gsap.delayedCall(1,d)},d=()=>{s.textContent.length>0?(s.textContent=s.textContent.slice(0,-1),gsap.delayedCall(o,d)):(e=(e+1)%i.length,r())};l()};return void r()}if("swirl"===a){let e=0;const t=()=>{s.innerHTML="";const a=i[e],l=document.createElement("span");l.className="fb-animated-heading-swirl-text",l.style.display="inline-block",s.appendChild(l);const d=[];a.split("").forEach(e=>{if(" "===e)l.appendChild(document.createTextNode(" "));else{const t=document.createElement("span");t.textContent=e,t.style.display="inline-block",t.style.opacity=0,l.appendChild(t),d.push(t)}}),gsap.fromTo(d,{opacity:0,y:20,rotation:-90},{opacity:1,y:0,rotation:0,duration:12*n,stagger:n,ease:r}),gsap.delayedCall(2.5,()=>{gsap.to(d,{opacity:0,y:-20,rotation:90,duration:10*o,stagger:o,ease:r,onComplete:()=>{l.remove(),e=(e+1)%i.length,t()}})})};return void t()}let l=0;const d=()=>{s.innerHTML="";const e=i[l],t=document.createElement("span");t.className="fb-animated-heading-text",t.textContent=e,s.appendChild(t);const c=a.includes("letter")?"letters":"words";((e,t="words")=>{const a=e.textContent;if(e.textContent="","words"===t){const t=a.split(" ");t.forEach((a,n)=>{const o=document.createElement("span");o.className="word",o.textContent=a,o.style.display="inline-block",e.appendChild(o),n<t.length-1&&e.appendChild(document.createTextNode(" "))})}else"letters"===t&&a.split("").forEach(t=>{if(" "===t)e.appendChild(document.createTextNode(" "));else{const a=document.createElement("span");a.className="char",a.textContent=t,a.style.display="inline-block",e.appendChild(a)}})})(t,c);const p=t.querySelectorAll(".word"),m=t.querySelectorAll(".char"),y=gsap.timeline({onComplete:()=>{gsap.delayedCall(1,()=>{gsap.to(t,{opacity:0,y:-30,duration:4*o,ease:r,onComplete:()=>{l=(l+1)%i.length,d()}})})}});switch(a){case"words-slide-up":y.from(p,{opacity:0,yPercent:100,duration:5*n,ease:r,stagger:n});break;case"words-rotate-in":y.set(p,{transformPerspective:1e3}),y.from(p,{rotationX:-90,duration:6*n,ease:r,stagger:n});break;case"words-slide-from-right":y.from(p,{opacity:0,x:"1em",duration:6*n,ease:r,stagger:n});break;case"letters-slide-up":y.from(m,{yPercent:100,opacity:0,duration:3*n,ease:r,stagger:n});break;case"letters-slide-down":y.from(m,{yPercent:-120,opacity:0,duration:3*n,ease:r,stagger:n});break;case"letters-fade-in":y.from(m,{opacity:0,duration:n,ease:r,stagger:n});break;case"letters-fade-in-random":y.from(m,{opacity:0,duration:n/2,ease:r,stagger:{amount:5*n,from:"random"}});break;case"scrub-each-word":y.from(p,{opacity:.2,duration:n,ease:r,stagger:{each:2*n}})}};d()})});