File: /home/u1694298/www/wp-content/plugins/yop-poll/build/block/index.js
(()=>{"use strict";var l={n:e=>{var o=e&&e.__esModule?()=>e.default:()=>e;return l.d(o,{a:o}),o},d:(e,o)=>{for(var t in o)l.o(o,t)&&!l.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:o[t]})},o:(l,e)=>Object.prototype.hasOwnProperty.call(l,e)};const e=window.wp.blocks,o=window.wp.element,t=window.wp.blockEditor,n=window.wp.components,p=window.wp.i18n,r=window.wp.apiFetch;var a=l.n(r);const s=window.ReactJSXRuntime,i=JSON.parse('{"UU":"yop-poll/poll"}');(0,e.registerBlockType)(i.UU,{edit:function({attributes:l,setAttributes:e}){const{pollId:r}=l,i=(0,t.useBlockProps)(),[c,d]=(0,o.useState)([]),[h,w]=(0,o.useState)(!0);(0,o.useEffect)(()=>{a()({path:"yop-poll/v1/polls?per_page=100"}).then(l=>{d(l.items||[]),w(!1)}).catch(()=>w(!1))},[]);const u=[{value:0,label:(0,p.__)("— Select a poll —","yop-poll")},...c.map(l=>({value:l.id,label:l.name||`Poll #${l.id}`}))],_=c.find(l=>parseInt(l.id,10)===r);return(0,s.jsxs)("div",{...i,children:[(0,s.jsx)(t.InspectorControls,{children:(0,s.jsx)(n.PanelBody,{title:(0,p.__)("Poll Settings","yop-poll"),children:(0,s.jsx)(n.SelectControl,{label:(0,p.__)("Select Poll","yop-poll"),value:r,options:u,onChange:l=>e({pollId:parseInt(l,10)})})})}),h?(0,s.jsx)(n.Placeholder,{icon:"chart-bar",label:(0,p.__)("YOP Poll","yop-poll"),children:(0,s.jsx)(n.Spinner,{})}):r&&_?(0,s.jsx)(n.Placeholder,{icon:"chart-bar",label:(0,p.__)("YOP Poll","yop-poll"),instructions:_.name,children:(0,s.jsx)("p",{children:(0,p.__)("This poll will be rendered on the frontend.","yop-poll")})}):(0,s.jsx)(n.Placeholder,{icon:"chart-bar",label:(0,p.__)("YOP Poll","yop-poll"),instructions:(0,p.__)("Select a poll to display.","yop-poll"),children:(0,s.jsx)(n.SelectControl,{value:r,options:u,onChange:l=>e({pollId:parseInt(l,10)})})})]})},save:()=>null})})();