!function(){"use strict";var e={n:function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,{a:n}),n},d:function(t,n){for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}},t=window.wp.blocks,n=window.wp.primitives,r=()=>React.createElement(n.SVG,{version:"1.0",xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24"},React.createElement(n.Path,{d:"M 20.75 3.25 L 20.75 19.75 L 3.25 19.75 L 3.25 3.25 Z M 19.25 18.25 L 19.25 4.75 L 10.25 4.75 L 10.25 18.25 Z M 4.75 4.75 L 4.75 18.25 L 8.75 18.25 L 8.75 4.75 Z"}),React.createElement(n.Path,{d:"M 4 8.25 C 4.6 8.25 7.392 8.25 10.638 8.25 C 12.26 8.25 13.997 8.25 15.63 8.25 C 16.446 8.25 17.237 8.25 17.974 8.25 C 18.711 8.25 20 8.25 20 8.25 L 20 9.75 C 20 9.75 18.711 9.75 17.974 9.75 C 17.237 9.75 16.446 9.75 15.63 9.75 C 13.997 9.75 12.26 9.75 10.638 9.75 C 7.392 9.75 4.6 9.75 4 9.75 Z M 4 13.25 L 20 13.25 L 20 14.75 L 4 14.75 Z"})),a=window.wp.apiFetch,l=e.n(a),c=window.wp.blockEditor,o=window.wp.components,s=window.wp.element,i=window.wp.i18n,u=window.wp.url;var m=({attributes:e,context:t,setAttributes:n})=>{const{alignment:a,number:m}=e,[p,d]=(0,s.useState)(!1),w=(0,c.useBlockProps)(),b=p.length>m?p.slice(0,m):p;return(0,s.useEffect)((()=>{const{postId:e=0}=t;l()({path:(0,u.addQueryArgs)(`/elasticprobe/v1/related-posts/${e}`,{number:100})}).then((e=>{d(e)})).catch((()=>{d(!1)}))}),[t]),React.createElement(s.Fragment,null,React.createElement(c.BlockControls,null,React.createElement(c.AlignmentToolbar,{value:a,onChange:e=>n({alignment:e})})),React.createElement(c.InspectorControls,null,React.createElement(o.PanelBody,{title:(0,i.__)("Settings","elasticprobe")},React.createElement(o.QueryControls,{numberOfItems:m,onNumberOfItemsChange:e=>n({number:e})}))),React.createElement("div",w,!1===b||0===b.length?React.createElement(o.Placeholder,{icon:r,label:(0,i.__)("Related Posts","elasticprobe")},!1===p?React.createElement(o.Spinner,null):(0,i.__)("No related posts yet.","elasticprobe")):React.createElement(o.Disabled,null,React.createElement("ul",{style:{textAlign:a}},b.map((e=>{const t=e.title.rendered.trim();return React.createElement("li",{key:e.id},React.createElement("a",{href:e.link,onClick:e=>e.preventDefault()},t?React.createElement(s.RawHTML,null,t):(0,i.__)("(Untitled)","elasticprobe")))}))))))},p=JSON.parse('{"UU":"elasticprobe/related-posts"}'),d={from:[{type:"block",blocks:["core/legacy-widget"],isMatch:({idBase:e})=>"ep-related-posts"===e,transform:({instance:e})=>{const{title:n=null,num_posts:r}=e.raw;return n?[(0,t.createBlock)("core/heading",{content:n}),(0,t.createBlock)("elasticprobe/related-posts",{number:r})]:(0,t.createBlock)("elasticprobe/related-posts",{number:r})}}]};(0,t.registerBlockType)(p.UU,{icon:r,edit:e=>React.createElement(m,e),save:()=>{},transforms:d})}();