(()=>{"use strict";var e,t={601:(e,t,s)=>{const r=window.wp.blocks,n=window.wp.blockEditor,o=window.wp.i18n,a=window.wp.components,i=window.wp.element,p=window.wp.apiFetch;var l=s.n(p);const d=window.wp.data,c=window.wp.coreData;function u(e){if("object"==typeof GatherPress)return e.split(".").reduce((e,t)=>e?.[t],GatherPress)}const g=window.ReactJSXRuntime,h=({defaultStatus:e,setDefaultStatus:t})=>{var s;const r=u("eventDetails.responses"),n=u("eventDetails.postId"),[p,h]=(0,i.useState)(r),m=p[e].records,{userList:v}=(0,d.useSelect)(e=>{const{getEntityRecords:t}=e(c.store);return{userList:t("root","user",{per_page:-1})}},[]),f=null!==(s=v?.reduce((e,t)=>({...e,[t.username]:t}),{}))&&void 0!==s?s:{},w=(e,t="attending")=>{l()({path:u("urls.eventApiPath")+"/rsvp",method:"POST",data:{post_id:n,status:t,user_id:e}}).then(e=>{h(e.responses),function(e,t){if("object"!=typeof GatherPress)return;const s="eventDetails.responses".split("."),r=s.pop();s.reduce((e,t)=>{var s;return null!==(s=e[t])&&void 0!==s?s:e[t]={}},GatherPress)[r]=t}(0,e.responses)})};return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(a.SelectControl,{label:(0,o.__)("RSVP Status","gatherpress"),value:e,options:[{label:(0,o._x)("Attending","RSVP status option in dropdown","gatherpress"),value:"attending"},{label:(0,o._x)("Waiting List","RSVP status option in dropdown","gatherpress"),value:"waiting_list"},{label:(0,o._x)("Not Attending","RSVP status option in dropdown","gatherpress"),value:"not_attending"}],onChange:e=>t(e)}),(0,g.jsx)(a.FormTokenField,{label:(0,o.__)("Members","gatherpress"),value:m?.map(e=>({id:e.userId,value:e.name})),tokenizeOnSpace:!0,onChange:async t=>{t.length>m.length?t.forEach(t=>{f[t]&&w(f[t].id,e)}):m.forEach(e=>{!1===t.some(t=>t.id===e.userId)&&w(e.userId,"no_status")})},suggestions:Object.keys(f),maxSuggestions:20},"query-controls-topics-select")]})},m={attending:(0,o._x)("Attending (%d)","Filter option to view list of confirmed attendees","gatherpress"),waitingList:(0,o._x)("Waiting List (%d)","Filter option to view list of waitlisted attendees","gatherpress"),notAttending:(0,o._x)("Not Attending (%d)","Filter option to view list of declined attendees","gatherpress"),noOne:(0,o.__)("No one is attending this event yet.","gatherpress")},v=[["core/group",{style:{spacing:{blockGap:"var:preset|spacing|20",margin:{bottom:"var:preset|spacing|30"}}},layout:{type:"flex",flexWrap:"nowrap",justifyContent:"space-between"}},[["core/group",{style:{spacing:{blockGap:"var:preset|spacing|20",margin:{bottom:"var:preset|spacing|30"}}},layout:{type:"flex",flexWrap:"nowrap"}},[["gatherpress/icon",{icon:"groups"}],["gatherpress/dropdown",{actAsSelect:!0,label:m.attending,metadata:{name:m.attending}},[["gatherpress/dropdown-item",{text:`${m.attending}`,metadata:{name:m.attending},className:"gatherpress--is-attending"}],["gatherpress/dropdown-item",{text:`${m.waitingList}`,metadata:{name:m.waitingList},className:"gatherpress--is-waiting-list"}],["gatherpress/dropdown-item",{text:`${m.notAttending}`,metadata:{name:m.notAttending},className:"gatherpress--is-not-attending"}]]]]],["gatherpress/rsvp-response-toggle"]]],["core/group",{layout:{type:"grid",columns:3,justifyContent:"center",alignContent:"space-around",minimumColumnWidth:"8rem"},className:"gatherpress--rsvp-responses"},[["gatherpress/rsvp-template",{}]]],["core/group",{metadata:{name:(0,o._x)("Empty RSVP","Block name displayed in the editor","gatherpress")},className:"gatherpress-rsvp-response--no-responses"},[["core/paragraph",{content:m.noOne,metadata:{name:(0,o._x)("Empty RSVP Text","Block name displayed in the editor","gatherpress")}}]]]],f=window.moment;var w=s.n(f);function y(){const e=(0,d.select)("core/editor")?.getCurrentPostType();return["wp_template","wp_template_part"].includes(e)}window.wp.hooks,window.wp.date;const b="YYYY-MM-DD HH:mm:ss";function x(){const e=j();return S(w()().format("YYYY-MM-DD HH:mm:ss"),e).add(1,"day").set("hour",18).set("minute",0).set("second",0).format(b)}function _(e){return/^[+-]\d{2}:\d{2}$/.test(e)}function S(e,t){return _(t)?w()(e).utcOffset(t,!0):w().tz(e,t)}function j(e=u("eventDetails.dateTime.timezone")){return _(e)||w().tz.zone(e)?e:(0,o.__)("GMT","gatherpress")}function P(){return"gatherpress_event"===(0,d.select)("core/editor")?.getCurrentPostType()}x(),function(){const e=j();S(x(),e).add(2,"hours").format(b)}();const k=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"gatherpress/rsvp-response","version":"2.0.0","title":"RSVP Response","category":"gatherpress","icon":"groups","example":{},"description":"Displays a list of members who have confirmed their attendance for an event.","usesContext":["postId","queryId"],"attributes":{"rsvpLimitEnabled":{"type":"boolean","default":false},"rsvpLimit":{"type":"number","default":8}},"supports":{"gatherpress":{"blockGuard":true,"postIdOverride":true},"align":["wide","full"],"interactivity":true,"html":false},"providesContext":{"commentId":"commentId","postId":"postId","gatherpress/rsvpLimitEnabled":"rsvpLimitEnabled","gatherpress/rsvpLimit":"rsvpLimit"},"textdomain":"gatherpress","editorScript":"file:./index.js","style":"file:./style-index.css","viewScriptModule":"file:./view.js"}');(0,r.registerBlockType)(k,{edit:({attributes:e,setAttributes:t,context:s})=>{var r,p;const[l,c]=(0,i.useState)(!1),[m,f]=(0,i.useState)(!1),[w,b]=(0,i.useState)("attending"),[x,_]=(0,i.useState)(null),[S,j]=(0,i.useState)(!0),[k,C]=(0,i.useState)(null),E=null!==(r=null!==(p=e?.postId||null)&&void 0!==p?p:s?.postId)&&void 0!==r?r:null,{rsvpLimitEnabled:L,rsvpLimit:O}=e,R=function(e=null){if(e){const t=(0,d.select)("core").getEntityRecord("postType","gatherpress_event",e),s=(0,d.select)("core/editor")?.getCurrentPostId();return s&&s===e?!!t:!!t&&"publish"===t.status}return P()}(E),I=(0,n.useBlockProps)({style:{opacity:y()||R?1:.3}});return(0,i.useEffect)(()=>{const e=function(){const e=document.querySelector('iframe[name="editor-canvas"]');return e?.contentDocument?e.contentDocument:document}(),t=()=>{const t=e.querySelectorAll(".gatherpress-rsvp-response--no-responses"),s=e.querySelectorAll(".gatherpress--rsvp-responses");t.forEach(e=>{e.style.setProperty("display",m?"block":"none","important")}),s.forEach(e=>{m?e.style.setProperty("display","none","important"):e.style.removeProperty("display")})},s=new MutationObserver(t);return s.observe(e.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["class"]}),t(),()=>s.disconnect()},[m,x]),(0,i.useEffect)(()=>{if(!E)return _(null),void j(!1);j(!0),C(null),async function(e){const t=u("urls.eventApiUrl");return(await fetch(`${t}/rsvp-responses?post_id=${e}`)).json()}(E).then(e=>{_(e.data),j(!1)}).catch(e=>{C(e.message),j(!1)})},[E]),S?(0,g.jsx)("div",{...I,children:(0,g.jsx)(a.Spinner,{})}):k?(0,g.jsx)("div",{...I,children:(0,g.jsx)("p",{children:(0,o.__)("Failed to load RSVP responses.","gatherpress")})}):(0,g.jsx)("div",{...I,children:(0,g.jsxs)(n.BlockContextProvider,{value:{"gatherpress/rsvpResponses":x,"gatherpress/rsvpLimitEnabled":L,"gatherpress/rsvpLimit":O,postId:E},children:[(0,g.jsx)(n.InspectorControls,{children:(0,g.jsxs)(a.PanelBody,{children:[(0,g.jsx)(a.ToggleControl,{label:(0,o.__)("Show Empty RSVP Block","gatherpress"),checked:m,onChange:e=>f(e),help:(0,o.__)("Toggle to show or hide the Empty RSVP block.","gatherpress")}),(0,g.jsx)(a.ToggleControl,{label:(0,o.__)("Limit RSVP Display","gatherpress"),checked:L,onChange:()=>t({rsvpLimitEnabled:!L}),help:(0,o.__)("Enable to limit the number of RSVPs displayed in this block.","gatherpress")}),L&&(0,g.jsx)(a.__experimentalNumberControl,{label:(0,o.__)("RSVP Display Limit","gatherpress"),value:O,onChange:e=>t({rsvpLimit:parseInt(e,10)||8}),min:1,max:100,help:(0,o.__)("Set the maximum number of RSVPs to display. Default is 8.","gatherpress")})]})}),P()&&(0,g.jsx)(n.BlockControls,{children:(0,g.jsx)(a.ToolbarGroup,{children:(0,g.jsx)(a.ToolbarButton,{label:(0,o.__)("Edit","gatherpress"),text:l?(0,o.__)("Preview","gatherpress"):(0,o.__)("Edit","gatherpress"),onClick:e=>{e.preventDefault(),c(!l)}})})}),l&&(0,g.jsx)(h,{defaultStatus:w,setDefaultStatus:b}),!l&&(0,g.jsx)(n.InnerBlocks,{template:v})]})})},save:()=>(0,g.jsx)("div",{...n.useBlockProps.save(),children:(0,g.jsx)(n.InnerBlocks.Content,{})})})}},s={};function r(e){var n=s[e];if(void 0!==n)return n.exports;var o=s[e]={exports:{}};return t[e](o,o.exports,r),o.exports}r.m=t,e=[],r.O=(t,s,n,o)=>{if(!s){var a=1/0;for(d=0;d=o)&&Object.keys(r.O).every(e=>r.O[e](s[p]))?s.splice(p--,1):(i=!1,o0&&e[d-1][2]>o;d--)e[d]=e[d-1];e[d]=[s,n,o]},r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var s in t)r.o(t,s)&&!r.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:t[s]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={2788:0,4556:0};r.O.j=t=>0===e[t];var t=(t,s)=>{var n,o,[a,i,p]=s,l=0;if(a.some(t=>0!==e[t])){for(n in i)r.o(i,n)&&(r.m[n]=i[n]);if(p)var d=p(r)}for(t&&t(s);lr(601));n=r.O(n)})();