(()=>{"use strict";var e={n:t=>{var n=t&&t.__esModule?()=>t.default:()=>t;return e.d(n,{a:n}),n},d:(t,n)=>{for(var a in n)e.o(n,a)&&!e.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:n[a]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.React,n=window.wp.blocks,a=window.wp.blockEditor,r=window.wp.components,l=window.wp.element,i=window.wp.data,o=window.wp.i18n,d=window.wp.apiFetch;var c=e.n(d);(0,n.registerBlockType)("wp-event-genius/calendar",{apiVersion:3,title:(0,o.__)("Event Genius Calendar","event-genius"),description:(0,o.__)("Display a beautiful calendar of events with filtering and search capabilities.","event-genius"),icon:"calendar",category:"widgets",attributes:{calendarId:{type:"string",default:""}},edit:function(e){const{attributes:n,setAttributes:d}=e,[s,u]=(0,l.useState)(""),[p,v]=(0,l.useState)(!1),[g,w]=(0,l.useState)([]),_=(0,a.useBlockProps)(),m=(0,i.useSelect)((e=>{try{const t=e("core/editor");if(!t)return!1;const n=t.getCurrentPostAttribute("type");return"wp_template"===n||"wp_template_part"===n}catch(e){return!1}}),[]);(0,l.useEffect)((()=>{c()({path:"/wp/v2/evge_calendar?per_page=100&orderby=id&order=desc"}).then((e=>{const t=e.map((e=>({label:e.name,value:e.id.toString()})));w([{label:(0,o.__)("Default Calendar","event-genius"),value:""},...t])})).catch((e=>{console.error("Error loading calendars:",e)}))}),[]),(0,l.useEffect)((()=>{m||(v(!0),c()({path:"/wp-event-genius/v1/calendar/preview",method:"POST",data:{calendar_id:n.calendarId||""}}).then((e=>{u(e.html)})).catch((e=>{console.error("Error loading preview:",e),u((0,o.__)("Error loading calendar preview.","event-genius"))})).finally((()=>{v(!1)})))}),[n.calendarId,m]);const f=g.find((e=>e.value===n.calendarId));return f?f.label:(0,o.__)("Default Calendar","event-genius"),(0,t.createElement)("div",{..._},(0,t.createElement)(a.InspectorControls,null,(0,t.createElement)(r.PanelBody,{title:(0,o.__)("Event Calendar Settings","event-genius")},(0,t.createElement)(r.SelectControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,o.__)("Select Calendar","event-genius"),value:n.calendarId,options:g,onChange:e=>d({calendarId:e})}))),(0,t.createElement)("div",{className:"wp-block-wp-event-genius-calendar"},m?(0,t.createElement)("div",{style:{padding:"20px",border:"1px dashed #ccc",borderRadius:"4px",textAlign:"center",backgroundColor:"#f9f9f9"}},(0,t.createElement)("div",{style:{fontSize:"24px",marginBottom:"10px"}},"📅"),(0,t.createElement)("div",{style:{fontWeight:"bold",marginBottom:"5px"}},(0,o.__)("Calendar Content","event-genius")),(0,t.createElement)("div",{style:{color:"#666",fontSize:"14px"}},(0,o.__)("Displays the default calendar on the front end.","event-genius"))):p?(0,t.createElement)("div",{className:"evge-loading-spinner"},(0,t.createElement)(r.Spinner,null),(0,t.createElement)("p",null,(0,o.__)("Loading events...","event-genius"))):(0,t.createElement)("div",{dangerouslySetInnerHTML:{__html:s}})))},save:function(){return null}})})();