(()=>{"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,s=window.wp.components,a=window.wp.element,i=window.wp.apiFetch;var r=e.n(i);const l=window.wp.compose,d=window.ReactJSXRuntime;function c({block:e,attributes:t,LoadingResponsePlaceholder:o,loadCallback:n}){const[i,c]=(0,a.useState)(null),[p,u]=(0,a.useState)(!0),h=(0,a.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),g=(0,l.useRefEffect)(e=>{n?.(e)},[i]);if((0,a.useEffect)(()=>{const t=JSON.stringify(m);t===h.current&&i?u(!1):(h.current=t,u(!0),r()({path:`/wp/v2/block-renderer/${e}`,method:"POST",data:{attributes:m,context:"edit"}}).then(e=>{c(e.rendered),u(!1)}))},[m,e,i]),p&&!i){if(o){const e=o;return(0,d.jsx)(e,{})}return(0,d.jsx)("p",{children:"Loading…"})}return(0,d.jsx)(s.Disabled,{children:(0,d.jsx)("div",{ref:g,dangerouslySetInnerHTML:{__html:i??""}})})}const p=window.wp.data,u=window.wp.coreData,h=e=>{const[t,n]=(0,a.useState)([]),[i,r]=(0,a.useState)(1),[l,c]=(0,a.useState)([]),{records:h,totalPages:m,isLoading:g}=(0,p.useSelect)(e=>{const t=e(u.store),o={per_page:100,page:i};return{records:t.getEntityRecords("postType","mphb_room_type",o),totalPages:t.getEntityRecordsTotalPages("postType","mphb_room_type",{per_page:100}),isLoading:t.isResolving("getEntityRecords",["postType","mphb_room_type",o])}},[i]);(0,a.useEffect)(()=>{h&&(c(e=>{const t=[...e];return h.forEach(e=>{t.find(t=>t.id===e.id)||t.push(e)}),t}),m&&i<m&&r(e=>e+1))},[h,m]);const b=(0,a.useMemo)(()=>l.map(e=>e.title.raw),[l]);return(0,a.useEffect)(()=>{const t=l.filter(t=>e.value.includes(t.id.toString())).map(e=>e.title.raw);n(t)},[l,e.value]),(0,d.jsx)(s.BaseControl,{children:(0,d.jsxs)(s.Flex,{children:[(0,d.jsx)(s.FormTokenField,{label:(0,o.__)("Accommodation types to display","motopress-hotel-booking"),value:t,suggestions:b,onChange:t=>{const o=[];for(const e of t){const t=l.find(t=>t.title.raw===e)?.id;t&&o.push(t.toString())}e.onChange(o)},__experimentalShowHowTo:!1,__experimentalExpandOnFocus:!0,disabled:g}),g&&(0,d.jsx)(s.Spinner,{})]})})},m=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)(m,{edit:function(e){const{attributes:t,setAttributes:a}=e;return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(n.InspectorControls,{children:(0,d.jsxs)(s.PanelBody,{title:(0,o.__)("Settings","motopress-hotel-booking"),initialOpen:!0,children:[(0,d.jsx)(s.TextControl,{label:(0,o.__)("Start date","motopress-hotel-booking"),value:t.start_date,type:"date",autoComplete:"off",onChange:e=>{a({start_date:e})}}),(0,d.jsx)(h,{value:t.accommodation_type_ids.split(","),onChange:e=>{a({accommodation_type_ids:e.join(",")})}})]})}),(0,d.jsx)("div",{...(0,n.useBlockProps)(),children:(0,d.jsx)(c,{block:"motopress-hotel-booking/group-availability-calendar",attributes:t,loadCallback:e=>{MotoPressGroupAvailabilityCalendarShortcode.reInit(e)},LoadingResponsePlaceholder:()=>(0,d.jsx)(s.Placeholder,{icon:"calendar-alt",label:(0,o.__)("Multi-Property Availability Calendar","motopress-hotel-booking"),children:(0,d.jsx)("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",width:"100%"},children:(0,d.jsx)(s.Spinner,{})})})})})]})},save:function(){return null}})})();