"use strict";(globalThis.webpackChunkacadlix=globalThis.webpackChunkacadlix||[]).push([["quiz_shortcode_block"],{"./src/blocks/quiz-shortcode/index.js":(e,t,l)=>{var a=l("@wordpress/blocks"),i=l("@wordpress/block-editor"),s=l("@wordpress/components"),o=l("@wordpress/i18n"),r=l("@wordpress/api-fetch"),d=l.n(r),n=l("@wordpress/element"),c=l("react/jsx-runtime");(0,a.registerBlockType)("acadlix/quiz-shortcode",{apiVersion:3,title:(0,o.__)("Acadlix Quiz","acadlix"),icon:"editor-code",category:"text",attributes:{shortcodeId:{type:"number",default:0},template:{type:"string",default:""},fields:{type:"string",default:""}},edit:function({attributes:e,setAttributes:t}){const l=(0,i.useBlockProps)(),{shortcodeId:a,template:r,fields:p}=e,u=[{label:(0,o.__)("Default template","acadlix"),value:""},{label:(0,o.__)("Template 1","acadlix"),value:"template-1"},{label:(0,o.__)("Template 2","acadlix"),value:"template-2"}],x=[{label:(0,o.__)("Category","acadlix"),value:"category"},{label:(0,o.__)("Time","acadlix"),value:"time"},{label:(0,o.__)("Questions","acadlix"),value:"questions"},{label:(0,o.__)("Points","acadlix"),value:"points"},{label:(0,o.__)("Attempts","acadlix"),value:"attempts"},{label:(0,o.__)("Start Date","acadlix"),value:"start_date"},{label:(0,o.__)("End Date","acadlix"),value:"end_date"},{label:(0,o.__)("Description","acadlix"),value:"description"}],_=p?p.split(",").map(e=>e.trim()).filter(Boolean):[],[h,b]=(0,n.useState)([]),[m,w]=(0,n.useState)(!0),[f,v]=(0,n.useState)("");(0,n.useEffect)(()=>{let e=!0;return d()({path:"/acadlix/v1/block-quiz-shortcodes"}).then(t=>{if(!e)return;const l=Array.isArray(t?.items)?t.items:[],a=[{label:(0,o.__)("Select a quiz","acadlix"),value:"0"},...l.map(e=>({label:e?.label||(0,o.__)("Untitled Quiz","acadlix"),value:String(e?.value||0)}))];b(a)}).catch(t=>{e&&v(t?.message||(0,o.__)("Unable to load quiz list from server.","acadlix"))}).finally(()=>{e&&w(!1)}),()=>{e=!1}},[]);const g=["[Acadlix_Quiz"];a>0&&g.push(String(a)),r&&g.push(`template="${r}"`),p&&g.push(`fields="${p}"`);const j=e=>{const l=parseInt(e,10);t({shortcodeId:Number.isNaN(l)?0:Math.max(0,l)})},S=e=>{t({template:e,fields:e?p:""})},k=()=>(0,c.jsxs)(s.PanelBody,{title:(0,o.__)("Quiz Settings","acadlix"),initialOpen:!0,children:[m?(0,c.jsx)(s.Spinner,{}):null,(0,c.jsx)(s.ComboboxControl,{label:(0,o.__)("Quiz","acadlix"),value:String(a||0),options:h,onChange:j,help:(0,o.__)("Select a quiz shortcode from server list.","acadlix"),disabled:m||!!f}),f?(0,c.jsx)(s.Notice,{status:"error",isDismissible:!1,children:f}):null,(0,c.jsx)(s.SelectControl,{label:(0,o.__)("Template (optional)","acadlix"),value:r||"",options:u,onChange:S,help:(0,o.__)("Choose a template for quiz rendering.","acadlix")}),(0,c.jsx)(s.BaseControl,{label:(0,o.__)("Fields (optional)","acadlix"),help:r?(0,o.__)("Select one or more fields.","acadlix"):(0,o.__)("Select a template first to enable field options.","acadlix"),children:(0,c.jsx)("div",{style:{display:"grid",gap:"10px"},children:x.map(e=>(0,c.jsx)(s.CheckboxControl,{label:e.label,checked:_.includes(e.value),disabled:!r,onChange:l=>{((e,l)=>{const a=l?[..._,e]:_.filter(t=>t!==e);t({fields:a.join(",")})})(e.value,l)}},e.value))})})]});return(0,c.jsxs)("div",{...l,children:[(0,c.jsx)(i.InspectorControls,{children:k()}),k(),a>0?(0,c.jsxs)(s.Notice,{status:"info",isDismissible:!1,children:[(0,o.__)("Shortcode to render:","acadlix")," ",`${g.join(" ")}]`]}):(0,c.jsx)(s.Notice,{status:"warning",isDismissible:!1,children:(0,o.__)("Set a valid Shortcode ID to render the quiz.","acadlix")})]})},save:function({attributes:e}){const{shortcodeId:t,template:l,fields:a}=e;if(!t||0===t)return null;const i=["[Acadlix_Quiz"];i.push(String(t)),l&&i.push(`template="${l}"`),a&&i.push(`fields="${a}"`),i.push("]");const s=i.join(" ");return(0,c.jsx)(n.RawHTML,{children:s})}})},"@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-shortcode/index.js")}]);