(()=>{"use strict";var e={n:t=>{var o=t&&t.__esModule?()=>t.default:()=>t;return e.d(o,{a:o}),o},d:(t,o)=>{for(var n in o)e.o(o,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:o[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.blocks,o=window.wp.i18n,n=window.wp.blockEditor,a=window.wp.components,i=window.wp.element,s=window.wp.apiFetch;var r=e.n(s);const l=window.wp.compose,c=window.ReactJSXRuntime;function d({block:e,attributes:t,LoadingResponsePlaceholder:o,loadCallback:n}){const[s,d]=(0,i.useState)(null),[p,u]=(0,i.useState)(!0),h=(0,i.useRef)(null),m=function(e){const t={};for(const[o,n]of Object.entries(e))o.startsWith("__")||o.startsWith("_")||(t[o]=n);return t}(t),b=(0,l.useRefEffect)(e=>{n?.(e)},[s]);if((0,i.useEffect)(()=>{const t=JSON.stringify(m);t===h.current&&s?u(!1):(h.current=t,u(!0),r()({path:`/wp/v2/block-renderer/${e}`,method:"POST",data:{attributes:m,context:"edit"}}).then(e=>{d(e.rendered),u(!1)}))},[m,e,s]),p&&!s){if(o){const e=o;return(0,c.jsx)(e,{})}return(0,c.jsx)("p",{children:"Loading…"})}return(0,c.jsx)(a.Disabled,{children:(0,c.jsx)("div",{ref:b,dangerouslySetInnerHTML:{__html:null!=s?s:""}})})}const p=e=>{const[t,n]=(0,i.useState)([]),[s,l]=(0,i.useState)([]),[d,p]=(0,i.useState)([]);return(0,i.useEffect)(()=>{(async()=>{try{const e=(await r()({path:"mphb/v1/accommodation_types"})).map(e=>({...e,id:String(e.id)}));p(e),l(e?.map(e=>e.title)||[])}catch(e){console.error(e)}})()},[]),(0,i.useEffect)(()=>{const t=d.filter(t=>e.value.includes(t.id)).map(e=>e.title);n(t)},[d,e.value]),(0,c.jsx)(a.BaseControl,{children:(0,c.jsx)(a.FormTokenField,{label:(0,o.__)("Accommodation types to display","motopress-hotel-booking"),value:t,suggestions:s,onChange:t=>{const o=[];for(const e of t){const t=d.find(t=>t.title===e)?.id;t&&o.push(t)}e.onChange(o)},__experimentalShowHowTo:!1,__experimentalExpandOnFocus:!0})})},u=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"motopress-hotel-booking/group-availability-calendar","version":"1.0.0","title":"Multi-Property Availability Calendar","description":"Displays a list of accommodation types and their availability by date in one view.","category":"hotel-booking","icon":"calendar-alt","example":{},"supports":{"align":["full","wide"],"html":false},"attributes":{"start_date":{"type":"string","default":"","_comment":"Format: YYYY-MM-DD"},"accommodation_type_ids":{"type":"string","default":""}},"textdomain":"motopress-hotel-booking","editorScript":"file:./index.js","style":"mphb-shortcodes-group-availability-calendar-css","render":"file:./render.php","script":"mphb-shortcodes-group-availability-calendar-js"}');(0,t.registerBlockType)(u,{edit:function(e){const{attributes:t,setAttributes:i}=e;return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(n.InspectorControls,{children:(0,c.jsxs)(a.PanelBody,{title:(0,o.__)("Settings","motopress-hotel-booking"),initialOpen:!0,children:[(0,c.jsx)(a.TextControl,{label:(0,o.__)("Start date","motopress-hotel-booking"),value:t.start_date,type:"date",autoComplete:"off",onChange:e=>{i({start_date:e})}}),(0,c.jsx)(p,{value:t.accommodation_type_ids.split(","),onChange:e=>{i({accommodation_type_ids:e.join(",")})}})]})}),(0,c.jsx)("div",{...(0,n.useBlockProps)(),children:(0,c.jsx)(d,{block:"motopress-hotel-booking/group-availability-calendar",attributes:t,loadCallback:e=>{MotoPressGroupAvailabilityCalendarShortcode.reInit(e)},LoadingResponsePlaceholder:()=>(0,c.jsx)(a.Placeholder,{icon:"calendar-alt",label:(0,o.__)("Multi-Property Availability Calendar","motopress-hotel-booking"),children:(0,c.jsx)("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",width:"100%"},children:(0,c.jsx)(a.Spinner,{})})})})})]})},save:function(){return null}})})();