(()=>{"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 o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.blocks,n=window.React,o=window.wp.blockEditor,i=window.wp.components,l=window.wp.i18n,r=window.wp.apiFetch;var s=e.n(r);const a=window.ReactJSXRuntime,d=["Su","Mo","Tu","We","Th","Fr","Sa"];function p({eventTitle:e,eventType:t,price:n}){const o=new Date,i=o.toLocaleString(void 0,{month:"long",year:"numeric"}),r=new Date(o.getFullYear(),o.getMonth(),1).getDay(),s=new Date(o.getFullYear(),o.getMonth()+1,0).getDate(),p=[];for(let e=0;e<35;e++){const t=e-r+1;p.push(t>0&&t<=s?t:null)}const c="one-on-one"===t||"group"===t;return(0,a.jsxs)("div",{style:{background:"#fff",border:"1px solid #e2e8f0",borderRadius:"8px",overflow:"hidden",fontSize:"12px",maxWidth:"400px"},children:[(0,a.jsxs)("div",{style:{padding:"12px 16px",borderBottom:"1px solid #e2e8f0",background:"#f8fafc"},children:[(0,a.jsx)("strong",{style:{color:"#1e293b",fontSize:"14px"},children:e}),n&&(0,a.jsxs)("span",{style:{color:"#64748b",fontSize:"13px",marginLeft:"8px"},children:[n,c&&(0,a.jsx)("span",{style:{fontSize:"11px"},children:" / "+(0,l.__)("session","nemtly-booking")})]})]}),(0,a.jsx)("div",{style:{padding:"10px 16px 4px",fontSize:"11px",fontWeight:600,textTransform:"uppercase",color:"#64748b"},children:(0,l.__)("Select a Date","nemtly-booking")}),(0,a.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 16px"},children:[(0,a.jsx)("span",{style:{color:"#94a3b8",cursor:"default"},children:"‹"}),(0,a.jsx)("strong",{style:{color:"#334155",fontSize:"13px"},children:i}),(0,a.jsx)("span",{style:{color:"#94a3b8",cursor:"default"},children:"›"})]}),(0,a.jsx)("div",{style:{padding:"0 12px 12px"},children:(0,a.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(7, 1fr)",gap:"1px",textAlign:"center"},children:[d.map((e=>(0,a.jsx)("div",{style:{color:"#94a3b8",fontSize:"10px",fontWeight:600,padding:"4px 0"},children:e},e))),p.map(((e,t)=>{const n=e===o.getDate();return(0,a.jsx)("div",{style:{padding:"6px 2px",minHeight:"28px",fontSize:"11px",color:e?n?"#fff":"#475569":"transparent",background:n?"#334155":"transparent",borderRadius:n?"50%":"0",width:n?"24px":"auto",height:n?"24px":"auto",display:"flex",alignItems:"center",justifyContent:"center",margin:"auto"},children:e||""},t)}))]})}),(0,a.jsx)("div",{style:{textAlign:"center",padding:"6px",color:"#94a3b8",fontSize:"11px",borderTop:"1px solid #e2e8f0",background:"#f8fafc"},children:(0,l.__)("Booking Calendar","nemtly-booking")})]})}const c=JSON.parse('{"UU":"nemtly/booking-calendar"}');(0,t.registerBlockType)(c.UU,{edit:function({attributes:e,setAttributes:t}){const{eventId:r}=e,d=(0,o.useBlockProps)({className:"nb-booking-calendar-block-preview"}),[c,g]=(0,n.useState)([]),[x,u]=(0,n.useState)(!0),[y,f]=(0,n.useState)(null);(0,n.useEffect)((()=>{s()({path:"/nemtly-booking/v1/events?per_page=100&event_type=one-on-one,group"}).then((e=>{const t=e?.result||e?.results||e||[];g(Array.isArray(t)?t:[]),u(!1)})).catch((()=>{s()({path:"/wp/v2/nemtly_event?per_page=100&status=publish"}).then((e=>{const t=(e||[]).map((e=>({id:e.id,title:e.title?.rendered||e.title,event_type:e.meta?.nemtly_event_type||"",price:e.meta?.nemtly_price||0,currency_symbol:""})));g(t),u(!1)})).catch((()=>{g([]),u(!1)}))}))}),[]),(0,n.useEffect)((()=>{if(r&&c.length){const e=c.find((e=>e.id===r));if(e){const t="object"==typeof e.title?e.title.rendered||"":e.title||"";f({...e,title:t})}else f(null)}else f(null)}),[r,c]);const h=(0,n.useMemo)((()=>c.map((e=>{const t="object"==typeof e.title?e.title.rendered||"":e.title||"";return{value:String(e.id),label:t||`Event #${e.id}`}}))),[c]),b=e=>{t({eventId:e?parseInt(e,10):0})};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(o.InspectorControls,{children:(0,a.jsx)(i.PanelBody,{title:(0,l.__)("Booking Calendar Settings","nemtly-booking"),children:x?(0,a.jsx)(i.Spinner,{}):(0,a.jsx)(i.ComboboxControl,{label:(0,l.__)("Select Event","nemtly-booking"),value:r?String(r):"",options:h,onChange:b,help:(0,l.__)("Choose the event to display the booking calendar for.","nemtly-booking")})})}),(0,a.jsx)("div",{...d,children:r?(0,a.jsx)(p,{eventTitle:y?.title||`Event #${r}`,eventType:y?.event_type||"",price:y?.price?`$${y.price}`:""}):(0,a.jsx)(i.Placeholder,{icon:"calendar",label:(0,l.__)("Booking Calendar","nemtly-booking"),instructions:(0,l.__)("Select an event from the block settings panel to display its booking calendar.","nemtly-booking"),children:x?(0,a.jsx)(i.Spinner,{}):(0,a.jsx)(i.ComboboxControl,{value:r?String(r):"",options:h,onChange:b,placeholder:(0,l.__)("Search for an event…","nemtly-booking")})})})]})},save:()=>null})})();