import{getContext as o,store as e,withSyncEvent as t}from"@wordpress/interactivity";function n(o,e){if(!o)return null;const t=window.getComputedStyle(o)[e];if("rgba(0, 0, 0, 0)"!==t&&"transparent"!==t){const o=t.match(/\d+/g);if(!o||o.length<3)return null;const[e,n,s]=o.slice(0,3);return`rgb(${e}, ${n}, ${s})`}return n(o.parentElement,e)}!function(){const o=document.querySelector(".wc-bookings-calendar");if(!o)return;const e=document.createElement("style"),t=n(o,"backgroundColor")||"#fff",s=n(o,"color")||"#000";e.appendChild(document.createTextNode(`:where(.wc-bookings-calendar),\n\t\t\t:where(.wc-bookings-modal) {\n\t\t\t\t--wc-bookings--calendar--color: ${s};\n\t\t\t\t--wc-bookings--calendar--background-color: ${t};\n\t\t\t}`)),document.head.appendChild(e)}();const{state:s}=e("woocommerce-bookings/booking-form",{}),{state:r,actions:i}=e("woocommerce-bookings/booking-modal",{state:{ui:{openByProductId:null},get isModalOpen(){const o=s.currentProductId;return r.ui.openByProductId===o},get shouldHideAddToCartButton(){const e=o("woocommerce-bookings/booking-form");return!e.selectedSlotKey||!e.selectedDate}},actions:{handleTabNavigation:o=>{if(!r.isModalOpen||"Tab"!==o.key)return;const e=document.querySelector(".wc-bookings-modal[open]");if(!e)return;const t=Array.from(e.querySelectorAll('a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), [tabindex]:not([tabindex="-1"])')).filter(o=>!o.hasAttribute("inert"));if(!t.length)return;const n=t[0],s=t[t.length-1],i=e.ownerDocument.activeElement;return e.contains(i)&&(o.shiftKey||i!==s)?void(o.shiftKey&&i===n&&(o.preventDefault(),o.stopPropagation(),s.focus())):(o.preventDefault(),o.stopPropagation(),void n.focus())},onModalKeyDown:t(o=>{if(r.isModalOpen)return"Escape"===o.key?(o.preventDefault(),void i.closeModal()):void("Tab"===o.key&&i.handleTabNavigation(o))}),openModal:()=>{const o=s.currentProductId;o&&(r.ui.openByProductId=o),function(){if("undefined"==typeof document)return;const o=document.body;if(!o||o.dataset.wcBookingsScrollLock)return;const e=window.scrollY||window.pageYOffset;o.dataset.wcBookingsScrollLock="1",o.dataset.wcBookingsScrollY=String(e),o.dataset.wcBookingsPrevOverflow=o.style.overflow||"",o.dataset.wcBookingsPrevPosition=o.style.position||"",o.dataset.wcBookingsPrevTop=o.style.top||"",o.dataset.wcBookingsPrevWidth=o.style.width||"",o.style.overflow="hidden",o.style.position="fixed",o.style.top=`-${e}px`,o.style.width="100%"}()},closeModal:()=>{r.ui.openByProductId=null,function(){if("undefined"==typeof document)return;const o=document.body;if(!o||!o.dataset.wcBookingsScrollLock)return;const e=Number(o.dataset.wcBookingsScrollY||0);o.style.overflow=o.dataset.wcBookingsPrevOverflow||"",o.style.position=o.dataset.wcBookingsPrevPosition||"",o.style.top=o.dataset.wcBookingsPrevTop||"",o.style.width=o.dataset.wcBookingsPrevWidth||"",delete o.dataset.wcBookingsScrollLock,delete o.dataset.wcBookingsScrollY,delete o.dataset.wcBookingsPrevOverflow,delete o.dataset.wcBookingsPrevPosition,delete o.dataset.wcBookingsPrevTop,delete o.dataset.wcBookingsPrevWidth,window.scrollTo(0,Number.isFinite(e)?e:0)}()}},callbacks:{focusModalWhenOpen(){r.isModalOpen&&setTimeout(()=>{const o=document.querySelector(".wc-bookings-modal[open]");o?.focus()},0)}}});