import*as t from"@wordpress/interactivity";var s={d:(t,e)=>{for(var n in e)s.o(e,n)&&!s.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},o:(t,s)=>Object.prototype.hasOwnProperty.call(t,s)};const e=(n={getContext:()=>t.getContext,getElement:()=>t.getElement,store:()=>t.store},r={},s.d(r,n),r);var n,r;function o(t){if("object"==typeof GatherPress)return t.split(".").reduce((t,s)=>t?.[s],GatherPress)}function a(t){return new URLSearchParams(location.search).get(t)}function u(t,s){var e;t.posts=null!==(e=t.posts)&&void 0!==e?e:[],s&&!t.posts[s]&&(t.posts[s]={eventResponses:{attending:0,waitingList:0,notAttending:0},currentUser:{status:"no_status",guests:0,anonymous:0},rsvpSelection:"attending"})}const c=(()=>{let t=null,s=null;const e=async function(){return t||s||(s=fetch(o("urls.eventApiUrl")+"/nonce",{method:"GET",credentials:"same-origin"}).then(t=>t.json()).then(e=>(t=e.nonce,s=null,e.nonce)).catch(()=>(s=null,null)),s)};return e.clearCache=()=>{t=null,s=null},e})();async function l(t,s,e=null,n=null,r=null){if(["no_status","waiting_list"].includes(s.status))return;r&&r.classList.add("gatherpress--is-loading");const a=async(e=!1)=>{const n=await c();if(!n)return;const r=await fetch(o("urls.eventApiUrl")+"/rsvp",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":n},body:JSON.stringify({post_id:t,status:s.status,guests:s.guests,anonymous:s.anonymous,rsvp_token:s.rsvpToken})});return 403!==r.status||e?r.json():(c.clearCache(),a(!0))};try{const s=await a();s.success&&(e&&(e.posts[t]={...e.posts[t],eventResponses:{attending:s.responses.attending.count,waitingList:s.responses.waiting_list.count,notAttending:s.responses.not_attending.count},currentUser:{status:s.status,guests:s.guests,anonymous:s.anonymous}}),"function"==typeof n&&n(s))}catch(t){console.warn("RSVP API request failed:",t)}finally{r&&r.classList.remove("gatherpress--is-loading")}}const{state:i,actions:p}=(0,e.store)("gatherpress",{actions:{updateGuestCount(){const t=(0,e.getElement)(),s=(0,e.getContext)().postId||0;u(i,s);const n=i.posts[s].currentUser;n.guests=parseInt(t.ref.value,10),n.rsvpToken=a("gatherpress_rsvp_token");const r=t.ref.closest(".gatherpress-rsvp--trigger-update");l(s,n,i,()=>{setTimeout(()=>{t.ref.focus()},10)},r)},updateAnonymous(){const t=(0,e.getElement)(),s=(0,e.getContext)().postId||0;u(i,s);const n=i.posts[s].currentUser;n.anonymous=t.ref.checked?1:0,n.rsvpToken=a("gatherpress_rsvp_token");const r=t.ref.closest(".gatherpress-rsvp--trigger-update");l(s,n,i,()=>{setTimeout(()=>{t.ref.focus()},10)},r)},updateRsvp(t=null){var s;t&&t.preventDefault();const n=(0,e.getElement)(),r=(0,e.getContext)(),o=r?.postId||0;u(i,o);const c=null!==(s=n.ref.dataset.setStatus)&&void 0!==s?s:"",d=i.posts[o].currentUser.status;let g="not_attending";t?["attending","waiting_list","not_attending"].includes(c)?g=c:["not_attending","no_status"].includes(d)&&(g="attending"):g=d;const f=i.posts[o].currentUser.guests,v=i.posts[o].currentUser.anonymous,h=a("gatherpress_rsvp_token"),m=n.ref.closest(".gatherpress-rsvp--trigger-update");l(o,{status:g,guests:f,anonymous:v,rsvpToken:h},i,()=>{const t=n.ref.closest("[data-rsvp-status]"),s=t.dataset.rsvpStatus,e=t.closest(".wp-block-gatherpress-rsvp");if(["not_attending","no_status"].includes(s)){const t=e.querySelector('[data-rsvp-status="attending"] .gatherpress-rsvp--trigger-update');p.openModal(null,t),setTimeout(()=>{p.closeModal(null,n.ref,!1)},10)}else setTimeout(()=>{p.closeModal(null,n.ref,!0)},10)},m)}},callbacks:{monitorAnonymousStatus(){const t=(0,e.getElement)(),s=(0,e.getContext)().postId||0;u(i,s),t.ref.checked=i.posts[s].currentUser.anonymous},setGuestCount(){const t=(0,e.getElement)(),s=(0,e.getContext)().postId||0;u(i,s),t.ref.value=i.posts[s].currentUser.guests},renderRsvpBlock(){const t=(0,e.getElement)(),s=(0,e.getContext)().postId||0;u(i,s);const n=t.ref.dataset.userDetails?JSON.parse(t.ref.dataset.userDetails):null;delete t.ref.dataset.userDetails,n&&(i.posts[s]={...i.posts[s],currentUser:{status:n?.status||"no_status",guests:n?.guests||0,anonymous:n?.anonymous||0}}),t.ref.querySelectorAll("[data-rsvp-status]").forEach(t=>{const e=t.parentNode;t.dataset.rsvpStatus===i.posts[s].currentUser.status?(t.classList.remove("gatherpress--is-hidden"),e.insertBefore(t,e.firstChild)):t.classList.add("gatherpress--is-hidden")})},updateGuestCountDisplay(){const t=(0,e.getContext)(),s=t?.postId||0;u(i,t);const n=parseInt(i.posts[s]?.currentUser?.guests||0,10),r=(0,e.getElement)(),o=r.ref.dataset.guestSingular,a=r.ref.dataset.guestPlural;let c="";0