(()=>{"use strict";var e={n:l=>{var t=l&&l.__esModule?()=>l.default:()=>l;return e.d(t,{a:t}),t},d:(l,t)=>{for(var s in t)e.o(t,s)&&!e.o(l,s)&&Object.defineProperty(l,s,{enumerable:!0,get:t[s]})},o:(e,l)=>Object.prototype.hasOwnProperty.call(e,l)};const l=window.wp.element,t=window.wp.blocks,s=window.wp.components,r=window.wp.blockEditor,n=window.wp.i18n,o=window.wp.serverSideRender;var a=e.n(o);const i=window.wp.apiFetch;var c=e.n(i);const u=window.wp.data,d=["course","lesson","llms_quiz"],m=function(e){let l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"name";const t=null==e?void 0:e.replace("llms_",""),s=t.charAt(0).toUpperCase()+t.slice(1);return"name"===l?t:s},p=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":2,"name":"llms/courses","title":"Courses","category":"llms-blocks","description":"Displays a loop of LifterLMS Course \\"Tiles\\" as displayed on the default \\"Courses\\" page.","textdomain":"lifterlms","attributes":{"category":{"type":"string"},"hidden":{"type":"boolean","default":true},"id":{"type":"string"},"mine":{"type":"string"},"order":{"type":"string","default":"ASC"},"orderby":{"type":"string","default":"title"},"posts_per_page":{"type":"integer","default":-1},"llms_visibility":{"type":"string"},"llms_visibility_in":{"type":"string"},"llms_visibility_posts":{"type":"string"}},"supports":{"align":["wide","full"]},"editorScript":"file:./index.js"}'),_=window.wp.primitives;(0,t.registerBlockType)(p,{icon:()=>(0,l.createElement)(_.SVG,{className:"llms-block-icon",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 640 512"},(0,l.createElement)(_.Path,{d:"M320 32c-8.1 0-16.1 1.4-23.7 4.1L15.8 137.4C6.3 140.9 0 149.9 0 160s6.3 19.1 15.8 22.6l57.9 20.9C57.3 229.3 48 259.8 48 291.9v28.1c0 28.4-10.8 57.7-22.3 80.8c-6.5 13-13.9 25.8-22.5 37.6C0 442.7-.9 448.3 .9 453.4s6 8.9 11.2 10.2l64 16c4.2 1.1 8.7 .3 12.4-2s6.3-6.1 7.1-10.4c8.6-42.8 4.3-81.2-2.1-108.7C90.3 344.3 86 329.8 80 316.5V291.9c0-30.2 10.2-58.7 27.9-81.5c12.9-15.5 29.6-28 49.2-35.7l157-61.7c8.2-3.2 17.5 .8 20.7 9s-.8 17.5-9 20.7l-157 61.7c-12.4 4.9-23.3 12.4-32.2 21.6l159.6 57.6c7.6 2.7 15.6 4.1 23.7 4.1s16.1-1.4 23.7-4.1L624.2 182.6c9.5-3.4 15.8-12.5 15.8-22.6s-6.3-19.1-15.8-22.6L343.7 36.1C336.1 33.4 328.1 32 320 32zM128 408c0 35.3 86 72 192 72s192-36.7 192-72L496.7 262.6 354.5 314c-11.1 4-22.8 6-34.5 6s-23.5-2-34.5-6L143.3 262.6 128 408z"})),edit:e=>{const{attributes:t,setAttributes:o}=e,i=(0,r.useBlockProps)(),[_,h]=(0,l.useState)([]),[f,b]=(0,l.useState)([]),[g,v]=(0,l.useState)(!1),[y,w]=(0,l.useState)("");(0,l.useEffect)((()=>{const e=setTimeout((()=>function(e){let l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";v(!0);const t=e?`&search=${encodeURIComponent(e)}`:"";c()({path:`/wp/v2/course_cat?per_page=10${t}`}).then((e=>{const t=e.map((e=>({value:e.slug,label:e.name})));t.unshift({value:"",label:(0,n.__)("- All -","lifterlms")}),l&&!t.some((e=>e.value===l))?c()({path:`/wp/v2/course_cat?slug=${encodeURIComponent(l)}`}).then((e=>{e&&e.length>0?b([...t,...e.map((e=>({value:e.slug,label:e.name})))]):b(t)})).catch((()=>{b(t)})):b(t)})).catch((()=>{b([{value:"",label:(0,n.__)("- All -","lifterlms")}])})).finally((()=>{v(!1)}))}(y,null==t?void 0:t.category)),300);return()=>clearTimeout(e)}),[y,null==t?void 0:t.category]);const C=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"course";const{posts:l,currentPostType:t}=(0,u.useSelect)((l=>{var t;return{posts:l("core").getEntityRecords("postType",e),currentPostType:null===(t=l("core/editor"))||void 0===t?void 0:t.getCurrentPostType()}}),[]),s=(m(e),[]);return d.includes(t)||s.push({label:(0,n.__)("Select course","lifterlms"),value:0}),null!=l&&l.length&&l.forEach((e=>{s.push({label:e.title.rendered+" (ID: "+e.id+")",value:e.id})})),d.includes(t)&&s.unshift({label:(0,n.sprintf)(
// Translators: %s = Post type name.
(0,n.__)("Inherit from current %s","lifterlms"),m(t)),value:0}),null!=s&&s.length||s.push({label:(0,n.__)("Loading","lifterlms"),value:0}),s}(),E={};null==C||C.forEach((e=>{let{value:l,label:t}=e;E[l]=t}));const S=(0,l.useMemo)((()=>(0,l.createElement)(a(),{block:p.name,attributes:t,LoadingResponsePlaceholder:()=>(0,l.createElement)(s.Spinner,null),ErrorResponsePlaceholder:()=>(0,l.createElement)("p",{className:"llms-block-error"},(0,n.__)("Error loading content. Please check block settings are valid. This block will not be displayed.","lifterlms")),EmptyResponsePlaceholder:()=>(0,l.createElement)("p",{className:"llms-block-empty"},(0,n.__)("No courses found matching your selection. This block will not be displayed.","lifterlms"))})),[t]);return(0,l.createElement)(l.Fragment,null,(0,l.createElement)(r.InspectorControls,null,(0,l.createElement)(s.PanelBody,{title:(0,n.__)("Courses Settings","lifterlms")},(0,l.createElement)(s.PanelRow,null,(0,l.createElement)(s.ComboboxControl,{label:(0,n.__)("Category","lifterlms"),help:(0,n.__)("Display courses from a specific Course Category only.","lifterlms"),value:(null==t?void 0:t.category)||"",options:f,onChange:e=>o({category:e}),onFilterValueChange:w,isLoading:g,allowReset:!0})),(0,l.createElement)(s.PanelRow,null,(0,l.createElement)(s.ToggleControl,{label:(0,n.__)("Show hidden courses?","lifterlms"),checked:t.hidden,onChange:e=>o({hidden:e}),help:(0,n.__)('Whether or not courses with a "hidden" visibility should be included. Defaults to "yes" (hidden courses displayed). Switch to "no" to exclude hidden courses.',"lifterlms")})),(0,l.createElement)(s.PanelRow,null,(0,l.createElement)(s.BaseControl,{help:(0,n.__)("Display only specific course(s). You can select multiple courses.","lifterlms")},(0,l.createElement)(s.FormTokenField,{label:(0,n.__)("Courses","lifterlms"),placeholder:(0,n.__)("Search available courses","lifterlms"),suggestions:Object.values(E),value:_,onChange:e=>{h(e),o({id:e.map((e=>Object.keys(E).find((l=>E[l]===e)))).join(",")})},__experimentalShowHowTo:!1}))),(0,l.createElement)(s.PanelRow,null,(0,l.createElement)(s.SelectControl,{label:(0,n.__)("Show only my courses","lifterlms"),options:[{value:"no",label:(0,n.__)("No","lifterlms")},{value:"any",label:(0,n.__)("Any","lifterlms")},{value:"enrolled",label:(0,n.__)("Enrolled","lifterlms")},{value:"expired",label:(0,n.__)("Expired","lifterlms")},{value:"cancelled",label:(0,n.__)("Cancelled","lifterlms")}],checked:t.mine,onChange:e=>o({mine:e}),help:(0,n.__)('Show only courses the current student is enrolled in. By default ("no") shows courses regardless of enrollment.',"lifterlms")})),(0,l.createElement)(s.PanelRow,null,(0,l.createElement)(s.SelectControl,{label:(0,n.__)("Order","lifterlms"),value:t.order,options:[{value:"ASC",label:(0,n.__)("Ascending","lifterlms")},{value:"DESC",label:(0,n.__)("Descending","lifterlms")}],onChange:e=>o({order:e}),help:(0,n.__)("Display courses in ascending or descending order.","lifterlms")})),(0,l.createElement)(s.PanelRow,null,(0,l.createElement)(s.SelectControl,{label:(0,n.__)("Order by","lifterlms"),value:t.orderby,options:[{value:"id",label:(0,n.__)("ID","lifterlms")},{value:"author",label:(0,n.__)("Author","lifterlms")},{value:"title",label:(0,n.__)("Title","lifterlms")},{value:"name",label:(0,n.__)("Name","lifterlms")},{value:"date",label:(0,n.__)("Date","lifterlms")},{value:"modified",label:(0,n.__)("Date modified","lifterlms")},{value:"rand",label:(0,n.__)("Random","lifterlms")},{value:"menu_order",label:(0,n.__)("Menu Order","lifterlms")}],onChange:e=>o({orderby:e}),help:(0,n.__)("Determines which field is used to order courses in the courses list.","lifterlms")})),(0,l.createElement)(s.PanelRow,null,(0,l.createElement)(s.__experimentalNumberControl,{label:(0,n.__)("Per Page","lifterlms"),value:t.posts_per_page,min:-1,max:100,onChange:e=>o({posts_per_page:null!=e?e:-1}),help:(0,n.__)(" Determines the number of results to display. Default returns all available courses.","lifterlms")})))),(0,l.createElement)("div",i,(0,l.createElement)(s.Disabled,null,S)))}})})();