"use strict";(globalThis.webpackChunkacadlix=globalThis.webpackChunkacadlix||[]).push([["login_shortcode_block"],{"./src/blocks/login-shortcode/index.js":(e,r,t)=>{var i=t("@wordpress/blocks"),s=t("@wordpress/block-editor"),o=t("@wordpress/components"),a=t("@wordpress/i18n"),l=t("@wordpress/api-fetch"),c=t.n(l),n=t("@wordpress/element"),d=t("react/jsx-runtime");(0,i.registerBlockType)("acadlix/login-shortcode",{apiVersion:3,title:(0,a.__)("Acadlix Login","acadlix"),icon:"editor-code",category:"text",attributes:{redirectUrl:{type:"string",default:""},redirectId:{type:"number",default:0}},edit:function({attributes:e,setAttributes:r}){const t=(0,s.useBlockProps)(),{redirectUrl:i,redirectId:l}=e,[p,u]=(0,n.useState)([]),[x,h]=(0,n.useState)(!0),[w,b]=(0,n.useState)("");(0,n.useEffect)(()=>{let e=!0;return c()({path:"/acadlix/v1/block-login-shortcodes"}).then(r=>{if(!e)return;const t=Array.isArray(r?.pages)?r.pages:[],i=[{label:(0,a.__)("None","acadlix"),value:"0"},...t?.map(e=>({label:e?.label||(0,a.__)("Untitled Page","acadlix"),value:String(e?.id||0)}))||[]];u(i)}).catch(r=>{e&&b(r?.message||(0,a.__)("Unable to load redirect list from server.","acadlix"))}).finally(()=>{e&&h(!1)}),()=>{e=!1}},[]);const _=["[acadlix_login"];i&&_.push(`redirect_url="${i}"`),l&&_.push(`redirect_page_id="${l}"`);const g=e=>{r({redirectUrl:e||""})},m=e=>{const t=parseInt(e,10);r({redirectId:Number.isNaN(t)?0:Math.max(0,t)})},f=()=>(0,d.jsxs)(o.PanelBody,{title:(0,a.__)("Redirect Settings","acadlix"),initialOpen:!0,children:[(0,d.jsx)(o.TextControl,{label:(0,a.__)("Redirect URL (optional)","acadlix"),value:i||"",onChange:g,help:(0,a.__)("Enter a full URL for redirect after login.","acadlix")}),x?(0,d.jsx)(o.Spinner,{}):null,(0,d.jsx)(o.ComboboxControl,{label:(0,a.__)("Redirect Page ID (optional)","acadlix"),value:String(l||0),options:p,onChange:m,help:(0,a.__)("Choose a page ID from the available list.","acadlix"),disabled:x||!!w}),(0,d.jsx)(o.Notice,{status:"info",isDismissible:!1,children:(0,a.__)("If both Redirect URL and Redirect Page ID are set, Redirect Page ID takes priority.","acadlix")}),w?(0,d.jsx)(o.Notice,{status:"error",isDismissible:!1,children:w}):null]});return(0,d.jsxs)("div",{...t,children:[(0,d.jsx)(s.InspectorControls,{children:f()}),f(),(0,d.jsxs)(o.Notice,{status:"info",isDismissible:!1,children:[(0,a.__)("Shortcode to render:","acadlix")," ",`${_.join(" ")}]`]})]})},save:function({attributes:e}){const{redirectUrl:r,redirectId:t}=e,i=["[acadlix_login"];r&&i.push(`redirect_url="${r}"`),t&&i.push(`redirect_page_id="${t}"`),i.push("]");const s=i.join(" ");return(0,d.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/login-shortcode/index.js")}]);