import*as e from"@wordpress/interactivity";var t={d:(e,s)=>{for(var r in s)t.o(s,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:s[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const s=(r={getContext:()=>e.getContext,getElement:()=>e.getElement,store:()=>e.store},a={},t.d(a,r),a);var r,a;function n(e,t){var s;e.posts=null!==(s=e.posts)&&void 0!==s?s:[],t&&!e.posts[t]&&(e.posts[t]={eventResponses:{attending:0,waitingList:0,notAttending:0},currentUser:{status:"no_status",guests:0,anonymous:0},rsvpSelection:"attending"})}const{state:o,actions:i}=(0,s.store)("gatherpress",{state:{posts:{}},actions:{processRsvpSelection(e){i.linkHandler(e);const t=(0,s.getElement)(),r=t?.ref?.dataset?.status;if(r){const e=(0,s.getContext)(),t=e?.postId||0;n(o,t),t&&(o.posts[t].rsvpSelection=r)}},toggleRsvpVisibility(e){e.preventDefault();const t=(0,s.getElement)(),r=t.ref.closest(".wp-block-gatherpress-rsvp-response");if("1"!==r.dataset.limitEnabled)return;const a=parseInt(r.dataset.limit,10)||8,n=r.querySelector(".gatherpress--rsvp-responses");n&&(t.ref.getAttribute("aria-label")===t.ref.dataset.showAll?(t.ref.setAttribute("aria-label",t.ref.dataset.showFewer),t.ref.textContent=t.ref.dataset.showFewer,n.querySelectorAll("[data-id].gatherpress--is-hidden").forEach(e=>e.classList.remove("gatherpress--is-hidden"))):(t.ref.setAttribute("aria-label",t.ref.dataset.showAll),t.ref.textContent=t.ref.dataset.showAll,n.querySelectorAll("[data-id]").forEach((e,t)=>{t>=a?e.classList.add("gatherpress--is-hidden"):e.classList.remove("gatherpress--is-hidden")})))}},callbacks:{processRsvpDropdown(){const e=(0,s.getContext)(),t=e?.postId||0,r=(0,s.getElement)(),a=r.ref.closest(".wp-block-gatherpress-rsvp-response");n(o,t);const i=a.dataset.counts?JSON.parse(a.dataset.counts):null;if(delete a.dataset.counts,i&&(o.posts[t]={...o.posts[t],eventResponses:{attending:i?.attending||0,waitingList:i?.waiting_list||0,notAttending:i?.not_attending||0}}),r?.ref&&!r.ref.dataset.label){const e=r.ref.textContent.trim();e&&(r.ref.dataset.label=e)}const l=r.ref.parentElement,d=l?.classList||[],p=r.ref.dataset.label,c=r.ref.dataset.status===o.posts[t]?.rsvpSelection||"attending"===r.ref.dataset.status&&"no_status"===o.posts[t]?.rsvpSelection,g=r.ref.closest(".wp-block-gatherpress-dropdown"),f=g.querySelector(".wp-block-gatherpress-dropdown__trigger");let h=0;if(d.contains("gatherpress--is-attending")?h=o.posts[t]?.eventResponses?.attending||0:d.contains("gatherpress--is-waiting-list")?h=o.posts[t]?.eventResponses?.waitingList||0:d.contains("gatherpress--is-not-attending")&&(h=o.posts[t]?.eventResponses?.notAttending||0),p){const e=p.replace("%d",h);r.ref.textContent=e}if(c){const e=r.ref.textContent.trim();g.querySelectorAll("[data-status]").forEach(e=>{e.classList.remove("gatherpress--is-disabled"),e.removeAttribute("tabindex"),e.removeAttribute("aria-disabled")}),r.ref.classList.add("gatherpress--is-disabled"),r.ref.setAttribute("tabindex","-1"),r.ref.setAttribute("aira-disabled","true"),f.textContent=e}0!==h||d.contains("gatherpress--is-attending")?l.classList.remove("gatherpress--is-hidden"):l.classList.add("gatherpress--is-hidden");const u=g.querySelectorAll(".wp-block-gatherpress-dropdown-item:not(.gatherpress--is-hidden)");1===u.length&&u[0].classList.contains("gatherpress--is-attending")&&u[0].textContent===f.textContent?(f.classList.add("gatherpress--is-disabled"),f.setAttribute("tabindex","-1")):(f.classList.remove("gatherpress--is-disabled"),f.setAttribute("tabindex","0")),"function"==typeof f.cleanupFocusTrap&&f.cleanupFocusTrap(),"function"==typeof f.cleanupCloseHandlers&&f.cleanupCloseHandlers()},showHideToggle(){var e;const t=(0,s.getElement)(),r=(0,s.getContext)(),a=r?.postId||0,n=t.ref.closest(".wp-block-gatherpress-rsvp-response");if("1"!==n.dataset.limitEnabled)return;const i=(null!==(e=o.posts[a]?.rsvpSelection)&&void 0!==e?e:"attending").replaceAll(/__+/g,"_").replaceAll(/_([a-zA-Z])/g,(e,t)=>t.toUpperCase());o.posts[a].eventResponses[i]<=(parseInt(n.dataset.limit,10)||8)?t.ref.classList.add("gatherpress--is-hidden"):t.ref.classList.remove("gatherpress--is-hidden");const l=t.ref.querySelector('a[role="button"]');l&&(l.setAttribute("aria-label",l.dataset.showAll),l.textContent=l.dataset.showAll)}}});