"use strict";(globalThis.webpackChunkacadlix=globalThis.webpackChunkacadlix||[]).push([["quiz_leaderboard_shortcode_block"],{"./src/blocks/quiz-leaderboard-shortcode/index.js":(e,s,r)=>{var t=r("@wordpress/blocks"),o=r("@wordpress/block-editor"),i=r("@wordpress/components"),a=r("@wordpress/i18n"),d=r("@wordpress/api-fetch"),l=r.n(d),n=r("@wordpress/element"),c=r("react/jsx-runtime");(0,t.registerBlockType)("acadlix/quiz-leaderboard-shortcode",{apiVersion:3,title:(0,a.__)("Acadlix Quiz Leaderboard","acadlix"),icon:"editor-code",category:"text",attributes:{shortcodeId:{type:"number",default:0}},edit:function({attributes:e,setAttributes:s}){const r=(0,o.useBlockProps)(),{shortcodeId:t}=e,[d,u]=(0,n.useState)([]),[p,b]=(0,n.useState)(!0),[x,h]=(0,n.useState)("");(0,n.useEffect)(()=>{let e=!0;return l()({path:"/acadlix/v1/block-quiz-shortcodes"}).then(s=>{if(!e)return;const r=Array.isArray(s?.items)?s.items:[],t=[{label:(0,a.__)("Select a quiz","acadlix"),value:"0"},...r.map(e=>({label:e?.label||(0,a.__)("Untitled Quiz","acadlix"),value:String(e?.value||0)}))];u(t)}).catch(s=>{e&&h(s?.message||(0,a.__)("Unable to load quiz list from server.","acadlix"))}).finally(()=>{e&&b(!1)}),()=>{e=!1}},[]);const w=["[Acadlix_Leaderboard"];t>0&&w.push(String(t));const _=e=>{const r=parseInt(e,10);s({shortcodeId:Number.isNaN(r)?0:Math.max(0,r)})},m=()=>(0,c.jsxs)(i.PanelBody,{title:(0,a.__)("Quiz Leaderboard Settings","acadlix"),initialOpen:!0,children:[p?(0,c.jsx)(i.Spinner,{}):null,(0,c.jsx)(i.ComboboxControl,{label:(0,a.__)("Quiz","acadlix"),value:String(t||0),options:d,onChange:_,help:(0,a.__)("Select a quiz shortcode from server list.","acadlix"),disabled:p||!!x}),x?(0,c.jsx)(i.Notice,{status:"error",isDismissible:!1,children:x}):null]});return(0,c.jsxs)("div",{...r,children:[(0,c.jsx)(o.InspectorControls,{children:m()}),m(),t>0?(0,c.jsxs)(i.Notice,{status:"info",isDismissible:!1,children:[(0,a.__)("Shortcode to render:","acadlix")," ",`${w.join(" ")}]`]}):(0,c.jsx)(i.Notice,{status:"warning",isDismissible:!1,children:(0,a.__)("Set a valid Shortcode ID to render the leaderboard.","acadlix")})]})},save:function({attributes:e}){const{shortcodeId:s}=e;if(!s||0===s)return null;const r=["[Acadlix_Leaderboard"];r.push(String(s)),r.push("]");const t=r.join(" ");return(0,c.jsx)(n.RawHTML,{children:t})}})},"@wordpress/api-fetch":e=>{e.exports=window.wp.apiFetch},"@wordpress/block-editor":e=>{e.exports=window.wp.blockEditor},"@wordpress/blocks":e=>{e.exports=window.wp.blocks},"@wordpress/components":e=>{e.exports=window.wp.components},"@wordpress/element":e=>{e.exports=window.wp.element},"@wordpress/i18n":e=>{e.exports=window.wp.i18n},"react/jsx-runtime":e=>{e.exports=window.ReactJSXRuntime}},e=>{e(e.s="./src/blocks/quiz-leaderboard-shortcode/index.js")}]);