(()=>{"use strict";const e=window.React,t=window.wp.blocks,n=window.wp.element,a=JSON.parse('{"UU":"em/event-when"}'),o="em-event-when-block";let i="when";function s(e){return String(e??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}const r=`\n.${o} {\n\tmax-width: 920px;\n\tmargin: 16px auto;\n\tpadding: 20px 24px;\n\tborder: 1px solid #e0e0e0;\n\tborder-radius: 8px;\n\tbackground: #fff;\n\tbox-sizing: border-box;\n}\n.${o} .em-canvas-tabs {\n\tdisplay: flex;\n\tgap: 4px;\n\tmargin: 0 0 16px;\n\tborder-bottom: 1px solid #ddd;\n}\n.${o} .em-canvas-tab {\n\tappearance: none;\n\tbackground: none;\n\tborder: none;\n\tborder-bottom: 3px solid transparent;\n\tcursor: pointer;\n\tfont-size: 14px;\n\tfont-weight: 500;\n\tpadding: 8px 14px;\n\tmargin-bottom: -1px;\n\tcolor: inherit;\n\topacity: 0.7;\n}\n.${o} .em-canvas-tab:hover {\n\topacity: 1;\n}\n.${o} .em-canvas-tab.is-active {\n\tborder-bottom-color: var( --wp-admin-theme-color, #3858e9 );\n\tfont-weight: 600;\n\topacity: 1;\n}\n.${o} .em-canvas-tab-panel[hidden] {\n\tdisplay: none;\n}\n`;function c(e,t){const n=e.querySelectorAll(".em-canvas-tab-panel"),a=e.querySelectorAll(".em-canvas-tab");e.querySelector(`.em-canvas-tab-panel[data-em-tab="${t}"]`)||(t=n[0]?.getAttribute("data-em-tab")||"when"),i=t,n.forEach(e=>{e.hidden=e.getAttribute("data-em-tab")!==t}),a.forEach(e=>{e.classList.toggle("is-active",e.getAttribute("data-em-tab-target")===t)})}(0,t.registerBlockType)(a.UU,{edit:function(){const t=(0,n.useRef)(null);function a(){const e=t.current;if(!e)return;if("canvas"!==(window.EM_EDITOR_TABS?.layout||"canvas"))return e.innerHTML="",void(e.style.display="none");const n=window._wpMetaBoxUrl;n&&fetch(n,{credentials:"same-origin"}).then(e=>e.text()).then(t=>{const n=(new DOMParser).parseFromString(t,"text/html"),a=(window.EM_EDITOR_TABS?.tabs||[]).filter(e=>e.canvas_support).map(e=>({id:e.id,label:e.label,boxes:(e.metaboxes||[]).filter(e=>e.canvas_support).map(e=>({id:e.id,className:(e.class||"").trim(),inside:n.getElementById(e.id)?.querySelector(".inside")})).filter(e=>e.inside)})).filter(e=>e.boxes.length);if("function"==typeof window.em_unsetup_ui_elements)try{window.em_unsetup_ui_elements(e)}catch(e){}if(e.innerHTML="",e.insertAdjacentHTML("beforeend",`<style>${r}</style>`),a.length>1){const t=a.map(e=>'<button type="button" class="em-canvas-tab" role="tab" data-em-tab-target="'+s(e.id)+'">'+s(e.label)+"</button>").join("");e.insertAdjacentHTML("beforeend",'<div class="em-canvas-tabs" role="tablist">'+t+"</div>")}const o=a.map((e,t)=>{const n=e.boxes.map(e=>"<div"+(e.className?' class="'+s(e.className)+'"':"")+' data-em-metabox="'+s(e.id)+'">'+e.inside.innerHTML+"</div>").join("");return'<div class="em-canvas-tab-panel" data-em-tab="'+s(e.id)+'"'+(t>0?" hidden":"")+">"+n+"</div>"}).join("");e.insertAdjacentHTML("beforeend",'<div class="wp-admin wp-core-ui em-event-editor"><form class="em-canvas-form" novalidate>'+o+"</form></div>"),e.querySelector("form.em-canvas-form")?.addEventListener("submit",e=>e.preventDefault()),e.querySelectorAll(".em-canvas-tab").forEach(t=>{t.addEventListener("click",()=>{c(e,t.getAttribute("data-em-tab-target"))})}),c(e,i);const l=e.ownerDocument.defaultView||window,d="canvas"===(window.EM_EDITOR_TABS?.layout||"canvas")&&l!==window,m=d&&"function"==typeof l.em_setup_ui_elements?l.em_setup_ui_elements:window.em_setup_ui_elements;if("function"==typeof m)try{m(e)}catch(e){}if(d)if("function"==typeof l.emRecurrenceFormRoot)try{l.document.dispatchEvent(new l.CustomEvent("em_event_editor_ready"))}catch(e){}else if("function"==typeof l.em_setup_scripts)try{l.em_setup_scripts(e)}catch(e){}const p=d?l:window;if(e.querySelector(".em-location-map, .em-locations-map"))try{p.em_maps_loaded&&"function"==typeof p.em_maps_load_location?(e.querySelectorAll(".em-location-map").forEach(e=>p.em_maps_load_location(e)),e.querySelectorAll(".em-locations-map").forEach(e=>p.em_maps_load_locations&&p.em_maps_load_locations(e))):"function"==typeof p.em_maps_load&&p.em_maps_load()}catch(e){}}).catch(e=>{console.error("[EM] event-when block: fetch failed",e)})}return(0,n.useEffect)(()=>(a(),window.emReloadWhenBlock=a,()=>{window.emReloadWhenBlock=null;const e=t.current;if(e&&"function"==typeof window.em_unsetup_ui_elements)try{window.em_unsetup_ui_elements(e)}catch(e){}}),[]),(0,e.createElement)("div",{className:`${o} em`,ref:t})},save:()=>null})})();