(()=>{"use strict";const e=window.wp.compose,t=window.wp.element,c=window.wp.blockEditor,n=window.wp.components,a=window.wp.blocks,o=window.wp.serverSideRender;function l(e){if(!e||!e.dataset.id||e.dataset.process)return;e.dataset.process=!0;const t=e.querySelector(".gutendraw-image");if(!t)return;const c=GutendrawImageBlock,n=e.dataset.id;fetch(`${c.api.public_url}/images/${n}`).then((e=>e.json())).then((c=>{t.innerHTML=c.image,e.classList.add("gutendraw-ready"),delete e.dataset.process}))}const s=JSON.parse('{"UU":"gutendraw/image-block"}'),r=GutendrawImageBlock;(0,a.registerBlockType)(s.UU,{edit:a=>{const{attributes:i,setAttributes:d}=a,{itemId:u,showTitle:m}=i,[w,p]=(0,t.useState)([]);(0,t.useEffect)((()=>{fetch(r.api.url+"/items",{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":r.api.nonce,"X-HTTP-Method-Override":"GET"},cache:"no-cache"}).then((e=>e.json())).then((e=>{if(e.success){const t=e.data.map((e=>({value:e.id,label:e.title})));t.unshift({value:"",label:"None"}),p(t)}}))}),[]);const h=(0,e.useRefEffect)((e=>{const t=new MutationObserver(((e,t)=>{for(let t of e)for(let e of t.addedNodes)"DIV"==e.tagName&&e.classList.contains("ssrblock")&&l(e.querySelector(".gutendraw"))}));return t.observe(e,{childList:!0,subtree:!1}),()=>{t.disconnect()}}),[]),b=(0,t.useMemo)((()=>React.createElement(o,{block:s.UU,attributes:i,className:"ssrblock"})),[i]);return React.createElement(React.Fragment,null,React.createElement(c.InspectorControls,null,React.createElement(n.PanelBody,{title:r.i18n.block_settings,initialOpen:!0},React.createElement(n.SelectControl,{label:r.i18n.block_select_item,value:u,options:w,onChange:e=>{d({itemId:e})}}),React.createElement(n.ToggleControl,{label:r.i18n.block_show_title,checked:m,onChange:e=>{d({showTitle:e})}}))),React.createElement(c.BlockControls,null,u&&React.createElement(n.ToolbarGroup,null,React.createElement(n.ToolbarButton,{label:r.i18n.block_edit,onClick:()=>{const e=new URL(r.data.url_edit);e.searchParams.set("id",u),window.open(e.href,"_blank").focus()}},r.i18n.block_edit))),React.createElement("div",(0,c.useBlockProps)({ref:h}),b))},icon:{src:React.createElement("svg",{width:"24",height:"24",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},React.createElement("path",{d:"m18.447 1.1565c-0.44023-0.43911-1.0117-0.45733-1.4701-2e-7l-16.171 16.15v5.8728h5.8803l16.171-16.15c0.45849-0.45839 0.44106-1.0288 1e-6 -1.4682zm-0.73504 2.2023 2.9401 2.9364-1.4701 1.4682-2.9401-2.9364zm-2.9401 2.9364 2.9401 2.9364-10.29 10.277-2.9401-2.9364zm-11.761 11.746 2.9401 2.9364h-2.9401zm3.3697-17.22c-0.25977 0.0022195-0.51626 0.11922-0.74023 0.34375l-4.4922 4.4902c-0.44764 0.44821-0.46622 1.0294 0 1.4961l4.1621 4.1641 1.5-1.498c-0.2994-0.30021-0.60002-0.59919-0.90039-0.89844l1.5039-1.5039-1.4141-1.4141-1.5039 1.5039c-0.36896-0.36607-0.736-0.73405-1.1035-1.1016l2.9961-2.9941 3.4141 3.416 1.4941-1.4961-4.1602-4.1641c-0.23364-0.23341-0.49609-0.34597-0.75586-0.34375zm12.291 11.881-1.4961 1.4961 3.4297 3.4316-2.9922 2.9922c-0.37391-0.37088-0.74533-0.74425-1.1172-1.1172l1.5039-1.5039-1.4141-1.4141-1.5039 1.5039c-0.30109-0.29787-0.59938-0.59853-0.89844-0.89844l-1.4961 1.498 4.1758 4.1777c0.47328 0.473 1.118 0.37827 1.5723-0.07617l4.4141-4.4141c0.44853-0.44783 0.46709-1.0298 0-1.4961z"}))}})})();