(()=>{"use strict";const e=window.wp.element,t=window.wp.blocks,r=window.wp.blockEditor,s=window.wp.components,a=window.wp.serverSideRender,o=window.wp.i18n,i=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"wpra-shortcode/wpra-shortcode","version":"1.0.0","title":"RSS Aggregator Display","category":"widgets","icon":"rss","description":"Display RSS feed content","keywords":["wpra","display","aggregator","rss","feed"],"supports":{"align":true,"html":false},"attributes":{"id":{"type":"number","default":0},"align":{"type":"string"},"isAll":{"type":"boolean"},"template":{"type":"string"},"pagination":{"type":"boolean"},"page":{"type":"number"},"limit":{"type":"number"},"exclude":{"type":"string"},"source":{"type":"string"},"className":{"type":"string"}},"textdomain":"wprss","editorScript":"wpra-block","editorStyle":["wpra-displays","wpra-et-layout-css","wpra-grid-layout-css"],"style":["wpra-displays","wpra-et-layout-css","wpra-grid-layout-css"],"render":"server-render"}'),l=window.ReactJSXRuntime,n={edit:t=>{const{attributes:i,setAttributes:n}=t,{align:c,id:p}=i,u=[{value:"0",label:(0,o.__)("Select a display","wp-rss-aggregator")},...WpraDisplayBlock.displayOptions.map(((e,t)=>({value:e.value,label:e.label,reactkey:`display-option-${t}`})))],[d,g]=(0,e.useState)([]),[w,y]=(0,e.useState)(""),h=t.attributes.isAll?t.attributes.exclude?String(t.attributes.exclude).split(","):[]:t.attributes.source?String(t.attributes.source).split(","):[];return(0,e.useEffect)((()=>{Array.isArray(h)&&h.length>0&&(async()=>{try{const t=await fetch(WpraDisplayBlock.ajaxURL,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({action:"wpra_rpc",nonce:WpraDisplayBlock.rpcNonce,rpc:JSON.stringify({version:1,type:"batch",actions:[{id:"sources.getNamesByV4ID",args:[Array.isArray(h)?h:[h]]}]})})}),r=await t.json();if(r.results&&r.results[0]&&"ok"===r.results[0].type){const t=Object.values(r.results[0].value);g(t);let s=(0,e.createInterpolateElement)((0,o.__)("Feed sources are currently disabled for this block. To migrate it to v5, first create a Display with your preferred layout and feed sources. Then, select that Display from the dropdown above. <contactSupportLink>Learn more</contactSupportLink>","wp-rss-aggregator"),{contactSupportLink:(0,l.jsx)("a",{href:"https://www.wprssaggregator.com/help/creating-a-display/",className:"underline text-primary cursor-pointer inline",target:"_blank"})});t.some((e=>e.includes("Missing")))&&(s=(0,e.createInterpolateElement)((0,o.__)("This block has been switched to v5, but one or more sources haven’t been migrated yet, which may cause them to appear as missing. Please migrate all sources first, then create a Display with your layout and sources, and select it from the dropdown above. <contactSupportLink>Learn more</contactSupportLink>","wp-rss-aggregator"),{contactSupportLink:(0,l.jsx)("a",{href:"https://www.wprssaggregator.com/help/creating-a-display/",className:"underline text-primary cursor-pointer inline",target:"_blank"})})),y(s)}}catch(e){console.log(e)}})()}),[]),(0,l.jsxs)("div",{...(0,r.useBlockProps)({className:c}),children:[(0,l.jsx)(r.BlockControls,{children:(0,l.jsx)(s.ToolbarGroup,{children:(0,l.jsx)(r.AlignmentControl,{value:c,onChange:e=>n({align:e}),controls:["wide","full","left","right","center"]})})}),(0,l.jsx)(a,{block:"wpra-shortcode/wpra-shortcode",attributes:t.attributes,className:"wpra-gutenberg-block"}),(0,l.jsx)(r.InspectorControls,{children:(0,l.jsxs)(s.PanelBody,{children:[(0,l.jsx)(s.SelectControl,{__nextHasNoMarginBottom:!0,label:(0,o.__)("Display","wp-rss-aggregator"),value:p.toString(),options:u,onChange:e=>n({id:Number(e)})}),!p&&h.length>0&&(0,l.jsx)(s.Disabled,{children:(0,l.jsx)(s.TextControl,{style:{background:"#F0F0F0",border:"#CCC",color:"#949494"},help:w,__nextHasNoMarginBottom:!0,label:t.attributes.isAll?(0,o.__)("Feed Sources to Exclude","wp-rss-aggregator"):(0,o.__)("Feed Sources to Show","wp-rss-aggregator"),value:d})})]})})]})},save:()=>null};(0,t.registerBlockType)(i,n)})();