(()=>{"use strict";var e={n:t=>{var s=t&&t.__esModule?()=>t.default:()=>t;return e.d(s,{a:s}),s},d:(t,s)=>{for(var r in s)e.o(s,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:s[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.blocks,s=window.wp.blockEditor,r=window.wp.i18n,o=window.wp.components,a=window.wp.compose,n=window.wp.element,i=window.wp.hooks,l=window.wp.data,c=[["core/group",{metadata:{gatherpressRsvpFormVisibility:{onSuccess:"show",whenPast:"hide"}},style:{spacing:{margin:{bottom:"1rem"}}}},[["core/heading",{content:(0,r.__)("Thank you for your RSVP!","gatherpress"),level:3,style:{typography:{fontWeight:"600"},color:{text:"#16a085"}}}],["core/paragraph",{content:(0,r.__)("Please check your email for a confirmation link to complete your registration.","gatherpress")}]]],["core/group",{metadata:{gatherpressRsvpFormVisibility:{whenPast:"show"}},style:{spacing:{margin:{bottom:"1rem"}}}},[["core/heading",{content:(0,r.__)("This event has already occurred.","gatherpress"),level:3,style:{typography:{fontWeight:"600"}}}],["core/paragraph",{content:(0,r.__)("Registration for this event is now closed.","gatherpress")}]]],["gatherpress/form-field",{metadata:{gatherpressRsvpFormVisibility:{onSuccess:"hide",whenPast:"hide"}},fieldName:"author",label:(0,r.__)("Name","gatherpress"),placeholder:(0,r.__)("Name as you'd like it to appear","gatherpress"),required:!0,autocomplete:"name"}],["gatherpress/form-field",{metadata:{gatherpressRsvpFormVisibility:{onSuccess:"hide",whenPast:"hide"}},fieldType:"email",fieldName:"email",label:(0,r.__)("Email","gatherpress"),placeholder:(0,r.__)("your@email.com","gatherpress"),required:!0,autocomplete:"email"}],["gatherpress/form-field",{metadata:{gatherpressRsvpFormVisibility:{onSuccess:"hide",whenPast:"hide"}},className:"gatherpress-rsvp-field-guests",fieldType:"number",fieldName:"gatherpress_rsvp_form_guests","data-gatherpress-field-type":"guests",label:(0,r.__)("Number of guests?","gatherpress"),placeholder:(0,r.__)("0","gatherpress"),minValue:0,inlineLayout:!0,fieldWidth:10,inputPadding:5,autocomplete:"off"}],["gatherpress/form-field",{metadata:{gatherpressRsvpFormVisibility:{onSuccess:"hide",whenPast:"hide"}},className:"gatherpress-rsvp-field-anonymous",fieldType:"checkbox",fieldName:"gatherpress_rsvp_form_anonymous","data-gatherpress-field-type":"anonymous",fieldValue:!1,label:(0,r.__)("List me as anonymous","gatherpress")}],["gatherpress/form-field",{metadata:{gatherpressRsvpFormVisibility:{onSuccess:"hide",whenPast:"hide"}},fieldType:"checkbox",fieldName:"gatherpress_event_updates_opt_in",fieldValue:!1,label:(0,r.__)("Email me updates about this event","gatherpress")}],["core/buttons",{metadata:{gatherpressRsvpFormVisibility:{onSuccess:"hide",whenPast:"hide"}}},[["core/button",{className:"gatherpress-submit-button",tagName:"button",text:(0,r.__)("Submit","gatherpress")}]]]],p=window.moment;var d=e.n(p);function u(){const e=document.querySelector('iframe[name="editor-canvas"]');return e?.contentDocument?e.contentDocument:document}function h(){const e=(0,l.select)("core/editor")?.getCurrentPostType();return["wp_template","wp_template_part"].includes(e)}window.wp.date;const m=window.ReactJSXRuntime,g="YYYY-MM-DD HH:mm:ss";function f(){const e=b();return v(d()().format("YYYY-MM-DD HH:mm:ss"),e).add(1,"day").set("hour",18).set("minute",0).set("second",0).format(g)}function _(e){return/^[+-]\d{2}:\d{2}$/.test(e)}function v(e,t){return _(t)?d()(e).utcOffset(t,!0):d().tz(e,t)}function b(e=function(){if("object"==typeof GatherPress)return"eventDetails.dateTime.timezone".split(".").reduce((e,t)=>e?.[t],GatherPress)}()){return _(e)||d().tz.zone(e)?e:(0,r.__)("GMT","gatherpress")}f(),function(){const e=b();v(f(),e).add(2,"hours").format(g)}();const y=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"gatherpress/rsvp-form","version":"1.0.0","title":"RSVP Form","category":"gatherpress","icon":"forms","example":{},"description":"Allows visitors to RSVP to an event without requiring a site account.","usesContext":["postId","queryId"],"supports":{"gatherpress":{"postIdOverride":true},"interactivity":true,"html":false},"textdomain":"gatherpress","editorScript":"file:./index.js","viewScriptModule":"file:./view.js"}'),w=(0,a.createHigherOrderComponent)(e=>t=>{const{clientId:a,attributes:i}=t,{currentBlock:c,parents:p,rsvpFormParentId:d}=(0,l.useSelect)(e=>{const{getBlockParents:t,getBlock:s}=e("core/block-editor"),r=s(a),o=t(a),n=o.find(e=>{const t=s(e);return"gatherpress/rsvp-form"===t?.name});return{currentBlock:r,parents:o,rsvpFormParentId:n}},[a]);if("gatherpress/rsvp-form"===c?.name)return p.some(e=>{const{getBlock:t}=(0,l.select)("core/block-editor"),s=t(e);return"gatherpress/rsvp-form"===s?.name})?((0,n.useEffect)(()=>{const{removeBlock:e}=(0,l.dispatch)("core/block-editor");e(a)},[a]),null):(0,m.jsx)(e,{...t});if(!d)return(0,m.jsx)(e,{...t});const u=i?.metadata?.gatherpressRsvpFormVisibility||{},h=u?.onSuccess||"",g=u?.whenPast||"",{updateBlockAttributes:f}=(0,l.dispatch)("core/block-editor"),_=(e,t)=>{const s={...i.metadata},r={...u};t&&""!==t?r[e]=t:delete r[e],0===Object.keys(r).length?delete s.gatherpressRsvpFormVisibility:s.gatherpressRsvpFormVisibility=r,f(a,{metadata:s})};return(0,m.jsxs)(n.Fragment,{children:[(0,m.jsx)(e,{...t}),(0,m.jsxs)(s.InspectorAdvancedControls,{children:[(0,m.jsx)(o.SelectControl,{label:(0,r.__)("On Successful Submission","gatherpress"),help:(0,r.__)("Control visibility when the RSVP form is successfully submitted.","gatherpress"),value:h,options:[{label:(0,r.__)("Always visible","gatherpress"),value:""},{label:(0,r.__)("Show","gatherpress"),value:"show"},{label:(0,r.__)("Hide","gatherpress"),value:"hide"}],onChange:e=>_("onSuccess",e)}),(0,m.jsx)(o.SelectControl,{label:(0,r.__)("When Event Has Passed","gatherpress"),help:(0,r.__)("Control visibility when the event end time has passed.","gatherpress"),value:g,options:[{label:(0,r.__)("Always visible","gatherpress"),value:""},{label:(0,r.__)("Show","gatherpress"),value:"show"},{label:(0,r.__)("Hide","gatherpress"),value:"hide"}],onChange:e=>_("whenPast",e)})]})]})},"withFormVisibilityControls");(0,t.registerBlockType)(y,{edit:({attributes:e,clientId:a,context:i})=>{var p,d;const[g,f]=(0,n.useState)("default"),_=null!==(p=null!==(d=e?.postId||null)&&void 0!==d?d:i?.postId)&&void 0!==p?p:null,v=(0,t.getBlockTypes)().map(e=>e.name).filter(e=>"gatherpress/rsvp-form"!==e),{maxGuestLimit:b,enableAnonymousRsvp:y}=(0,l.useSelect)(t=>function(e,t,s){let r,o;if(s?.postId&&t){const s=e("core").getEntityRecord("postType","gatherpress_event",t);r=s?.meta?.gatherpress_max_guest_limit,o=Boolean(s?.meta?.gatherpress_enable_anonymous_rsvp)}else{const t=e("core/editor")?.getCurrentPostType();if("gatherpress_event"===t){const t=e("core/editor").getEditedPostAttribute("meta");r=t?.gatherpress_max_guest_limit,o=Boolean(t?.gatherpress_enable_anonymous_rsvp)}}return{maxGuestLimit:null!=r?r:0,enableAnonymousRsvp:null!=o&&o}}(t,_,e),[_,e]),w=function(e=null){if(e){const t=(0,l.select)("core").getEntityRecord("postType","gatherpress_event",e),s=(0,l.select)("core/editor")?.getCurrentPostId();return s&&s===e?!!t:!!t&&"publish"===t.status}return"gatherpress_event"===(0,l.select)("core/editor")?.getCurrentPostType()}(_),k=(0,l.useSelect)(e=>{const{getBlock:t}=e("core/block-editor"),s=t(a);return s?.innerBlocks||[]},[a]),P=(0,n.useCallback)(e=>e.map(e=>{if("gatherpress/form-field"===e.name){const t=e.attributes?.fieldName;let s=!1;if("gatherpress_rsvp_form_guests"===t?s=0===parseInt(b,10):"gatherpress_rsvp_form_anonymous"===t&&(s=!y),"gatherpress_rsvp_form_guests"===t||"gatherpress_rsvp_form_anonymous"===t){const t={...e.attributes};return s?t["data-gatherpress-no-render"]="true":delete t["data-gatherpress-no-render"],{...e,attributes:t}}}return e.innerBlocks&&0{const t=[];return e.forEach(e=>{const s=e.attributes?.metadata?.gatherpressRsvpFormVisibility;if(s&&((e,t)=>{const{onSuccess:s="",whenPast:r=""}=e,o="past"===t;return o&&r?"show"!==r:o||!r||s?!!s&&("success"===t?"show"!==s:"show"===s):"show"===r})(s,g)){const s=`#block-${e.clientId}`;t.push(`${s} { display: none !important; }`)}e.innerBlocks&&0{const e=S(k),t=u(),s=`gatherpress-form-visibility-${a}`;let r=t.getElementById(s);return r||(r=t.createElement("style"),r.id=s,t.head.appendChild(r)),r.textContent=e.join("\n"),()=>{r?.remove()}},[g,k,a,S]),(0,n.useEffect)(()=>{const e=u(),t=`gatherpress-rsvp-form-visibility-${a}`;let s=e.getElementById(t);s||(s=e.createElement("style"),s.id=t,e.head.appendChild(s));const r=[];return 0===parseInt(b,10)&&r.push(`#block-${a} .gatherpress-rsvp-field-guests { opacity: 0.3; }`),y||r.push(`#block-${a} .gatherpress-rsvp-field-anonymous { opacity: 0.3; }`),s.textContent=r.join("\n"),()=>{s?.remove()}},[b,y,a]);const B=(0,s.useBlockProps)({style:{opacity:h()||w?1:.3}});return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(s.InspectorControls,{children:(0,m.jsx)(o.PanelBody,{title:(0,r.__)("Preview Settings","gatherpress"),children:(0,m.jsx)(o.SelectControl,{label:(0,r.__)("Form State Preview","gatherpress"),help:(0,r.__)("Preview how blocks appear in different form states. This setting is not saved.","gatherpress"),value:g,options:[{label:(0,r.__)("Default (before submission)","gatherpress"),value:"default"},{label:(0,r.__)("Success (after submission)","gatherpress"),value:"success"},{label:(0,r.__)("Past (event has ended)","gatherpress"),value:"past"}],onChange:f})})}),(0,m.jsx)("div",{...B,children:(0,m.jsx)(s.InnerBlocks,{template:c,allowedBlocks:v})})]})},save:()=>(0,m.jsx)("div",{...s.useBlockProps.save(),children:(0,m.jsx)(s.InnerBlocks.Content,{})})}),(0,i.addFilter)("editor.BlockEdit","gatherpress/form-visibility-controls",w),(0,i.addFilter)("blocks.canInsertBlockType","gatherpress/prevent-nested-rsvp-form",function(e,t,s){if("gatherpress/rsvp-form"!==t.name)return e;const{getBlockParents:r,getBlock:o,getSelectedBlockClientId:a}=(0,l.select)("core/block-editor"),n=s||a();return(!n||!r(n,!0).some(e=>{const t=o(e);return"gatherpress/rsvp-form"===t?.name}))&&e})})();