(()=>{"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 n in s)e.o(s,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:s[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.i18n,s=window.wp.domReady;var n=e.n(s);const r=window.wp.data,a=window.wp.components,i=window.wp.plugins,o=window.wp.editor,l=window.moment;var c=e.n(l);const u=window.wp.element,d=window.wp.hooks;function m(e){if("object"==typeof GatherPress)return e.split(".").reduce((e,t)=>e?.[t],GatherPress)}function p(e,t){if("object"!=typeof GatherPress)return;const s=e.split("."),n=s.pop();s.reduce((e,t)=>{var s;return null!==(s=e[t])&&void 0!==s?s:e[t]={}},GatherPress)[n]=t}function g(){(0,r.dispatch)("core/editor")?.editPost({meta:{_non_existing_meta:!0}})}const h=window.wp.date,_=window.ReactJSXRuntime,v="YYYY-MM-DD HH:mm:ss";function x(){const e=E();return T(c()().format("YYYY-MM-DD HH:mm:ss"),e).add(1,"day").set("hour",18).set("minute",0).set("second",0).format(v)}const f=x(),j=function(){const e=E();return T(x(),e).add(2,"hours").format(v)}();function S(){const e=[{label:(0,t.__)("1 hour","gatherpress"),value:1},{label:(0,t.__)("1.5 hours","gatherpress"),value:1.5},{label:(0,t.__)("2 hours","gatherpress"),value:2},{label:(0,t.__)("3 hours","gatherpress"),value:3},{label:(0,t.__)("Set an end time…","gatherpress"),value:!1}];return(0,d.applyFilters)("gatherpress.durationOptions",e)}function b(e){return T(function(){let e=m("eventDetails.dateTime.datetime_start");return e=""===e?f:T(e,E()).format(v),p("eventDetails.dateTime.datetime_start",e),e}(),E()).add(e,"hours").format(v)}function D(){return S().find(e=>b(e.value)===function(){let e=m("eventDetails.dateTime.datetime_end");return e=""===e?j:T(e,E()).format(v),p("eventDetails.dateTime.datetime_end",e),e}())?.value||!1}function P(){return k(m("settings.dateFormat"))+" "+k(m("settings.timeFormat"))}function w(e){return/^[+-]\d{2}:\d{2}$/.test(e)}function T(e,t){return w(t)?c()(e).utcOffset(t,!0):c().tz(e,t)}function E(e=m("eventDetails.dateTime.timezone")){return w(e)||c().tz.zone(e)?e:(0,t.__)("GMT","gatherpress")}function C(e=""){const t=/^([+-])(\d{2}):(00|15|30|45)$/,s=e.replace(t,"$1");return s!==e?"UTC"+s+parseInt(e.replace(t,"$2")).toString()+e.replace(t,"$3").replace("00","").replace("15",".25").replace("30",".5").replace("45",".75"):e}function y(e,t=null,s=null){const n=D();p("eventDetails.dateTime.datetime_start",e),"number"==typeof n?N(T(e,E()).add(n,"hours").format(v),s):function(e,t=null,s=null){const n=E(),r=T(m("eventDetails.dateTime.datetime_end"),n).valueOf(),a=T(e,n).valueOf();if(a>=r){const e=null===s?D():s,r=!1!==e&&"number"==typeof e?e:2;N(T(a,n).add(r,"hours").format(v),t)}}(e,s,n),"function"==typeof t&&t(e),g()}function N(e,t=null,s=null){!function(e,t=null){const s=E(),n=T(m("eventDetails.dateTime.datetime_start"),s).valueOf(),r=T(e,s).valueOf();r<=n&&y(T(r,s).subtract(2,"hours").format(v),t)}(e,s),p("eventDetails.dateTime.datetime_end",e),null!==t&&t(e),g()}function k(e){const t={d:"DD",D:"ddd",j:"D",l:"dddd",N:"E",S:"o",w:"e",z:"DDD",W:"W",F:"MMMM",m:"MM",M:"MMM",n:"M",t:"",L:"",o:"YYYY",Y:"YYYY",y:"YY",a:"a",A:"A",B:"",g:"h",G:"H",h:"hh",H:"HH",i:"mm",s:"ss",u:"SSS",e:"zz",I:"",O:"",P:"",T:"",Z:"",c:"",r:"",U:"X"};return String(e).split("").map((e,s,n)=>{const r=n[s-1];return e in t&&"\\"!==r?t[e]:e}).join("")}function O(){const e=E(),t=T(m("eventDetails.dateTime.datetime_end"),e),s=T(c()().format("YYYY-MM-DD HH:mm:ss"),e);return"gatherpress_event"===(0,r.select)("core/editor")?.getCurrentPostType()&&s.valueOf()>t.valueOf()}function A(){const e="gatherpress_event_past",s=(0,r.dispatch)("core/notices");s.removeNotice(e),O()&&s.createNotice("warning",(0,t.__)("This event has already passed.","gatherpress"),{id:e,isDismissible:!1})}const F=()=>{const{editPost:e,unlockPostSaving:s}=(0,r.useDispatch)("core/editor"),n=(0,r.useSelect)(e=>e("core/editor").isCleanNewPost(),[]);let i=(0,r.useSelect)(e=>{const t=e("core/editor").getEditedPostAttribute("meta"),s=t?.gatherpress_enable_anonymous_rsvp;return Boolean(s)},[]);n&&(i=m("settings.enableAnonymousRsvp"));const[o,l]=(0,u.useState)(i),c=(0,u.useCallback)(t=>{const n={gatherpress_enable_anonymous_rsvp:Boolean(t)};l(t),e({meta:n}),s()},[e,s]);return(0,u.useEffect)(()=>{n&&i&&c(i)},[n,i,c]),(0,_.jsx)(a.CheckboxControl,{label:(0,t.__)("Enable Anonymous RSVP","gatherpress"),checked:o,onChange:e=>{c(e)}})},M=()=>(0,_.jsx)("section",{children:(0,_.jsx)(F,{})}),Y=()=>{const{dateTimeStart:e,duration:s}=(0,r.useSelect)(e=>({dateTimeStart:e("gatherpress/datetime").getDateTimeStart(),duration:e("gatherpress/datetime").getDuration()}),[]),{setDateTimeStart:n,setDateTimeEnd:i}=(0,r.useDispatch)("gatherpress/datetime"),o=(0,h.getSettings)(),l=/a(?!\\)/i.test(o.formats.time.toLowerCase().replaceAll("\\\\","").split("").reverse().join(""));return(0,u.useEffect)(()=>{n(T(e,E()).format(v)),s&&i(b(s)),A()},[e,s,n,i]),(0,_.jsx)(a.PanelRow,{children:(0,_.jsxs)(a.Flex,{direction:"column",gap:"1",children:[(0,_.jsx)(a.FlexItem,{children:(0,_.jsx)("h3",{style:{marginBottom:0},children:(0,_.jsx)("label",{htmlFor:"gatherpress-datetime-start",children:(0,t.__)("Date & time start","gatherpress")})})}),(0,_.jsx)(a.FlexItem,{children:(0,_.jsx)(a.Dropdown,{popoverProps:{placement:"bottom-end"},renderToggle:({isOpen:t,onToggle:s})=>(0,_.jsx)(a.Button,{id:"gatherpress-datetime-start",onClick:s,"aria-expanded":t,variant:"link",children:T(e,E()).format(P())}),renderContent:()=>(0,_.jsx)(a.DateTimePicker,{currentDate:e,onChange:e=>{y(e,n,i)},is12Hour:l})})})]})})},L=()=>{const{dateTimeEnd:e}=(0,r.useSelect)(e=>({dateTimeEnd:e("gatherpress/datetime").getDateTimeEnd()}),[]),{setDateTimeEnd:s,setDateTimeStart:n}=(0,r.useDispatch)("gatherpress/datetime"),i=(0,h.getSettings)(),o=/a(?!\\)/i.test(i.formats.time.toLowerCase().replaceAll("\\\\","").split("").reverse().join(""));return(0,u.useEffect)(()=>{s(T(e,E()).format(v)),A()}),(0,_.jsx)(a.PanelRow,{children:(0,_.jsxs)(a.Flex,{direction:"column",gap:"1",children:[(0,_.jsx)(a.FlexItem,{children:(0,_.jsx)("h3",{style:{marginBottom:0},children:(0,_.jsx)("label",{htmlFor:"gatherpress-datetime-end",children:(0,t.__)("Date & time end","gatherpress")})})}),(0,_.jsx)(a.FlexItem,{children:(0,_.jsx)(a.Dropdown,{popoverProps:{placement:"bottom-end"},renderToggle:({isOpen:t,onToggle:s})=>(0,_.jsx)(a.Button,{id:"gatherpress-datetime-end",onClick:s,"aria-expanded":t,variant:"link",children:T(e,E()).format(P())}),renderContent:()=>(0,_.jsx)(a.DateTimePicker,{currentDate:e,onChange:e=>N(e,s,n),is12Hour:o})})})]})})},z=()=>{const{timezone:e}=(0,r.useSelect)(e=>({timezone:e("gatherpress/datetime").getTimezone()}),[]),{setTimezone:s}=(0,r.useDispatch)("gatherpress/datetime"),n=m("misc.timezoneChoices");return(0,u.useEffect)(()=>{s(m("eventDetails.dateTime.timezone"))},[s]),(0,_.jsx)(a.PanelRow,{children:(0,_.jsx)(a.SelectControl,{label:(0,t.__)("Time Zone","gatherpress"),value:C(e),onChange:e=>{e=function(e=""){const t=/^UTC([+-])(\d+)(\.\d+)?$/,s=e.replace(t,"$1");if(s===e)return e;const n=e.replace(t,"$2").padStart(2,"0");let r=e.replace(t,"$3");return""===r&&(r=":00"),r=r.replace(".25",":15").replace(".5",":30").replace(".75",":45"),s+n+r}(e),s(e),g()},__nexthasnomarginbottom:!0,children:n&&"object"==typeof n&&0(0,_.jsx)("optgroup",{label:e,children:Object.keys(n[e]).map(t=>(0,_.jsx)("option",{value:t,children:n[e][t]},t))},e)):(0,_.jsx)("option",{value:"",children:(0,t.__)("Error, no choices available","gatherpress")})})})},R=()=>{const{duration:e}=(0,r.useSelect)(e=>({duration:e("gatherpress/datetime").getDuration()}),[]),s=(0,r.useDispatch)(),{setDateTimeEnd:n,setDuration:i}=s("gatherpress/datetime");return(0,_.jsx)(a.SelectControl,{label:(0,t.__)("Duration","gatherpress"),value:!!S().some(t=>t.value===e)&&e,options:S(),onChange:e=>{(e="false"!==e&&parseFloat(e))&&n(b(e)),i(e)},__nexthasnomarginbottom:!0})},H=()=>{const e=(0,r.useDispatch)("core/editor").editPost;let t=(0,r.useSelect)(e=>e("core/editor").getEditedPostAttribute("meta")?.gatherpress_datetime);try{t=t?JSON.parse(t):{}}catch(e){console.error("Failed to parse gatherpress_datetime meta:",e),t={}}const{dateTimeStart:s,dateTimeEnd:n,duration:a,timezone:i}=(0,r.useSelect)(e=>({dateTimeStart:e("gatherpress/datetime").getDateTimeStart(),dateTimeEnd:e("gatherpress/datetime").getDateTimeEnd(),duration:e("gatherpress/datetime").getDuration(),timezone:e("gatherpress/datetime").getTimezone()}),[]),{setDuration:o}=(0,r.useDispatch)("gatherpress/datetime");return(0,u.useEffect)(()=>{const r=JSON.stringify({...t,dateTimeStart:T(s,i).format(v),dateTimeEnd:T(n,i).format(v),timezone:i});e({meta:{gatherpress_datetime:r}})},[s,n,i,t,e,o,a]),(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)("section",{children:(0,_.jsx)(Y,{})}),(0,_.jsx)("section",{children:a?(0,_.jsx)(R,{}):(0,_.jsx)(L,{})}),(0,_.jsx)("section",{children:(0,_.jsx)(z,{})})]})},V=()=>(0,_.jsx)(H,{}),$=()=>{const{editPost:e,unlockPostSaving:s}=(0,r.useDispatch)("core/editor"),n=(0,r.useSelect)(e=>e("core/editor").isCleanNewPost(),[]);let i=(0,r.useSelect)(e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_max_guest_limit,[]);n&&(i=m("settings.maxGuestLimit")),!1===i&&(i=0);const[o,l]=(0,u.useState)(i),c=(0,u.useCallback)(t=>{const n={gatherpress_max_guest_limit:Number(t)};l(t),e({meta:n}),s()},[e,s]);return(0,u.useEffect)(()=>{n&&0!==i&&c(i)},[n,i,c]),(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(a.__experimentalNumberControl,{label:(0,t.__)("Maximum Number of Guests","gatherpress"),value:o,min:0,max:5,onChange:e=>{c(e)}}),(0,_.jsx)("p",{className:"description",children:(0,t.__)("Maximum number of additional people each attendee can bring.","gatherpress")})]})},B=()=>(0,_.jsx)("section",{children:(0,_.jsx)($,{})}),I=()=>{const{editPost:e,unlockPostSaving:s}=(0,r.useDispatch)("core/editor"),n=(0,r.useSelect)(e=>e("core/editor").isCleanNewPost(),[]);let i=(0,r.useSelect)(e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_max_attendance_limit,[]);n&&(i=m("settings.maxAttendanceLimit")),!1===i&&(i=0);const[o,l]=(0,u.useState)(i),c=(0,u.useCallback)(t=>{const n={gatherpress_max_attendance_limit:Number(t)};l(t),e({meta:n}),s()},[e,s]);return(0,u.useEffect)(()=>{n&&0!==i&&c(i)},[n,i,c]),(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(a.__experimentalNumberControl,{label:(0,t.__)("Maximum Attendance Limit","gatherpress"),value:o,min:0,onChange:e=>{c(e)}}),(0,_.jsx)("p",{className:"description",children:(0,t.__)("Total number of people allowed at the event. A value of 0 indicates no limit.","gatherpress")})]})},G=()=>(0,_.jsx)("section",{children:(0,_.jsx)(I,{})}),J=()=>{const[e,s]=(0,u.useState)(!1),{openModal:n}=(0,r.useDispatch)("gatherpress/email-modal"),i=(0,r.useSelect)(e=>e("gatherpress/email-modal").isSaving(),[]),{currentStatus:o,isSaving:l,isDirty:c}=(0,r.useSelect)(e=>{const t=e("core/editor");return{currentStatus:t.getEditedPostAttribute("status"),isSaving:t.isSavingPost(),isDirty:t.isEditedPostDirty()}},[]);return(0,u.useEffect)(()=>{const e="publish"===o&&!O();s(e)},[o]),e&&(0,_.jsxs)("section",{children:[(0,_.jsx)("h3",{style:{marginBottom:"0.5rem"},children:(0,t.__)("Send an event update via email","gatherpress")}),(0,_.jsx)(a.Button,{variant:"secondary",onClick:n,disabled:i||l||c,children:(0,t.__)("Compose Message","gatherpress")})]})},W=(e,t="")=>{for(const[s,n]of Object.entries(e)){let e=s;t&&(e+="_"+String(t));const r=new CustomEvent(e,{detail:n});dispatchEvent(r)}},U=(e,t="")=>{for(const[s,n]of Object.entries(e)){let e=s;t&&(e+="_"+String(t)),addEventListener(e,e=>{n(e.detail)},!1)}},X=()=>{const{editPost:e,unlockPostSaving:s}=(0,r.useDispatch)("core/editor"),n=(0,r.useSelect)(e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_online_event_link),[i,o]=(0,u.useState)(n);return U({setOnlineEventLink:o},m("eventDetails.postId")),(0,_.jsx)(a.TextControl,{label:(0,t.__)("Online event link","gatherpress"),value:i,placeholder:(0,t.__)("Add link to online event","gatherpress"),onChange:t=>{(t=>{e({meta:{gatherpress_online_event_link:t}}),o(t),W({setOnlineEventLink:t},m("eventDetails.postId")),s()})(t)}})},Z=()=>(0,_.jsx)("section",{children:(0,_.jsx)(X,{})}),q=()=>{const[e,s]=(0,u.useState)(""),n=(0,r.useDispatch)("core/editor").editPost,{unlockPostSaving:i}=(0,r.useDispatch)("core/editor"),o=(0,r.useSelect)(e=>e("core/editor").getEditedPostAttribute("_gatherpress_venue")),l=(0,r.useSelect)(e=>e("core").getEntityRecord("taxonomy","_gatherpress_venue",o)),c=l?.slug.replace(/^_/,""),[d,m]=(0,u.useState)(""),p=o+":"+d,g=(0,r.useSelect)(e=>e("core").getEntityRecords("postType","gatherpress_venue",{per_page:1,slug:d})),{updateVenueLatitude:h,updateVenueLongitude:v}=(0,r.useDispatch)("gatherpress/venue");(0,u.useEffect)(()=>{var e,n,r,a,i,o;let l={};if(d&&Array.isArray(g)){var u;const e=null!==(u=g[0]?.meta?.gatherpress_venue_information)&&void 0!==u?u:"{}";var _;e&&(l=JSON.parse(e),l.name=null!==(_=g[0]?.title.rendered)&&void 0!==_?_:"")}const x=null!==(e=l?.name)&&void 0!==e?e:(0,t.__)("No venue selected.","gatherpress"),f=null!==(n=l?.fullAddress)&&void 0!==n?n:"",j=null!==(r=l?.phoneNumber)&&void 0!==r?r:"",S=null!==(a=l?.website)&&void 0!==a?a:"",b=null!==(i=l?.latitude)&&void 0!==i?i:"0",D=null!==(o=l?.longitude)&&void 0!==o?o:"0";c&&m(c),s(p?String(p):""),h(b),v(D),W({setName:x,setFullAddress:f,setPhoneNumber:j,setWebsite:S,setLatitude:b,setLongitude:D,setIsOnlineEventTerm:"online-event"===d})},[d,g,c,p,h,v]);let x=(0,r.useSelect)(e=>e("core").getEntityRecords("taxonomy","_gatherpress_venue",{per_page:-1,context:"view"}),[]);return x?(x=x.map(e=>({label:e.name,value:e.id+":"+e.slug.replace(/^_/,"")})),x.unshift({value:":",label:(0,t.__)("Choose a venue","gatherpress")})):x=[],(0,_.jsx)(a.PanelRow,{children:(0,_.jsx)(a.SelectControl,{label:(0,t.__)("Venue Selector","gatherpress"),value:e,onChange:e=>{(e=>{s(e);const t=""===(e=e.split(":"))[0]?[]:[e[0]];n({_gatherpress_venue:t}),m(e[1]),i()})(e)},options:x})})},K=()=>(0,_.jsx)("section",{children:(0,_.jsx)(q,{})}),{Fill:Q,Slot:ee}=(0,a.createSlotFill)("EventPluginDocumentSettings"),te=({children:e,className:t})=>(0,_.jsx)(Q,{children:(0,_.jsx)(a.PanelRow,{className:t,children:e})});te.Slot=ee,(0,i.registerPlugin)("gatherpress-event-settings",{render:()=>"gatherpress_event"===(0,r.select)("core/editor")?.getCurrentPostType()&&(0,_.jsxs)(o.PluginDocumentSettingPanel,{name:"gatherpress-event-settings",title:(0,t.__)("Event settings","gatherpress"),className:"gatherpress-event-settings",children:[(0,_.jsx)(te.Slot,{}),(0,_.jsxs)(a.__experimentalVStack,{spacing:4,children:[(0,_.jsx)(V,{}),(0,_.jsx)(K,{}),(0,_.jsx)(Z,{}),(0,_.jsx)(B,{}),(0,_.jsx)(G,{}),(0,_.jsx)(M,{}),(0,_.jsx)(J,{})]})]})}),n()(()=>{const e=(0,r.select)("core/edit-post"),t=(0,r.dispatch)("core/editor");e&&t&&(e.isEditorPanelOpened("gatherpress-event-settings/gatherpress-event-settings")||t.toggleEditorPanelOpened("gatherpress-event-settings/gatherpress-event-settings"))});const se=window.wp.compose,ne=()=>{var e,s,n;const i=(0,r.useDispatch)("core/editor").editPost,o=e=>{const t=JSON.stringify({...m,...e});i({meta:{gatherpress_venue_information:t}})},{updateVenueLatitude:l,updateVenueLongitude:c}=(0,r.useDispatch)("gatherpress/venue"),{mapCustomLatLong:d}=(0,r.useSelect)(e=>({mapCustomLatLong:e("gatherpress/venue").getMapCustomLatLong()}),[]);let m=(0,r.useSelect)(e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_venue_information);m=m?JSON.parse(m):{};const[p,g]=(0,u.useState)(null!==(e=m.fullAddress)&&void 0!==e?e:""),[h,v]=(0,u.useState)(null!==(s=m.phoneNumber)&&void 0!==s?s:""),[x,f]=(0,u.useState)(null!==(n=m.website)&&void 0!==n?n:"");U({setFullAddress:g,setPhoneNumber:v,setWebsite:f});const j=(0,u.useRef)(o),S=(0,u.useCallback)(()=>{let e=null,s=null;fetch(`https://nominatim.openstreetmap.org/search?q=${p}&format=geojson`).then(e=>{if(!e.ok)throw new Error((0,t.sprintf)(/* translators: %s: Error message */ /* translators: %s: Error message */ (0,t.__)("Network response was not ok %s","gatherpress"),e.statusText));return e.json()}).then(t=>{0{j.current=o},[o]),(0,u.useEffect)(()=>{b()},[p,b]),(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(a.TextControl,{label:(0,t.__)("Full Address","gatherpress"),value:p,onChange:e=>{W({setFullAddress:e}),o({fullAddress:e})}}),(0,_.jsx)(a.TextControl,{label:(0,t.__)("Phone Number","gatherpress"),value:h,onChange:e=>{W({setPhoneNumber:e}),o({phoneNumber:e})}}),(0,_.jsx)(a.TextControl,{label:(0,t.__)("Website","gatherpress"),value:x,type:"url",onChange:e=>{W({setWebsite:e}),o({website:e})}})]})},re=()=>(0,_.jsx)("section",{children:(0,_.jsx)(ne,{})}),{Fill:ae,Slot:ie}=(0,a.createSlotFill)("VenuePluginDocumentSettings"),oe=({children:e,className:t})=>(0,_.jsx)(ae,{children:(0,_.jsx)(a.PanelRow,{className:t,children:e})});oe.Slot=ie,(0,i.registerPlugin)("gatherpress-venue-settings",{render:()=>"gatherpress_venue"===(0,r.select)("core/editor")?.getCurrentPostType()&&(0,_.jsxs)(o.PluginDocumentSettingPanel,{name:"gatherpress-venue-settings",title:(0,t.__)("Venue settings","gatherpress"),className:"gatherpress-venue-settings",children:[(0,_.jsx)(oe.Slot,{}),(0,_.jsx)(a.__experimentalVStack,{spacing:6,children:(0,_.jsx)(re,{})})]})}),(0,i.registerPlugin)("gatherpress-venue-settings-at-events",{render:function(){return(0,_.jsx)(a.Fill,{name:"EventPluginDocumentSettings",children:(0,_.jsx)(oe.Slot,{})})}}),n()(()=>{const e=(0,r.select)("core/edit-post"),t=(0,r.dispatch)("core/editor");e&&t&&(e.isEditorPanelOpened("gatherpress-venue-settings/gatherpress-venue-settings")||t.toggleEditorPanelOpened("gatherpress-venue-settings/gatherpress-venue-settings"))})})();