@project-sunbird/collection-editor-react 0.1.20 → 0.1.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -463,4 +463,4 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
463
463
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function n0(e,t){if(e){if(typeof e=="string")return hf(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if(r==="Object"&&e.constructor&&(r=e.constructor.name),r==="Map"||r==="Set")return Array.from(e);if(r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return hf(e,t)}}function hf(e,t){(t==null||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function s0(e,t){var r=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(r!=null){var n=[],s=!0,i=!1,o,a;try{for(r=r.call(e);!(s=(o=r.next()).done)&&(n.push(o.value),!(t&&n.length===t));s=!0);}catch(c){i=!0,a=c}finally{try{!s&&r.return!=null&&r.return()}finally{if(i)throw a}}return n}}function i0(e){if(Array.isArray(e))return e}function o0(e,t,r){var n=Gr(),s=e0(e,t),i=YC(e);Kr(function(){var a=fC(i,s,n),c=t0(a,2),d=c[0],u=c[1];return t.receiveHandlerId(d),r.receiveHandlerId(d),u},[n,t,s,r,i.map(function(o){return o.toString()}).join("|")])}function a0(){var e=Gr();return h.useMemo(function(){return new eC(e)},[e])}function l0(e){var t=Gr(),r=h.useMemo(function(){return new dC(t.getBackend())},[t]);return Kr(function(){return r.dropTargetOptions=e||null,r.reconnect(),function(){return r.disconnectDropTarget()}},[e]),r}function c0(e){return h.useMemo(function(){return e.hooks.dropTarget()},[e])}function pf(e,t){var r=af(e,t),n=a0(),s=l0(r.options);return o0(r,n,s),[df(r.collect,n,s),c0(s)]}function u0(e,t){return p0(e)||h0(e,t)||f0(e,t)||d0()}function d0(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
464
464
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function f0(e,t){if(e){if(typeof e=="string")return gf(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if(r==="Object"&&e.constructor&&(r=e.constructor.name),r==="Map"||r==="Set")return Array.from(e);if(r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return gf(e,t)}}function gf(e,t){(t==null||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function h0(e,t){var r=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(r!=null){var n=[],s=!0,i=!1,o,a;try{for(r=r.call(e);!(s=(o=r.next()).done)&&(n.push(o.value),!(t&&n.length===t));s=!0);}catch(c){i=!0,a=c}finally{try{!s&&r.return!=null&&r.return()}finally{if(i)throw a}}return n}}function p0(e){if(Array.isArray(e))return e}function g0(e){var t=Gr(),r=t.getMonitor(),n=cf(r,e),s=u0(n,2),i=s[0],o=s[1];return h.useEffect(function(){return r.subscribeToOffsetChange(o)}),h.useEffect(function(){return r.subscribeToStateChange(o)}),i}function yf(e){var t=null,r=function(){return t==null&&(t=e()),t};return r}function y0(e,t){return e.filter(function(r){return r!==t})}function v0(e,t){var r=new Set,n=function(o){return r.add(o)};e.forEach(n),t.forEach(n);var s=[];return r.forEach(function(i){return s.push(i)}),s}function m0(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function b0(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function _0(e,t,r){return t&&b0(e.prototype,t),e}function vf(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var w0=function(){function e(t){m0(this,e),vf(this,"entered",[]),vf(this,"isNodeInDocument",void 0),this.isNodeInDocument=t}return _0(e,[{key:"enter",value:function(r){var n=this,s=this.entered.length,i=function(a){return n.isNodeInDocument(a)&&(!a.contains||a.contains(r))};return this.entered=v0(this.entered.filter(i),[r]),s===0&&this.entered.length>0}},{key:"leave",value:function(r){var n=this.entered.length;return this.entered=y0(this.entered.filter(this.isNodeInDocument),r),n>0&&this.entered.length===0}},{key:"reset",value:function(){this.entered=[]}}]),e}(),S0=yf(function(){return/firefox/i.test(navigator.userAgent)}),mf=yf(function(){return!!window.safari});function C0(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function E0(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function O0(e,t,r){return t&&E0(e.prototype,t),e}function Os(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var bf=function(){function e(t,r){C0(this,e),Os(this,"xs",void 0),Os(this,"ys",void 0),Os(this,"c1s",void 0),Os(this,"c2s",void 0),Os(this,"c3s",void 0);for(var n=t.length,s=[],i=0;i<n;i++)s.push(i);s.sort(function(P,F){return t[P]<t[F]?-1:1});for(var o=[],a=[],c,d,u=0;u<n-1;u++)c=t[u+1]-t[u],d=r[u+1]-r[u],o.push(c),a.push(d/c);for(var f=[a[0]],g=0;g<o.length-1;g++){var y=a[g],_=a[g+1];if(y*_<=0)f.push(0);else{c=o[g];var p=o[g+1],v=c+p;f.push(3*v/((v+p)/y+(v+c)/_))}}f.push(a[a.length-1]);for(var m=[],b=[],S,w=0;w<f.length-1;w++){S=a[w];var E=f[w],T=1/o[w],x=E+f[w+1]-S-S;m.push((S-E-x)*T),b.push(x*T*T)}this.xs=t,this.ys=r,this.c1s=f,this.c2s=m,this.c3s=b}return O0(e,[{key:"interpolate",value:function(r){var n=this.xs,s=this.ys,i=this.c1s,o=this.c2s,a=this.c3s,c=n.length-1;if(r===n[c])return s[c];for(var d=0,u=a.length-1,f;d<=u;){f=Math.floor(.5*(d+u));var g=n[f];if(g<r)d=f+1;else if(g>r)u=f-1;else return s[f]}c=Math.max(0,u);var y=r-n[c],_=y*y;return s[c]+i[c]*y+o[c]*_+a[c]*y*_}}]),e}(),I0=1;function _f(e){var t=e.nodeType===I0?e:e.parentElement;if(!t)return null;var r=t.getBoundingClientRect(),n=r.top,s=r.left;return{x:s,y:n}}function Wi(e){return{x:e.clientX,y:e.clientY}}function D0(e){var t;return e.nodeName==="IMG"&&(S0()||!((t=document.documentElement)!==null&&t!==void 0&&t.contains(e)))}function T0(e,t,r,n){var s=e?t.width:r,i=e?t.height:n;return mf()&&e&&(i/=window.devicePixelRatio,s/=window.devicePixelRatio),{dragPreviewWidth:s,dragPreviewHeight:i}}function N0(e,t,r,n,s){var i=D0(t),o=i?e:t,a=_f(o),c={x:r.x-a.x,y:r.y-a.y},d=e.offsetWidth,u=e.offsetHeight,f=n.anchorX,g=n.anchorY,y=T0(i,t,d,u),_=y.dragPreviewWidth,p=y.dragPreviewHeight,v=function(){var x=new bf([0,.5,1],[c.y,c.y/u*p,c.y+p-u]),P=x.interpolate(g);return mf()&&i&&(P+=(window.devicePixelRatio-1)*p),P},m=function(){var x=new bf([0,.5,1],[c.x,c.x/d*_,c.x+_-d]);return x.interpolate(f)},b=s.offsetX,S=s.offsetY,w=b===0||b,E=S===0||S;return{x:w?b:m(),y:E?S:v()}}var wf="__NATIVE_FILE__",Sf="__NATIVE_URL__",Cf="__NATIVE_TEXT__",Ef="__NATIVE_HTML__";const Of=Object.freeze(Object.defineProperty({__proto__:null,FILE:wf,HTML:Ef,TEXT:Cf,URL:Sf},Symbol.toStringTag,{value:"Module"}));function qa(e,t,r){var n=t.reduce(function(s,i){return s||e.getData(i)},"");return n??r}var An;function Qi(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var Ha=(An={},Qi(An,wf,{exposeProperties:{files:function(t){return Array.prototype.slice.call(t.files)},items:function(t){return t.items},dataTransfer:function(t){return t}},matchesTypes:["Files"]}),Qi(An,Ef,{exposeProperties:{html:function(t,r){return qa(t,r,"")},dataTransfer:function(t){return t}},matchesTypes:["Html","text/html"]}),Qi(An,Sf,{exposeProperties:{urls:function(t,r){return qa(t,r,"").split(`
465
465
  `)},dataTransfer:function(t){return t}},matchesTypes:["Url","text/uri-list"]}),Qi(An,Cf,{exposeProperties:{text:function(t,r){return qa(t,r,"")},dataTransfer:function(t){return t}},matchesTypes:["Text","text/plain"]}),An);function k0(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function x0(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function A0(e,t,r){return t&&x0(e.prototype,t),e}function If(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var P0=function(){function e(t){k0(this,e),If(this,"item",void 0),If(this,"config",void 0),this.config=t,this.item={},this.initializeExposedProperties()}return A0(e,[{key:"initializeExposedProperties",value:function(){var r=this;Object.keys(this.config.exposeProperties).forEach(function(n){Object.defineProperty(r.item,n,{configurable:!0,enumerable:!0,get:function(){return console.warn(`Browser doesn't allow reading "`.concat(n,'" until the drop event.')),null}})})}},{key:"loadDataTransfer",value:function(r){var n=this;if(r){var s={};Object.keys(this.config.exposeProperties).forEach(function(i){s[i]={value:n.config.exposeProperties[i](r,n.config.matchesTypes),configurable:!0,enumerable:!0}}),Object.defineProperties(this.item,s)}}},{key:"canDrag",value:function(){return!0}},{key:"beginDrag",value:function(){return this.item}},{key:"isDragging",value:function(r,n){return n===r.getSourceId()}},{key:"endDrag",value:function(){}}]),e}();function M0(e,t){var r=new P0(Ha[e]);return r.loadDataTransfer(t),r}function Wa(e){if(!e)return null;var t=Array.prototype.slice.call(e.types||[]);return Object.keys(Ha).filter(function(r){var n=Ha[r].matchesTypes;return n.some(function(s){return t.indexOf(s)>-1})})[0]||null}function L0(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function F0(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function $0(e,t,r){return t&&F0(e.prototype,t),e}function Qa(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var j0=function(){function e(t,r){L0(this,e),Qa(this,"ownerDocument",null),Qa(this,"globalContext",void 0),Qa(this,"optionsArgs",void 0),this.globalContext=t,this.optionsArgs=r}return $0(e,[{key:"window",get:function(){if(this.globalContext)return this.globalContext;if(typeof window<"u")return window}},{key:"document",get:function(){var r;return(r=this.globalContext)!==null&&r!==void 0&&r.document?this.globalContext.document:this.window?this.window.document:void 0}},{key:"rootElement",get:function(){var r;return((r=this.optionsArgs)===null||r===void 0?void 0:r.rootElement)||this.window}}]),e}();function Df(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),r.push.apply(r,n)}return r}function Tf(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?Df(Object(r),!0).forEach(function(n){_e(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):Df(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}function B0(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function U0(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function z0(e,t,r){return t&&U0(e.prototype,t),e}function _e(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var V0=function(){function e(t,r,n){var s=this;B0(this,e),_e(this,"options",void 0),_e(this,"actions",void 0),_e(this,"monitor",void 0),_e(this,"registry",void 0),_e(this,"enterLeaveCounter",void 0),_e(this,"sourcePreviewNodes",new Map),_e(this,"sourcePreviewNodeOptions",new Map),_e(this,"sourceNodes",new Map),_e(this,"sourceNodeOptions",new Map),_e(this,"dragStartSourceIds",null),_e(this,"dropTargetIds",[]),_e(this,"dragEnterTargetIds",[]),_e(this,"currentNativeSource",null),_e(this,"currentNativeHandle",null),_e(this,"currentDragSourceNode",null),_e(this,"altKeyPressed",!1),_e(this,"mouseMoveTimeoutTimer",null),_e(this,"asyncEndDragFrameId",null),_e(this,"dragOverTargetIds",null),_e(this,"lastClientOffset",null),_e(this,"hoverRafId",null),_e(this,"getSourceClientOffset",function(i){var o=s.sourceNodes.get(i);return o&&_f(o)||null}),_e(this,"endDragNativeItem",function(){s.isDraggingNativeItem()&&(s.actions.endDrag(),s.currentNativeHandle&&s.registry.removeSource(s.currentNativeHandle),s.currentNativeHandle=null,s.currentNativeSource=null)}),_e(this,"isNodeInDocument",function(i){return!!(i&&s.document&&s.document.body&&s.document.body.contains(i))}),_e(this,"endDragIfSourceWasRemovedFromDOM",function(){var i=s.currentDragSourceNode;i==null||s.isNodeInDocument(i)||s.clearCurrentDragSourceNode()&&s.monitor.isDragging()&&s.actions.endDrag()}),_e(this,"handleTopDragStartCapture",function(){s.clearCurrentDragSourceNode(),s.dragStartSourceIds=[]}),_e(this,"handleTopDragStart",function(i){if(!i.defaultPrevented){var o=s.dragStartSourceIds;s.dragStartSourceIds=null;var a=Wi(i);s.monitor.isDragging()&&s.actions.endDrag(),s.actions.beginDrag(o||[],{publishSource:!1,getSourceClientOffset:s.getSourceClientOffset,clientOffset:a});var c=i.dataTransfer,d=Wa(c);if(s.monitor.isDragging()){if(c&&typeof c.setDragImage=="function"){var u=s.monitor.getSourceId(),f=s.sourceNodes.get(u),g=s.sourcePreviewNodes.get(u)||f;if(g){var y=s.getCurrentSourcePreviewNodeOptions(),_=y.anchorX,p=y.anchorY,v=y.offsetX,m=y.offsetY,b={anchorX:_,anchorY:p},S={offsetX:v,offsetY:m},w=N0(f,g,a,b,S);c.setDragImage(g,w.x,w.y)}}try{c==null||c.setData("application/json",{})}catch{}s.setCurrentDragSourceNode(i.target);var E=s.getCurrentSourcePreviewNodeOptions(),T=E.captureDraggingState;T?s.actions.publishDragSource():setTimeout(function(){return s.actions.publishDragSource()},0)}else if(d)s.beginDragNativeItem(d);else{if(c&&!c.types&&(i.target&&!i.target.hasAttribute||!i.target.hasAttribute("draggable")))return;i.preventDefault()}}}),_e(this,"handleTopDragEndCapture",function(){s.clearCurrentDragSourceNode()&&s.monitor.isDragging()&&s.actions.endDrag()}),_e(this,"handleTopDragEnterCapture",function(i){s.dragEnterTargetIds=[];var o=s.enterLeaveCounter.enter(i.target);if(!(!o||s.monitor.isDragging())){var a=i.dataTransfer,c=Wa(a);c&&s.beginDragNativeItem(c,a)}}),_e(this,"handleTopDragEnter",function(i){var o=s.dragEnterTargetIds;if(s.dragEnterTargetIds=[],!!s.monitor.isDragging()){s.altKeyPressed=i.altKey,o.length>0&&s.actions.hover(o,{clientOffset:Wi(i)});var a=o.some(function(c){return s.monitor.canDropOnTarget(c)});a&&(i.preventDefault(),i.dataTransfer&&(i.dataTransfer.dropEffect=s.getCurrentDropEffect()))}}),_e(this,"handleTopDragOverCapture",function(){s.dragOverTargetIds=[]}),_e(this,"handleTopDragOver",function(i){var o=s.dragOverTargetIds;if(s.dragOverTargetIds=[],!s.monitor.isDragging()){i.preventDefault(),i.dataTransfer&&(i.dataTransfer.dropEffect="none");return}s.altKeyPressed=i.altKey,s.lastClientOffset=Wi(i),s.hoverRafId===null&&typeof requestAnimationFrame<"u"&&(s.hoverRafId=requestAnimationFrame(function(){s.monitor.isDragging()&&s.actions.hover(o||[],{clientOffset:s.lastClientOffset}),s.hoverRafId=null}));var a=(o||[]).some(function(c){return s.monitor.canDropOnTarget(c)});a?(i.preventDefault(),i.dataTransfer&&(i.dataTransfer.dropEffect=s.getCurrentDropEffect())):s.isDraggingNativeItem()?i.preventDefault():(i.preventDefault(),i.dataTransfer&&(i.dataTransfer.dropEffect="none"))}),_e(this,"handleTopDragLeaveCapture",function(i){s.isDraggingNativeItem()&&i.preventDefault();var o=s.enterLeaveCounter.leave(i.target);o&&s.isDraggingNativeItem()&&setTimeout(function(){return s.endDragNativeItem()},0)}),_e(this,"handleTopDropCapture",function(i){if(s.dropTargetIds=[],s.isDraggingNativeItem()){var o;i.preventDefault(),(o=s.currentNativeSource)===null||o===void 0||o.loadDataTransfer(i.dataTransfer)}else Wa(i.dataTransfer)&&i.preventDefault();s.enterLeaveCounter.reset()}),_e(this,"handleTopDrop",function(i){var o=s.dropTargetIds;s.dropTargetIds=[],s.actions.hover(o,{clientOffset:Wi(i)}),s.actions.drop({dropEffect:s.getCurrentDropEffect()}),s.isDraggingNativeItem()?s.endDragNativeItem():s.monitor.isDragging()&&s.actions.endDrag()}),_e(this,"handleSelectStart",function(i){var o=i.target;typeof o.dragDrop=="function"&&(o.tagName==="INPUT"||o.tagName==="SELECT"||o.tagName==="TEXTAREA"||o.isContentEditable||(i.preventDefault(),o.dragDrop()))}),this.options=new j0(r,n),this.actions=t.getActions(),this.monitor=t.getMonitor(),this.registry=t.getRegistry(),this.enterLeaveCounter=new w0(this.isNodeInDocument)}return z0(e,[{key:"profile",value:function(){var r,n;return{sourcePreviewNodes:this.sourcePreviewNodes.size,sourcePreviewNodeOptions:this.sourcePreviewNodeOptions.size,sourceNodeOptions:this.sourceNodeOptions.size,sourceNodes:this.sourceNodes.size,dragStartSourceIds:((r=this.dragStartSourceIds)===null||r===void 0?void 0:r.length)||0,dropTargetIds:this.dropTargetIds.length,dragEnterTargetIds:this.dragEnterTargetIds.length,dragOverTargetIds:((n=this.dragOverTargetIds)===null||n===void 0?void 0:n.length)||0}}},{key:"window",get:function(){return this.options.window}},{key:"document",get:function(){return this.options.document}},{key:"rootElement",get:function(){return this.options.rootElement}},{key:"setup",value:function(){var r=this.rootElement;if(r!==void 0){if(r.__isReactDndBackendSetUp)throw new Error("Cannot have two HTML5 backends at the same time.");r.__isReactDndBackendSetUp=!0,this.addEventListeners(r)}}},{key:"teardown",value:function(){var r=this.rootElement;if(r!==void 0&&(r.__isReactDndBackendSetUp=!1,this.removeEventListeners(this.rootElement),this.clearCurrentDragSourceNode(),this.asyncEndDragFrameId)){var n;(n=this.window)===null||n===void 0||n.cancelAnimationFrame(this.asyncEndDragFrameId)}}},{key:"connectDragPreview",value:function(r,n,s){var i=this;return this.sourcePreviewNodeOptions.set(r,s),this.sourcePreviewNodes.set(r,n),function(){i.sourcePreviewNodes.delete(r),i.sourcePreviewNodeOptions.delete(r)}}},{key:"connectDragSource",value:function(r,n,s){var i=this;this.sourceNodes.set(r,n),this.sourceNodeOptions.set(r,s);var o=function(d){return i.handleDragStart(d,r)},a=function(d){return i.handleSelectStart(d)};return n.setAttribute("draggable","true"),n.addEventListener("dragstart",o),n.addEventListener("selectstart",a),function(){i.sourceNodes.delete(r),i.sourceNodeOptions.delete(r),n.removeEventListener("dragstart",o),n.removeEventListener("selectstart",a),n.setAttribute("draggable","false")}}},{key:"connectDropTarget",value:function(r,n){var s=this,i=function(d){return s.handleDragEnter(d,r)},o=function(d){return s.handleDragOver(d,r)},a=function(d){return s.handleDrop(d,r)};return n.addEventListener("dragenter",i),n.addEventListener("dragover",o),n.addEventListener("drop",a),function(){n.removeEventListener("dragenter",i),n.removeEventListener("dragover",o),n.removeEventListener("drop",a)}}},{key:"addEventListeners",value:function(r){r.addEventListener&&(r.addEventListener("dragstart",this.handleTopDragStart),r.addEventListener("dragstart",this.handleTopDragStartCapture,!0),r.addEventListener("dragend",this.handleTopDragEndCapture,!0),r.addEventListener("dragenter",this.handleTopDragEnter),r.addEventListener("dragenter",this.handleTopDragEnterCapture,!0),r.addEventListener("dragleave",this.handleTopDragLeaveCapture,!0),r.addEventListener("dragover",this.handleTopDragOver),r.addEventListener("dragover",this.handleTopDragOverCapture,!0),r.addEventListener("drop",this.handleTopDrop),r.addEventListener("drop",this.handleTopDropCapture,!0))}},{key:"removeEventListeners",value:function(r){r.removeEventListener&&(r.removeEventListener("dragstart",this.handleTopDragStart),r.removeEventListener("dragstart",this.handleTopDragStartCapture,!0),r.removeEventListener("dragend",this.handleTopDragEndCapture,!0),r.removeEventListener("dragenter",this.handleTopDragEnter),r.removeEventListener("dragenter",this.handleTopDragEnterCapture,!0),r.removeEventListener("dragleave",this.handleTopDragLeaveCapture,!0),r.removeEventListener("dragover",this.handleTopDragOver),r.removeEventListener("dragover",this.handleTopDragOverCapture,!0),r.removeEventListener("drop",this.handleTopDrop),r.removeEventListener("drop",this.handleTopDropCapture,!0))}},{key:"getCurrentSourceNodeOptions",value:function(){var r=this.monitor.getSourceId(),n=this.sourceNodeOptions.get(r);return Tf({dropEffect:this.altKeyPressed?"copy":"move"},n||{})}},{key:"getCurrentDropEffect",value:function(){return this.isDraggingNativeItem()?"copy":this.getCurrentSourceNodeOptions().dropEffect}},{key:"getCurrentSourcePreviewNodeOptions",value:function(){var r=this.monitor.getSourceId(),n=this.sourcePreviewNodeOptions.get(r);return Tf({anchorX:.5,anchorY:.5,captureDraggingState:!1},n||{})}},{key:"isDraggingNativeItem",value:function(){var r=this.monitor.getItemType();return Object.keys(Of).some(function(n){return Of[n]===r})}},{key:"beginDragNativeItem",value:function(r,n){this.clearCurrentDragSourceNode(),this.currentNativeSource=M0(r,n),this.currentNativeHandle=this.registry.addSource(r,this.currentNativeSource),this.actions.beginDrag([this.currentNativeHandle])}},{key:"setCurrentDragSourceNode",value:function(r){var n=this;this.clearCurrentDragSourceNode(),this.currentDragSourceNode=r;var s=1e3;this.mouseMoveTimeoutTimer=setTimeout(function(){var i;return(i=n.rootElement)===null||i===void 0?void 0:i.addEventListener("mousemove",n.endDragIfSourceWasRemovedFromDOM,!0)},s)}},{key:"clearCurrentDragSourceNode",value:function(){if(this.currentDragSourceNode){if(this.currentDragSourceNode=null,this.rootElement){var r;(r=this.window)===null||r===void 0||r.clearTimeout(this.mouseMoveTimeoutTimer||void 0),this.rootElement.removeEventListener("mousemove",this.endDragIfSourceWasRemovedFromDOM,!0)}return this.mouseMoveTimeoutTimer=null,!0}return!1}},{key:"handleDragStart",value:function(r,n){r.defaultPrevented||(this.dragStartSourceIds||(this.dragStartSourceIds=[]),this.dragStartSourceIds.unshift(n))}},{key:"handleDragEnter",value:function(r,n){this.dragEnterTargetIds.unshift(n)}},{key:"handleDragOver",value:function(r,n){this.dragOverTargetIds===null&&(this.dragOverTargetIds=[]),this.dragOverTargetIds.unshift(n)}},{key:"handleDrop",value:function(r,n){this.dropTargetIds.unshift(n)}}]),e}(),Ki;function q0(){return Ki||(Ki=new Image,Ki.src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="),Ki}var H0=function(t,r,n){return new V0(t,r,n)};function W0(e,t){return typeof e=="function"?e(t):e??"NODE"}function Q0(e){return e.isDraggable&&!e.isEditing}function K0(e){const t=Dt(),r=t.selectedIds,[n,s,i]=GC(()=>({canDrag:()=>Q0(e),type:W0(t.props.dragType,e),item:()=>{const o=t.isSelected(e.id)?Array.from(r):[e.id];return t.dispatch(Dn.dragStart(e.id,o)),{id:e.id,dragIds:o,data:e.data}},end:()=>{t.hideCursor(),t.redrawList(),t.dispatch(Dn.dragEnd())}}),[r,e,t.props.dragType]);return h.useEffect(()=>{i(q0())},[i]),s}function G0(e,t){const r=e.getBoundingClientRect(),n=t.x-Math.round(r.x),s=t.y-Math.round(r.y),i=r.height,o=s<i/2,a=!o,c=i/4,d=s>c&&s<i-c;return{x:n,inTopHalf:o,inBottomHalf:a,inMiddle:d,atTop:!d&&o,atBottom:!d&&a}}function Y0(e,t,r,n){return e?e.isInternal?n.atTop?[t,e]:n.inMiddle?[e,e]:[e,r]:n.inTopHalf?[t,e]:[e,r]:[t,null]}function Gi(e,t){return{parentId:e||null,index:t}}function Pn(e,t){return{type:"line",index:e,level:t}}function R0(e){return{type:"highlight",id:e}}function Ka(e,t){var r;let n=e;for(;n.parent&&n.level>t;)n=n.parent;const s=((r=n.parent)===null||r===void 0?void 0:r.id)||null,i=cd(n)+1;return{parentId:s,index:i}}function Nf(e){var t;const r=G0(e.element,e.offset),n=e.indent,s=Math.round(Math.max(0,r.x-n)/n),{node:i,nextNode:o,prevNode:a}=e,[c,d]=Y0(i,a,o,r);if(i&&i.isInternal&&r.inMiddle)return{drop:Gi(i.id,null),cursor:R0(i.id)};if(!c)return{drop:Gi((t=d==null?void 0:d.parent)===null||t===void 0?void 0:t.id,0),cursor:Pn(0,0)};if(id(c)){const u=ki(s,(d==null?void 0:d.level)||0,c.level);return{drop:Ka(c,u),cursor:Pn(c.rowIndex+1,u)}}if(od(c)){const u=ki(s,(d==null?void 0:d.level)||0,c.level);return{drop:Ka(c,u),cursor:Pn(c.rowIndex+1,u)}}if(ad(c)){const u=ki(s,0,c.level+1);return u>c.level?{drop:Gi(c.id,0),cursor:Pn(c.rowIndex+1,u)}:{drop:Ka(c,u),cursor:Pn(c.rowIndex+1,u)}}return{drop:Gi(c==null?void 0:c.id,0),cursor:Pn(c.rowIndex+1,c.level+1)}}function X0(e,t){const r=Dt(),[n,s]=pf(()=>({accept:"NODE",canDrop:()=>r.canDrop(),hover:(i,o)=>{const a=o.getClientOffset();if(!e.current||!a)return;const{cursor:c,drop:d}=Nf({element:e.current,offset:a,indent:r.indent,node:t,prevNode:t.prev,nextNode:t.next});d&&r.dispatch(Dn.hovering(d.parentId,d.index)),o.canDrop()?c&&r.showCursor(c):r.hideCursor()},drop:(i,o)=>{if(!o.canDrop())return null;r.drop()}}),[t,e.current,r.props]);return s}function Z0(e){const t=Dt(),r=t.at(e);if(!r)throw new Error(`Could not find node for index: ${e}`);return h.useMemo(()=>{const n=r.clone();return t.visibleNodes[e]=n,n},[...Object.values(r.state),r])}const kf=h.memo(function({index:t,style:r}){sd(),y_();const n=Dt(),s=Z0(t),i=h.useRef(null),o=K0(s),a=X0(i,s),c=h.useCallback(p=>{i.current=p,a(p)},[a]),d=n.indent*s.level,u=h.useMemo(()=>({paddingLeft:d}),[d]),f=h.useMemo(()=>{var p,v;return Object.assign(Object.assign({},r),{top:parseFloat(r.top)+((v=(p=n.props.padding)!==null&&p!==void 0?p:n.props.paddingTop)!==null&&v!==void 0?v:0),minWidth:"max-content"})},[r,n.props.padding,n.props.paddingTop]),g={role:"treeitem","aria-level":s.level+1,"aria-selected":s.isSelected,"aria-expanded":s.isOpen,style:f,tabIndex:-1,className:n.props.rowClassName};h.useEffect(()=>{var p;!s.isEditing&&s.isFocused&&((p=i.current)===null||p===void 0||p.focus({preventScroll:!0}))},[s.isEditing,s.isFocused,i.current]);const y=n.renderNode,_=n.renderRow;return l.jsx(_,{node:s,innerRef:c,attrs:g,children:l.jsx(y,{node:s,tree:n,style:u,dragHandle:o})})});let Ga="",xf=null;function Af(){sd();const e=Dt();return l.jsx("div",{role:"tree","aria-label":e.props["aria-label"],"aria-labelledby":e.props["aria-labelledby"],"aria-multiselectable":!e.props.disableMultiSelection||void 0,style:{height:e.height,width:e.width,minHeight:0,minWidth:0},onContextMenu:e.props.onContextMenu,onClick:e.props.onClick,tabIndex:0,onFocus:t=>{t.currentTarget.contains(t.relatedTarget)||e.onFocus()},onBlur:t=>{t.currentTarget.contains(t.relatedTarget)||e.onBlur()},onKeyDown:t=>{var r;if(e.isEditing)return;if(t.key==="Backspace"){if(!e.props.onDelete)return;const s=Array.from(e.selectedIds);if(s.length>1){let i=e.mostRecentNode;for(;i&&i.isSelected;)i=i.nextSibling;i||(i=e.lastNode),e.focus(i,{scroll:!1}),e.delete(Array.from(s))}else{const i=e.focusedNode;if(i){const o=i.nextSibling,a=i.parent;e.focus(o||a,{scroll:!1}),e.delete(i)}}return}if(t.key==="Tab"&&!t.shiftKey){t.preventDefault(),ud(t.currentTarget);return}if(t.key==="Tab"&&t.shiftKey){t.preventDefault(),dd(t.currentTarget);return}if(t.key==="ArrowDown"){t.preventDefault();const s=e.nextNode;if(t.metaKey){e.select(e.focusedNode),e.activate(e.focusedNode);return}else if(!t.shiftKey||e.props.disableMultiSelection){e.focus(s);return}else{if(!s)return;const i=e.focusedNode;i?i.isSelected?e.selectContiguous(s):e.selectMulti(s):e.focus(e.firstNode);return}}if(t.key==="ArrowUp"){t.preventDefault();const s=e.prevNode;if(!t.shiftKey||e.props.disableMultiSelection){e.focus(s);return}else{if(!s)return;const i=e.focusedNode;i?i.isSelected?e.selectContiguous(s):e.selectMulti(s):e.focus(e.lastNode);return}}if(t.key==="ArrowRight"){const s=e.focusedNode;if(!s)return;s.isInternal&&s.isOpen?e.focus(e.nextNode):s.isInternal&&e.open(s.id);return}if(t.key==="ArrowLeft"){const s=e.focusedNode;if(!s||s.isRoot)return;s.isInternal&&s.isOpen?e.close(s.id):!((r=s.parent)===null||r===void 0)&&r.isRoot||e.focus(s.parent);return}if(t.key==="a"&&(t.metaKey||t.ctrlKey)&&!e.props.disableMultiSelection){t.preventDefault(),e.selectAll();return}if(t.key==="a"&&!t.metaKey&&!t.ctrlKey&&e.props.onCreate){e.createLeaf();return}if(t.key==="A"&&!t.metaKey&&!t.ctrlKey){if(!e.props.onCreate)return;e.createInternal();return}if(t.key==="Home"){t.preventDefault(),e.focus(e.firstNode);return}if(t.key==="End"){t.preventDefault(),e.focus(e.lastNode);return}if(t.key==="Enter"){const s=e.focusedNode;if(!s||!s.isEditable||!e.props.onRename)return;setTimeout(()=>{s&&e.edit(s)});return}if(t.key===" "){t.preventDefault();const s=e.focusedNode;if(!s)return;s.isLeaf?(s.select(),s.activate()):s.toggle();return}if(t.key==="*"){const s=e.focusedNode;if(!s)return;e.openSiblings(s);return}if(t.key==="PageUp"){t.preventDefault(),e.pageUp();return}t.key==="PageDown"&&(t.preventDefault(),e.pageDown()),clearTimeout(xf),Ga+=t.key,xf=setTimeout(()=>{Ga=""},600);const n=e.visibleNodes.find(s=>{const i=s.data.name;return typeof i=="string"?i.toLowerCase().startsWith(Ga):!1});n&&e.focus(n.id)},children:l.jsx(J0,{})})}function J0(){var e,t;const r=Dt(),n={className:r.props.className,outerRef:r.listEl,itemCount:r.visibleNodes.length,height:r.height,width:r.width,overscanCount:r.overscanCount,itemKey:s=>{var i;return((i=r.visibleNodes[s])===null||i===void 0?void 0:i.id)||s},outerElementType:(e=r.props.outerElementType)!==null&&e!==void 0?e:sw,innerElementType:(t=r.props.innerElementType)!==null&&t!==void 0?t:aw,onScroll:r.props.onScroll,onItemsRendered:r.onItemsRendered.bind(r)};return typeof r.props.rowHeight=="function"?l.jsx(ew,Object.assign({},n,{itemSize:r.rowHeightAt,ref:r.list,children:kf})):l.jsx(tw,Object.assign({},n,{itemSize:r.rowHeight,ref:r.list,children:kf}))}function Pf(e){return e.isFiltered?t1(e.root,e.isMatch.bind(e)):e1(e.root)}function e1(e){const t=[];function r(n){var s;n.level>=0&&t.push(n),n.isOpen&&((s=n.children)===null||s===void 0||s.forEach(r))}return r(e),t.forEach(Mf),t}function t1(e,t){const r={},n=[];function s(o){if(!o.isRoot&&t(o)){r[o.id]=!0;let c=o.parent;for(;c;)r[c.id]=!0,c=c.parent}if(o.children)for(let c of o.children)s(c)}function i(o){var a;o.level>=0&&r[o.id]&&n.push(o),o.isOpen&&((a=o.children)===null||a===void 0||a.forEach(i))}return s(e),i(e),n.forEach(Mf),n}function Mf(e,t){e.rowIndex=t}const Lf=e=>e.reduce((t,r,n)=>(t[r.id]=n,t),{});var Ya=function(e,t,r,n){function s(i){return i instanceof r?i:new r(function(o){o(i)})}return new(r||(r=Promise))(function(i,o){function a(u){try{d(n.next(u))}catch(f){o(f)}}function c(u){try{d(n.throw(u))}catch(f){o(f)}}function d(u){u.done?i(u.value):s(u.value).then(a,c)}d((n=n.apply(e,t||[])).next())})};const{safeRun:yt}=w_;class Is{constructor(t,r,n,s){this.store=t,this.props=r,this.list=n,this.listEl=s,this.visibleStartIndex=0,this.visibleStopIndex=0,this.rowOffsets=null,this.rowHeightAt=i=>{const o=this.props.rowHeight;if(typeof o=="function"){const a=this.at(i);return a?o(a):this.rowHeight}return o??24},this.rowTopPosition=i=>{if(typeof this.props.rowHeight!="function")return i*this.rowHeight;const o=this.getRowOffsets(),a=Math.max(0,Math.min(i,o.length-1));return o[a]},this.redrawList=(i=0)=>{this.rowOffsets=null;const o=this.list.current;o&&"resetAfterIndex"in o&&o.resetAfterIndex(Math.max(0,i))},this.root=yd(this),this.visibleNodes=Pf(this),this.idToIndex=Lf(this.visibleNodes)}update(t){this.props=t,this.root=yd(this),this.visibleNodes=Pf(this),this.idToIndex=Lf(this.visibleNodes),this.rowOffsets=null;const r=this.list.current;r&&"resetAfterIndex"in r&&r.resetAfterIndex(0,!1)}dispatch(t){return this.store.dispatch(t)}get state(){return this.store.getState()}get openState(){return this.state.nodes.open.unfiltered}get width(){var t;return(t=this.props.width)!==null&&t!==void 0?t:300}get height(){var t;return(t=this.props.height)!==null&&t!==void 0?t:500}get indent(){var t;return(t=this.props.indent)!==null&&t!==void 0?t:24}get rowHeight(){return typeof this.props.rowHeight=="number"?this.props.rowHeight:24}getRowOffsets(){if(this.rowOffsets)return this.rowOffsets;const t=[0];for(let r=0;r<this.visibleNodes.length;r++)t.push(t[r]+this.rowHeightAt(r));return this.rowOffsets=t,t}get overscanCount(){var t;return(t=this.props.overscanCount)!==null&&t!==void 0?t:1}get searchTerm(){return(this.props.searchTerm||"").trim()}get matchFn(){var t;const r=(t=this.props.searchMatch)!==null&&t!==void 0?t:(n,s)=>JSON.stringify(Object.values(n.data)).toLocaleLowerCase().includes(s.toLocaleLowerCase());return n=>r(n,this.searchTerm)}accessChildren(t){var r;const n=this.props.childrenAccessor||"children";return(r=ws(t,n))!==null&&r!==void 0?r:null}accessId(t){const r=this.props.idAccessor||"id",n=ws(t,r);if(!n)throw new Error("Data must contain an 'id' property or props.idAccessor must return a string");return n}identify(t){if(typeof t=="string")return t;if(t instanceof Cs)return t.id;const r=this.props.idAccessor||"id";return ws(t,r)}identifyNull(t){return t==null?null:this.identify(t)}get firstNode(){var t;return(t=this.visibleNodes[0])!==null&&t!==void 0?t:null}get lastNode(){var t;return(t=this.visibleNodes[this.visibleNodes.length-1])!==null&&t!==void 0?t:null}get focusedNode(){var t;return(t=this.get(this.state.nodes.focus.id))!==null&&t!==void 0?t:null}get mostRecentNode(){var t;return(t=this.get(this.state.nodes.selection.mostRecent))!==null&&t!==void 0?t:null}get nextNode(){const t=this.indexOf(this.focusedNode);return t===null?null:this.at(t+1)}get prevNode(){const t=this.indexOf(this.focusedNode);return t===null?null:this.at(t-1)}get(t){return t&&t in this.idToIndex&&this.visibleNodes[this.idToIndex[t]]||null}at(t){return this.visibleNodes[t]||null}nodesBetween(t,r){var n;if(t===null||r===null)return[];const s=(n=this.indexOf(t))!==null&&n!==void 0?n:0,i=this.indexOf(r);if(i===null)return[];const o=Math.min(s,i),a=Math.max(s,i);return this.visibleNodes.slice(o,a+1)}indexOf(t){const r=this.identifyNull(t);return r?this.idToIndex[r]:null}get editingId(){return this.state.nodes.edit.id}createInternal(){return this.create({type:"internal"})}createLeaf(){return this.create({type:"leaf"})}create(){return Ya(this,arguments,void 0,function*(t={}){var r,n;const s=t.parentId===void 0?gd(this):t.parentId,i=(r=t.index)!==null&&r!==void 0?r:pd(this),o=(n=t.type)!==null&&n!==void 0?n:"leaf",a=yield yt(this.props.onCreate,{type:o,parentId:s,index:i,parentNode:this.get(s)});a&&(this.focus(a),setTimeout(()=>{this.edit(a).then(()=>{this.select(a),this.activate(a)})}))})}delete(t){return Ya(this,void 0,void 0,function*(){if(!t)return;const n=(Array.isArray(t)?t:[t]).map(o=>this.identify(o)),s=n.map(o=>this.get(o)).filter(o=>!!o),i=s.length?Math.min(...s.map(o=>{var a;return(a=o.rowIndex)!==null&&a!==void 0?a:0})):0;yield yt(this.props.onDelete,{nodes:s,ids:n}),this.redrawList(i)})}edit(t){var r,n;const s=this.identify(t);return this.resolveEdit({cancelled:!0}),this.scrollTo(s),this.dispatch(Sa(s)),this.redrawList((n=(r=this.get(s))===null||r===void 0?void 0:r.rowIndex)!==null&&n!==void 0?n:0),new Promise(i=>{Is.editPromise=i})}submit(t,r){return Ya(this,void 0,void 0,function*(){var n,s;if(!t)return;const i=this.identify(t);yield yt(this.props.onRename,{id:i,name:r,node:this.get(i)}),this.dispatch(Sa(null)),this.resolveEdit({cancelled:!1,value:r}),this.redrawList((s=(n=this.get(i))===null||n===void 0?void 0:n.rowIndex)!==null&&s!==void 0?s:0),setTimeout(()=>this.onFocus())})}reset(){this.dispatch(Sa(null)),this.resolveEdit({cancelled:!0}),this.redrawList(),setTimeout(()=>this.onFocus())}activate(t){const r=this.get(this.identifyNull(t));r&&yt(this.props.onActivate,r)}resolveEdit(t){const r=Is.editPromise;r&&r(t),Is.editPromise=null}get selectedIds(){return this.state.nodes.selection.ids}get selectedNodes(){let t=[];for(let r of Array.from(this.selectedIds)){const n=this.get(r);n&&t.push(n)}return t}focus(t,r={}){t&&(this.props.selectionFollowsFocus?this.select(t):(this.dispatch(On(this.identify(t))),r.scroll!==!1&&this.scrollTo(t),this.focusedNode&&yt(this.props.onFocus,this.focusedNode)))}pageUp(){var t,r;const n=this.visibleStartIndex,i=this.visibleStopIndex-n;let o=(r=(t=this.focusedNode)===null||t===void 0?void 0:t.rowIndex)!==null&&r!==void 0?r:0;o>n?o=n:o=Math.max(n-i,0),this.focus(this.at(o))}pageDown(){var t,r;const n=this.visibleStartIndex,s=this.visibleStopIndex,i=s-n;let o=(r=(t=this.focusedNode)===null||t===void 0?void 0:t.rowIndex)!==null&&r!==void 0?r:0;o<s?o=s:o=Math.min(o+i,this.visibleNodes.length-1),this.focus(this.at(o))}select(t,r={}){var n;if(!t)return;const s=r.focus!==!1,i=this.identify(t);s&&this.dispatch(On(i)),!((n=this.get(i))===null||n===void 0)&&n.isSelectable&&this.setSelection({ids:[i],anchor:i,mostRecent:i}),this.scrollTo(i,r.align),this.focusedNode&&s&&yt(this.props.onFocus,this.focusedNode)}deselect(t){if(!t)return;const r=this.identify(t);this.dispatch(Ir.remove(r)),yt(this.props.onSelect,this.selectedNodes)}selectMulti(t,r={}){const n=this.get(this.identifyNull(t));if(!n)return;const s=r.focus!==!1;s&&this.dispatch(On(n.id)),n.isSelectable&&(this.dispatch(Ir.add(n.id)),this.dispatch(Ir.anchor(n.id)),this.dispatch(Ir.mostRecent(n.id))),this.scrollTo(n,r.align),this.focusedNode&&s&&yt(this.props.onFocus,this.focusedNode),yt(this.props.onSelect,this.selectedNodes)}selectContiguous(t){var r;if(!t)return;const n=this.identify(t);if(this.dispatch(On(n)),!((r=this.get(n))===null||r===void 0)&&r.isSelectable){const{anchor:s,mostRecent:i}=this.state.nodes.selection,o=this.filterSelectableNodes(this.nodesBetween(s,this.identifyNull(n)));this.dispatch(Ir.remove(this.nodesBetween(s,i))),this.dispatch(Ir.add(o)),this.dispatch(Ir.mostRecent(n))}this.scrollTo(n),this.focusedNode&&yt(this.props.onFocus,this.focusedNode),yt(this.props.onSelect,this.selectedNodes)}deselectAll(){this.setSelection({ids:[],anchor:null,mostRecent:null})}selectAll(){var t,r,n;const s=this.filterSelectableNodes(Object.keys(this.idToIndex));this.setSelection({ids:s,anchor:(t=s[0])!==null&&t!==void 0?t:null,mostRecent:(r=s[s.length-1])!==null&&r!==void 0?r:null}),this.dispatch(On((n=this.lastNode)===null||n===void 0?void 0:n.id)),this.focusedNode&&yt(this.props.onFocus,this.focusedNode)}filterSelectableNodes(t){return t.map(r=>this.get(this.identify(r))).filter(r=>!!r&&r.isSelectable)}setSelection(t){var r;const n=new Set((r=t.ids)===null||r===void 0?void 0:r.map(o=>this.identify(o))),s=this.identifyNull(t.anchor),i=this.identifyNull(t.mostRecent);this.dispatch(Ir.set({ids:n,anchor:s,mostRecent:i})),yt(this.props.onSelect,this.selectedNodes)}get cursorParentId(){const{cursor:t}=this.state.dnd;switch(t.type){case"highlight":return t.id;default:return null}}get cursorOverFolder(){return this.state.dnd.cursor.type==="highlight"}get dragNodes(){return this.state.dnd.dragIds.map(t=>this.get(t)).filter(t=>!!t)}get dragNode(){return this.get(this.state.nodes.drag.id)}get dragDestinationParent(){return this.get(this.state.nodes.drag.destinationParentId)}get dragDestinationIndex(){return this.state.nodes.drag.destinationIndex}canDrop(){var t;if(this.isFiltered)return!1;const r=(t=this.get(this.state.dnd.parentId))!==null&&t!==void 0?t:this.root,n=this.dragNodes,s=this.props.disableDrop;for(const i of n)if(!i||!r||i.isInternal&&ld(r,i))return!1;return typeof s=="function"?!s({parentNode:r,dragNodes:this.dragNodes,index:this.state.dnd.index||0}):typeof s=="string"?!r.data[s]:typeof s=="boolean"?!s:!0}drop(){const{parentId:t,index:r,dragIds:n}=this.state.dnd;yt(this.props.onMove,{dragIds:n,parentId:t===Ss?null:t,index:r===null?0:r,dragNodes:this.dragNodes,parentNode:this.get(t)}),this.open(t)}hideCursor(){this.dispatch(Dn.cursor({type:"none"}))}showCursor(t){this.dispatch(Dn.cursor(t))}open(t,r=!0){var n,s;const i=this.identifyNull(t);i&&(this.isOpen(i)||(this.dispatch(Ca.open(i,this.isFiltered)),r&&this.redrawList((s=(n=this.get(i))===null||n===void 0?void 0:n.rowIndex)!==null&&s!==void 0?s:0),yt(this.props.onToggle,i)))}close(t,r=!0){var n,s;const i=this.identifyNull(t);i&&this.isOpen(i)&&(this.dispatch(Ca.close(i,this.isFiltered)),r&&this.redrawList((s=(n=this.get(i))===null||n===void 0?void 0:n.rowIndex)!==null&&s!==void 0?s:0),yt(this.props.onToggle,i))}toggle(t){const r=this.identifyNull(t);if(r)return this.isOpen(r)?this.close(r):this.open(r)}openParents(t){const r=this.identifyNull(t);if(!r)return;const n=wa(this.root,r);let s=n==null?void 0:n.parent;for(;s;)this.open(s.id,!1),s=s.parent;this.redrawList()}openSiblings(t){const r=t.parent;if(!r)this.toggle(t.id);else if(r.children){const n=t.isOpen;for(let s of r.children)s.isInternal&&(n?this.close(s.id,!1):this.open(s.id,!1));this.redrawList(),this.scrollTo(this.focusedNode)}}openAll(){xi(this.root,t=>{t.isInternal&&this.open(t.id,!1)}),this.redrawList()}closeAll(){xi(this.root,t=>{t.isInternal&&this.close(t.id,!1)}),this.redrawList()}scrollTo(t,r="smart"){if(!t)return;const n=this.identify(t);return this.openParents(n),hd(()=>n in this.idToIndex).then(()=>{var s;const i=this.idToIndex[n];i!==void 0&&((s=this.list.current)===null||s===void 0||s.scrollToItem(i,r))}).catch(()=>{})}get isEditing(){return this.state.nodes.edit.id!==null}get isFiltered(){var t;return!!(!((t=this.props.searchTerm)===null||t===void 0)&&t.trim())}get hasFocus(){return this.state.nodes.focus.treeFocused}get hasNoSelection(){return this.state.nodes.selection.ids.size===0}get hasOneSelection(){return this.state.nodes.selection.ids.size===1}get hasMultipleSelections(){return this.state.nodes.selection.ids.size>1}isSelected(t){return t?this.state.nodes.selection.ids.has(t):!1}isOpen(t){var r,n,s;if(!t)return!1;if(t===Ss)return!0;const i=(r=this.props.openByDefault)!==null&&r!==void 0?r:!0;return this.isFiltered?(n=this.state.nodes.open.filtered[t])!==null&&n!==void 0?n:!0:(s=this.state.nodes.open.unfiltered[t])!==null&&s!==void 0?s:i}isEditable(t){return this.isActionPossible(t,this.props.disableEdit)}isDraggable(t){return this.isActionPossible(t,this.props.disableDrag)}isSelectable(t){return this.isActionPossible(t,this.props.disableSelect)}isActionPossible(t,r=()=>!1){return!ws(t,r)}isDragging(t){const r=this.identifyNull(t);return r?this.state.nodes.drag.id===r:!1}isFocused(t){return this.hasFocus&&this.state.nodes.focus.id===t}isMatch(t){return this.matchFn(t)}willReceiveDrop(t){const r=this.identifyNull(t);if(!r)return!1;const{destinationParentId:n,destinationIndex:s}=this.state.nodes.drag;return r===n&&s===null}onFocus(){const t=this.focusedNode||this.firstNode;t&&this.dispatch(On(t.id))}onBlur(){this.dispatch(x_())}onItemsRendered(t){this.visibleStartIndex=t.visibleStartIndex,this.visibleStopIndex=t.visibleStopIndex}get renderContainer(){return this.props.renderContainer||Af}get renderRow(){return this.props.renderRow||I_}get renderNode(){return this.props.children||D_}get renderDragPreview(){return this.props.renderDragPreview||md}get renderCursor(){return this.props.renderCursor||O_}}function vt(e){return`Minified Redux error #${e}; visit https://redux.js.org/Errors?code=${e} for the full message or use the non-minified dev environment for full errors. `}var r1=typeof Symbol=="function"&&Symbol.observable||"@@observable",Ff=r1,Ra=()=>Math.random().toString(36).substring(7).split("").join("."),n1={INIT:`@@redux/INIT${Ra()}`,REPLACE:`@@redux/REPLACE${Ra()}`,PROBE_UNKNOWN_ACTION:()=>`@@redux/PROBE_UNKNOWN_ACTION${Ra()}`},Yr=n1;function $f(e){if(typeof e!="object"||e===null)return!1;let t=e;for(;Object.getPrototypeOf(t)!==null;)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t||Object.getPrototypeOf(e)===null}function s1(e){if(e===void 0)return"undefined";if(e===null)return"null";const t=typeof e;switch(t){case"boolean":case"string":case"number":case"symbol":case"function":return t}if(Array.isArray(e))return"array";if(a1(e))return"date";if(o1(e))return"error";const r=i1(e);switch(r){case"Symbol":case"Promise":case"WeakMap":case"WeakSet":case"Map":case"Set":return r}return Object.prototype.toString.call(e).slice(8,-1).toLowerCase().replace(/\s/g,"")}function i1(e){return typeof e.constructor=="function"?e.constructor.name:null}function o1(e){return e instanceof Error||typeof e.message=="string"&&e.constructor&&typeof e.constructor.stackTraceLimit=="number"}function a1(e){return e instanceof Date?!0:typeof e.toDateString=="function"&&typeof e.getDate=="function"&&typeof e.setDate=="function"}function Dr(e){let t=typeof e;return process.env.NODE_ENV!=="production"&&(t=s1(e)),t}function jf(e,t,r){if(typeof e!="function")throw new Error(process.env.NODE_ENV==="production"?vt(2):`Expected the root reducer to be a function. Instead, received: '${Dr(e)}'`);if(typeof t=="function"&&typeof r=="function"||typeof r=="function"&&typeof arguments[3]=="function")throw new Error(process.env.NODE_ENV==="production"?vt(0):"It looks like you are passing several store enhancers to createStore(). This is not supported. Instead, compose them together to a single function. See https://redux.js.org/tutorials/fundamentals/part-4-store#creating-a-store-with-enhancers for an example.");if(typeof t=="function"&&typeof r>"u"&&(r=t,t=void 0),typeof r<"u"){if(typeof r!="function")throw new Error(process.env.NODE_ENV==="production"?vt(1):`Expected the enhancer to be a function. Instead, received: '${Dr(r)}'`);return r(jf)(e,t)}let n=e,s=t,i=new Map,o=i,a=0,c=!1;function d(){o===i&&(o=new Map,i.forEach((v,m)=>{o.set(m,v)}))}function u(){if(c)throw new Error(process.env.NODE_ENV==="production"?vt(3):"You may not call store.getState() while the reducer is executing. The reducer has already received the state as an argument. Pass it down from the top reducer instead of reading it from the store.");return s}function f(v){if(typeof v!="function")throw new Error(process.env.NODE_ENV==="production"?vt(4):`Expected the listener to be a function. Instead, received: '${Dr(v)}'`);if(c)throw new Error(process.env.NODE_ENV==="production"?vt(5):"You may not call store.subscribe() while the reducer is executing. If you would like to be notified after the store has been updated, subscribe from a component and invoke store.getState() in the callback to access the latest state. See https://redux.js.org/api/store#subscribelistener for more details.");let m=!0;d();const b=a++;return o.set(b,v),function(){if(m){if(c)throw new Error(process.env.NODE_ENV==="production"?vt(6):"You may not unsubscribe from a store listener while the reducer is executing. See https://redux.js.org/api/store#subscribelistener for more details.");m=!1,d(),o.delete(b),i=null}}}function g(v){if(!$f(v))throw new Error(process.env.NODE_ENV==="production"?vt(7):`Actions must be plain objects. Instead, the actual type was: '${Dr(v)}'. You may need to add middleware to your store setup to handle dispatching other values, such as 'redux-thunk' to handle dispatching functions. See https://redux.js.org/tutorials/fundamentals/part-4-store#middleware and https://redux.js.org/tutorials/fundamentals/part-6-async-logic#using-the-redux-thunk-middleware for examples.`);if(typeof v.type>"u")throw new Error(process.env.NODE_ENV==="production"?vt(8):'Actions may not have an undefined "type" property. You may have misspelled an action type string constant.');if(typeof v.type!="string")throw new Error(process.env.NODE_ENV==="production"?vt(17):`Action "type" property must be a string. Instead, the actual type was: '${Dr(v.type)}'. Value was: '${v.type}' (stringified)`);if(c)throw new Error(process.env.NODE_ENV==="production"?vt(9):"Reducers may not dispatch actions.");try{c=!0,s=n(s,v)}finally{c=!1}return(i=o).forEach(b=>{b()}),v}function y(v){if(typeof v!="function")throw new Error(process.env.NODE_ENV==="production"?vt(10):`Expected the nextReducer to be a function. Instead, received: '${Dr(v)}`);n=v,g({type:Yr.REPLACE})}function _(){const v=f;return{subscribe(m){if(typeof m!="object"||m===null)throw new Error(process.env.NODE_ENV==="production"?vt(11):`Expected the observer to be an object. Instead, received: '${Dr(m)}'`);function b(){const w=m;w.next&&w.next(u())}return b(),{unsubscribe:v(b)}},[Ff](){return this}}}return g({type:Yr.INIT}),{dispatch:g,subscribe:f,getState:u,replaceReducer:y,[Ff]:_}}function Bf(e){typeof console<"u"&&typeof console.error=="function"&&console.error(e);try{throw new Error(e)}catch{}}function l1(e,t,r,n){const s=Object.keys(t),i=r&&r.type===Yr.INIT?"preloadedState argument passed to createStore":"previous state received by the reducer";if(s.length===0)return"Store does not have a valid reducer. Make sure the argument passed to combineReducers is an object whose values are reducers.";if(!$f(e))return`The ${i} has unexpected type of "${Dr(e)}". Expected argument to be an object with the following keys: "${s.join('", "')}"`;const o=Object.keys(e).filter(a=>!t.hasOwnProperty(a)&&!n[a]);if(o.forEach(a=>{n[a]=!0}),!(r&&r.type===Yr.REPLACE)&&o.length>0)return`Unexpected ${o.length>1?"keys":"key"} "${o.join('", "')}" found in ${i}. Expected to find one of the known reducer keys instead: "${s.join('", "')}". Unexpected keys will be ignored.`}function c1(e){Object.keys(e).forEach(t=>{const r=e[t];if(typeof r(void 0,{type:Yr.INIT})>"u")throw new Error(process.env.NODE_ENV==="production"?vt(12):`The slice reducer for key "${t}" returned undefined during initialization. If the state passed to the reducer is undefined, you must explicitly return the initial state. The initial state may not be undefined. If you don't want to set a value for this reducer, you can use null instead of undefined.`);if(typeof r(void 0,{type:Yr.PROBE_UNKNOWN_ACTION()})>"u")throw new Error(process.env.NODE_ENV==="production"?vt(13):`The slice reducer for key "${t}" returned undefined when probed with a random type. Don't try to handle '${Yr.INIT}' or other actions in "redux/*" namespace. They are considered private. Instead, you must return the current state for any unknown actions, unless it is undefined, in which case you must return the initial state, regardless of the action type. The initial state may not be undefined, but can be null.`)})}function Uf(e){const t=Object.keys(e),r={};for(let o=0;o<t.length;o++){const a=t[o];process.env.NODE_ENV!=="production"&&typeof e[a]>"u"&&Bf(`No reducer provided for key "${a}"`),typeof e[a]=="function"&&(r[a]=e[a])}const n=Object.keys(r);let s;process.env.NODE_ENV!=="production"&&(s={});let i;try{c1(r)}catch(o){i=o}return function(a={},c){if(i)throw i;if(process.env.NODE_ENV!=="production"){const f=l1(a,r,c,s);f&&Bf(f)}let d=!1;const u={};for(let f=0;f<n.length;f++){const g=n[f],y=r[g],_=a[g],p=y(_,c);if(typeof p>"u"){const v=c&&c.type;throw new Error(process.env.NODE_ENV==="production"?vt(14):`When called with an action of type ${v?`"${String(v)}"`:"(unknown type)"}, the slice reducer for key "${g}" returned undefined. To ignore an action, you must explicitly return the previous state. If you want this reducer to hold no value, you can return null instead of undefined.`)}u[g]=p,d=d||p!==_}return d=d||n.length!==Object.keys(a).length,d?u:a}}function u1(e=In().nodes.drag,t){switch(t.type){case"DND_DRAG_START":return Object.assign(Object.assign({},e),{id:t.id,selectedIds:t.dragIds});case"DND_DRAG_END":return Object.assign(Object.assign({},e),{id:null,destinationParentId:null,destinationIndex:null,selectedIds:[]});case"DND_HOVERING":return t.parentId!==e.destinationParentId||t.index!=e.destinationIndex?Object.assign(Object.assign({},e),{destinationParentId:t.parentId,destinationIndex:t.index}):e;default:return e}}const d1=Uf({nodes:Uf({focus:A_,edit:k_,open:P_,selection:M_,drag:u1}),dnd:L_}),f1=In();function h1({treeProps:e,imperativeHandle:t,children:r}){const n=h.useRef(null),s=h.useRef(null),i=h.useRef(jf(d1,In(e))),o=g_.useSyncExternalStore(i.current.subscribe,i.current.getState,()=>f1),a=h.useMemo(()=>new Is(i.current,e,n,s),[]),c=h.useRef(0);return h.useMemo(()=>{c.current+=1,a.update(e)},Object.values(e)),h.useMemo(()=>{c.current+=1,a.update(a.props)},[o.nodes.open]),h.useImperativeHandle(t,()=>a),h.useEffect(()=>{a.props.selection?a.select(a.props.selection,{focus:!1}):a.deselectAll()},[a.props.selection]),h.useEffect(()=>{a.props.searchTerm||i.current.dispatch(Ca.clear(!0))},[a.props.searchTerm]),l.jsx(ed.Provider,{value:a,children:l.jsx(nd.Provider,{value:c.current,children:l.jsx(td.Provider,{value:o.nodes,children:l.jsx(rd.Provider,{value:o.dnd,children:l.jsx(HS,Object.assign({},e.dndManager?{manager:e.dndManager}:{backend:e.dndBackend||H0,options:{rootElement:a.props.dndRootElement||void 0}},{children:r}))})})})})}function p1(){const e=Dt(),[,t]=pf(()=>({accept:"NODE",canDrop:(r,n)=>n.isOver({shallow:!0})?e.canDrop():!1,hover:(r,n)=>{if(!n.isOver({shallow:!0}))return;const s=n.getClientOffset();if(!e.listEl.current||!s)return;const{cursor:i,drop:o}=Nf({element:e.listEl.current,offset:s,indent:e.indent,node:null,prevNode:e.visibleNodes[e.visibleNodes.length-1],nextNode:null});o&&e.dispatch(Dn.hovering(o.parentId,o.index)),n.canDrop()?i&&e.showCursor(i):e.hideCursor()},drop:(r,n)=>{if(!n.isOver({shallow:!0})||!n.canDrop())return null;e.drop()}}),[e]);t(e.listEl)}function g1(e){return p1(),e.children}function y1(){const t=Dt().props.renderContainer||Af;return l.jsx(l.Fragment,{children:l.jsx(t,{})})}function v1(){const e=Dt(),{offset:t,mouse:r,item:n,isDragging:s}=g0(o=>({offset:o.getSourceClientOffset(),mouse:o.getClientOffset(),item:o.getItem(),isDragging:o.isDragging()})),i=e.props.renderDragPreview||md;return l.jsx(i,{offset:t,mouse:r,id:(n==null?void 0:n.id)||null,dragIds:(n==null?void 0:n.dragIds)||[],isDragging:s})}function m1(e={}){var t,r;const n=(t=e.idAccessor)!==null&&t!==void 0?t:"id",s=(r=e.childrenAccessor)!==null&&r!==void 0?r:"children";return{getId:typeof n=="function"?n:i=>i[n],getChildren:typeof s=="function"?s:i=>i[s],childrenKey:typeof s=="string"?s:"children"}}class b1{constructor(t,r={}){this.accessors=m1(r),this.root=_1(t,this.accessors)}get data(){var t,r;return(r=(t=this.root.children)===null||t===void 0?void 0:t.map(n=>n.data))!==null&&r!==void 0?r:[]}create(t){const r=t.parentId?this.find(t.parentId):this.root;if(!r)return null;r.addChild(t.data,t.index)}move(t){const r=this.find(t.id),n=t.parentId?this.find(t.parentId):this.root;!r||!n||(n.addChild(r.data,t.index),r.drop())}update(t){const r=this.find(t.id);r&&r.update(t.changes)}drop(t){const r=this.find(t.id);r&&r.drop()}find(t,r=this.root){if(!r)return null;if(r.id===t)return r;if(r.children){for(let n of r.children){const s=this.find(t,n);if(s)return s}return null}return null}}function _1(e,t){const r=new zf({},null,t,"ROOT");return r.children=e.map(n=>Xa(n,r,t)),r}function Xa(e,t,r){const n=new zf(e,t,r),s=r.getChildren(e);return s&&(n.children=s.map(i=>Xa(i,n,r))),n}class zf{constructor(t,r,n,s){this.data=t,this.parent=r,this.accessors=n,this.id=s??n.getId(t)}hasParent(){return!!this.parent}get childIndex(){return this.hasParent()?this.parent.children.indexOf(this):-1}addChild(t,r){var n,s;const i=Xa(t,this,this.accessors);this.children=(n=this.children)!==null&&n!==void 0?n:[],this.children.splice(r,0,i);const o=this.accessors.childrenKey,a=this.data;a[o]=(s=a[o])!==null&&s!==void 0?s:[],a[o].splice(r,0,t)}removeChild(t){var r,n;(r=this.children)===null||r===void 0||r.splice(t,1),(n=this.data[this.accessors.childrenKey])===null||n===void 0||n.splice(t,1)}update(t){if(this.hasParent()){const r=this.childIndex;this.parent.addChild(Object.assign(Object.assign({},this.data),t),r),this.drop()}}drop(){this.hasParent()&&this.parent.removeChild(this.childIndex)}}let w1=0;function S1(e,t={}){const[r,n]=h.useState(e),s=t.idAccessor,i=t.childrenAccessor,o=h.useMemo(()=>new b1(r,{idAccessor:s,childrenAccessor:i}),[r,s,i]),a=_=>{for(const p of _.dragIds)o.move({id:p,parentId:_.parentId,index:_.index});n(o.data)},c=({name:_,id:p})=>{o.update({id:p,changes:{name:_}}),n(o.data)},d=typeof s=="string"?s:"id",u=typeof i=="string"?i:"children";return[r,{onMove:a,onRename:c,onCreate:({parentId:_,index:p,type:v})=>{if(typeof s=="function")throw new Error("React Arborist => initialData can't create nodes when idAccessor is a function: the generated id can't be written under a key the accessor reads. Use a string idAccessor, or the controlled `data` prop with your own onCreate.");if(v==="internal"&&typeof i=="function")throw new Error("React Arborist => initialData can't create folder nodes when childrenAccessor is a function: the new children array can't be written under a key the accessor reads. Use a string childrenAccessor, or the controlled `data` prop with your own onCreate.");const m={[d]:`simple-tree-id-${w1++}`,name:""};return v==="internal"&&(m[u]=[]),o.create({parentId:_,index:p,data:m}),n(o.data),m},onDelete:_=>{_.ids.forEach(p=>o.drop({id:p})),n(o.data)}}]}function C1(e){if(e.initialData&&e.data)throw new Error("React Arborist Tree => Provide either a data or initialData prop, but not both.");if(e.initialData&&(e.onCreate||e.onDelete||e.onMove||e.onRename))throw new Error(`React Arborist Tree => You passed the initialData prop along with a data handler.
466
- Use the data prop if you want to provide your own handlers.`);if(e.initialData){const[t,r]=S1(e.initialData,{idAccessor:e.idAccessor,childrenAccessor:e.childrenAccessor});return Object.assign(Object.assign(Object.assign({},e),r),{data:t})}else return e}function E1(e,t){const r=C1(e);return l.jsxs(h1,{treeProps:r,imperativeHandle:t,children:[l.jsx(g1,{children:l.jsx(y1,{})}),l.jsx(v1,{})]})}const O1=h.forwardRef(E1);function Za(){return xe(e=>{var n;const t=e.treeData[0];return(((n=t==null?void 0:t.metadata)==null?void 0:n.status)??(t==null?void 0:t.status)??"Draft").toLowerCase()==="draft"})}function I1(){return xe(e=>{var s;if(!e.selectedNodeId)return!1;const t=(s=e.treeData[0])==null?void 0:s.id,r=i=>{var o;for(const a of i){if(a.id===e.selectedNodeId)return a;if((o=a.children)!=null&&o.length){const c=r(a.children);if(c)return c}}},n=r(e.treeData);return!!(n!=null&&n.isFolder)&&n.id!==t})}const Vf={video:"#EA580C",pdf:"#DC2626",h5p:"#0D9488",scorm:"#7C3AED",audio:"#DB2777",quiz:"#16A34A",default:"#6B7280"},qf={video:"Video",pdf:"FileText",h5p:"Layers",scorm:"Package",audio:"Music",quiz:"HelpCircle",default:"File"},Hf=["Course Assessment","eTextbook","Exam Question","Explanation Content","Learning Resource","Practice Question Set","SCORM Content","Teacher Resource"],D1=[{label:"All",value:"all"},{label:"Course Assessment",value:"Course Assessment"},{label:"eTextbook",value:"eTextbook"},{label:"Exam Question",value:"Exam Question"},{label:"Explanation Content",value:"Explanation Content"},{label:"Learning Resource",value:"Learning Resource"},{label:"Practice Question Set",value:"Practice Question Set"},{label:"SCORM Content",value:"SCORM Content"},{label:"Teacher Resource",value:"Teacher Resource"}];function T1(e){const t=[e.mimeType??"",e.primaryCategory??"",e.contentType??""].join(" ").toLowerCase();return t.includes("video")?"video":t.includes("pdf")||t.includes("epub")?"pdf":t.includes("h5p")?"h5p":t.includes("scorm")?"scorm":t.includes("audio")||t.includes("mp3")?"audio":t.includes("quiz")||t.includes("question")||t.includes("ecml")?"quiz":"default"}function Yi(e){const t=T1(e);return{key:t,color:Vf[t]??Vf.default,bgClass:`sbx-ct-sq--${t}`,badgeClass:`sbx-ct-badge--${t}`,tintClass:`sbx-ct-tint--${t}`,iconName:qf[t]??qf.default,label:t.charAt(0).toUpperCase()+t.slice(1)}}const Tt={row:"_row_i3qt2_1",grip:"_grip_i3qt2_16",menuBtn:"_menuBtn_i3qt2_19",selected:"_selected_i3qt2_23",title:"_title_i3qt2_28",dropTarget:"_dropTarget_i3qt2_33",toggle:"_toggle_i3qt2_50",ctIcon:"_ctIcon_i3qt2_65",folderIcon:"_folderIcon_i3qt2_77",renameInput:"_renameInput_i3qt2_92",dropHere:"_dropHere_i3qt2_101",menuWrap:"_menuWrap_i3qt2_111",menu:"_menu_i3qt2_19",dangerItem:"_dangerItem_i3qt2_163"},N1={video:Ro,pdf:Ho,h5p:Wo,scorm:Ko,audio:Qo,quiz:Vo,default:mn},k1=({node:e,style:t,dragHandle:r,editorMode:n})=>{const[s,i]=h.useState(!1),[o,a]=h.useState(!1),[c,d]=h.useState(e.data.name),u=h.useRef(null),f=n==="edit",g=Za(),y=Yi(e.data),_=N1[y.key]??mn,p=e.isSelected,v=e.level===0,m=e.data.isFolder??(e.children&&e.children.length>0),b=v?mv:m?Cv:_;h.useEffect(()=>{if(!s)return;const E=T=>{var x;(x=u.current)!=null&&x.contains(T.target)||i(!1)};return document.addEventListener("mousedown",E),()=>document.removeEventListener("mousedown",E)},[s]);const S=h.useCallback(()=>{c.trim()&&e.submit(c.trim()),a(!1)},[c,e]),w=h.useCallback(E=>{E.key==="Enter"&&S(),E.key==="Escape"&&(d(e.data.name),a(!1))},[S,e.data.name]);return l.jsxs("div",{className:[Tt.row,p?Tt.selected:"",e.state.isOver&&m?Tt.dropTarget:""].filter(Boolean).join(" "),style:t,onClick:()=>e.select(),"data-node-id":e.data.id,"data-droppable":m?"true":void 0,role:"treeitem","aria-selected":p,"aria-expanded":m?!e.isClosed:void 0,children:[f&&l.jsx("span",{ref:r,className:Tt.grip,"aria-hidden":"true",children:l.jsx(Wc,{size:14})}),l.jsx("button",{className:Tt.toggle,onClick:E=>{E.stopPropagation(),e.toggle()},"aria-label":e.isClosed?"Expand":"Collapse",style:{visibility:m?"visible":"hidden"},children:e.isClosed?l.jsx(zc,{size:14}):l.jsx(hs,{size:14})}),l.jsx("span",{className:`${Tt.ctIcon} ${v||m?Tt.folderIcon:y.bgClass}`,"aria-hidden":"true",children:l.jsx(b,{size:12})}),o?l.jsx("input",{className:Tt.renameInput,value:c,autoFocus:!0,onChange:E=>d(E.target.value),onBlur:S,onKeyDown:w,onClick:E=>E.stopPropagation()}):l.jsx("span",{className:Tt.title,title:e.data.name,onDoubleClick:()=>f&&a(!0),children:e.data.name.length>25?`${e.data.name.slice(0,25)}...`:e.data.name}),e.state.isOver&&m&&l.jsx("span",{className:Tt.dropHere,"aria-hidden":"true",children:"Drop here"}),f&&l.jsxs("div",{className:Tt.menuWrap,ref:u,children:[l.jsx("button",{className:Tt.menuBtn,onClick:E=>{E.stopPropagation(),i(T=>!T)},"aria-label":"Node options",children:l.jsx(qc,{size:14})}),s&&l.jsxs("div",{className:Tt.menu,role:"menu",children:[l.jsxs("button",{role:"menuitem",onClick:()=>{a(!0),i(!1)},children:[l.jsx(Nv,{size:13})," Rename"]}),m&&g&&l.jsxs("button",{role:"menuitem",onClick:()=>{e.tree.create({parentId:e.id}),i(!1)},children:[l.jsx(Hc,{size:13})," Add sub-unit"]}),e.data.parent&&g&&l.jsxs("button",{role:"menuitem",onClick:()=>{e.tree.create({parentId:e.data.parent}),i(!1)},children:[l.jsx(ps,{size:13})," Add Sibling"]}),l.jsxs("button",{role:"menuitem",className:Tt.dangerItem,onClick:()=>{e.tree.delete(e.id),i(!1)},children:[l.jsx(Yo,{size:13})," Delete"]})]})]})]})};async function x1(e,t){var i,o;const n=((i=(await Ae.post(`/action/content/v3/upload/url/${e}?type=hierarchy`,{request:{content:{fileName:t}}})).data)==null?void 0:i.result)??{},s=((o=n.content)==null?void 0:o.preSignedURL)??n.pre_signed_url??n.preSignedUrl;if(!s)throw new Error("Could not obtain an upload URL");return s}async function A1(e,t){const r=await fetch(e,{method:"PUT",headers:{"x-ms-blob-type":"BlockBlob","Content-Type":"text/csv"},body:t});if(!r.ok)throw new Error(`Blob upload failed (${r.status})`);return e.split("?")[0]}async function P1(e,t){var a;const r=await x1(e,t.name),n=await A1(r,t),s=new FormData;return s.append("fileUrl",n),s.append("mimeType",t.type||"text/csv"),{processId:(((a=(await Ae.post(`/action/collection/v1/import/${e}`,s)).data)==null?void 0:a.result)??{}).processId??""}}async function M1(e){var r;return((r=(await Ae.get(`/action/collection/v1/import/status/${e}`)).data)==null?void 0:r.result)??{status:"PENDING"}}async function Wf(e){var n,s,i;const r=(i=(s=(n=(await Ae.get(`/action/collection/v1/export/${e}`)).data)==null?void 0:n.result)==null?void 0:s.collection)==null?void 0:i.tocUrl;if(!r)throw new Error("No export URL returned");return r}async function L1(e){return Wf(e)}const Pe={container:"_container_jr3ij_1",header:"_header_jr3ij_13",title:"_title_jr3ij_22",closeBtn:"_closeBtn_jr3ij_29",body:"_body_jr3ij_45",dropZone:"_dropZone_jr3ij_54",dragOver:"_dragOver_jr3ij_67",hasFile:"_hasFile_jr3ij_72",hiddenInput:"_hiddenInput_jr3ij_78",fileInfo:"_fileInfo_jr3ij_82",fileIcon:"_fileIcon_jr3ij_89",fileName:"_fileName_jr3ij_93",fileSize:"_fileSize_jr3ij_100",dropHint:"_dropHint_jr3ij_105",dropIcon:"_dropIcon_jr3ij_112",dropText:"_dropText_jr3ij_117",dropSubtext:"_dropSubtext_jr3ij_124",sampleLink:"_sampleLink_jr3ij_130",statusBar:"_statusBar_jr3ij_145",status_uploading:"_status_uploading_jr3ij_154",status_processing:"_status_processing_jr3ij_154",status_done:"_status_done_jr3ij_159",status_error:"_status_error_jr3ij_164",successDetail:"_successDetail_jr3ij_170",spinner:"_spinner_jr3ij_175",spin:"_spin_jr3ij_175",errorMsg:"_errorMsg_jr3ij_191",failedSection:"_failedSection_jr3ij_197",failedTitle:"_failedTitle_jr3ij_203",tableWrap:"_tableWrap_jr3ij_213",failedTable:"_failedTable_jr3ij_219",reasonCell:"_reasonCell_jr3ij_244",footer:"_footer_jr3ij_248"},F1=({contentId:e,onComplete:t,onClose:r,mode:n="create"})=>{const[s,i]=h.useState(null),[o,a]=h.useState(!1),[c,d]=h.useState("idle"),[u,f]=h.useState(""),[g,y]=h.useState([]),[_,p]=h.useState(null),v=h.useRef(null),m=h.useRef(null),b=h.useCallback(()=>{m.current!==null&&(clearInterval(m.current),m.current=null)},[]);h.useEffect(()=>()=>b(),[b]);const S=N=>N.name.toLowerCase().endsWith(".csv")?N.size>50*1024*1024?(f("File size must not exceed 50 MB."),!1):!0:(f("Only .csv files are accepted."),!1),w=h.useCallback(N=>{f(""),y([]),p(null),d("idle"),S(N)&&i(N)},[]),E=h.useCallback(N=>{N.preventDefault(),a(!1);const M=N.dataTransfer.files[0];M&&w(M)},[w]),T=h.useCallback(N=>{var j;const M=(j=N.target.files)==null?void 0:j[0];M&&w(M),N.target.value=""},[w]),x=h.useCallback(async()=>{try{const N=await L1(e),M=document.createElement("a");M.href=N,M.download="sample_hierarchy.csv",M.target="_blank",M.click()}catch{f("Failed to download sample CSV.")}},[e]),P=h.useCallback(async()=>{if(s){d("uploading"),f(""),y([]);try{const{processId:N}=await P1(e,s);if(!N){d("done"),p(null),setTimeout(t,1500);return}d("processing"),m.current=setInterval(async()=>{try{const M=await M1(N);M.status==="COMPLETED"?(b(),d("done"),p(M.successCount??null),M.failedRecords&&M.failedRecords.length>0?y(M.failedRecords):setTimeout(t,1500)):M.status==="FAILED"&&(b(),d("error"),f("Upload processing failed. Please check the error rows below."),M.failedRecords&&y(M.failedRecords))}catch{b(),d("error"),f("Lost connection while checking status. Please try again.")}},2e3)}catch{d("error"),f("Upload failed. Please check your file and try again.")}}},[e,s,t,b]),F={idle:"",uploading:"Uploading...",processing:"Processing...",done:"Done!",error:"Error"};return l.jsxs("div",{className:Pe.container,children:[l.jsxs("div",{className:Pe.header,children:[l.jsx("h2",{className:Pe.title,children:n==="update"?"Update Folder Metadata via CSV":"Create Folders via CSV"}),l.jsx("button",{className:Pe.closeBtn,onClick:r,"aria-label":"Close",children:"✕"})]}),l.jsxs("div",{className:Pe.body,children:[l.jsxs("div",{className:`${Pe.dropZone} ${o?Pe.dragOver:""} ${s?Pe.hasFile:""}`,onDragEnter:N=>{N.preventDefault(),a(!0)},onDragOver:N=>{N.preventDefault(),a(!0)},onDragLeave:N=>{N.preventDefault(),a(!1)},onDrop:E,onClick:()=>{var N;return(N=v.current)==null?void 0:N.click()},role:"button",tabIndex:0,"aria-label":"Drop CSV file here or click to browse",onKeyDown:N=>{var M;return N.key==="Enter"&&((M=v.current)==null?void 0:M.click())},children:[l.jsx("input",{ref:v,type:"file",accept:".csv",className:Pe.hiddenInput,onChange:T,"aria-hidden":"true"}),s?l.jsxs("div",{className:Pe.fileInfo,children:[l.jsx("span",{className:Pe.fileIcon,children:"📄"}),l.jsx("span",{className:Pe.fileName,children:s.name}),l.jsxs("span",{className:Pe.fileSize,children:["(",(s.size/1024).toFixed(1)," KB)"]})]}):l.jsxs("div",{className:Pe.dropHint,children:[l.jsx("span",{className:Pe.dropIcon,children:"⬆️"}),l.jsx("p",{className:Pe.dropText,children:"Drag & drop your CSV here"}),l.jsx("p",{className:Pe.dropSubtext,children:"or click to browse"})]})]}),l.jsx("button",{className:Pe.sampleLink,onClick:x,type:"button",children:"Download Sample CSV"}),c!=="idle"&&l.jsxs("div",{className:`${Pe.statusBar} ${Pe[`status_${c}`]}`,role:"status","aria-live":"polite",children:[c==="processing"&&l.jsx("span",{className:Pe.spinner,"aria-hidden":"true"}),F[c],c==="done"&&_!==null&&l.jsxs("span",{className:Pe.successDetail,children:[" — ",_," item(s) imported"]})]}),u&&l.jsx("p",{className:Pe.errorMsg,role:"alert",children:u}),g.length>0&&l.jsxs("div",{className:Pe.failedSection,children:[l.jsxs("h4",{className:Pe.failedTitle,children:["Failed Rows (",g.length,")"]}),l.jsx("div",{className:Pe.tableWrap,children:l.jsxs("table",{className:Pe.failedTable,children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{children:"Row"}),l.jsx("th",{children:"Name"}),l.jsx("th",{children:"Reason"})]})}),l.jsx("tbody",{children:g.map((N,M)=>l.jsxs("tr",{children:[l.jsx("td",{children:N.rowNumber??M+1}),l.jsx("td",{children:N.name??"—"}),l.jsx("td",{className:Pe.reasonCell,children:N.reason??"Unknown error"})]},M))})]})})]})]}),l.jsxs("div",{className:Pe.footer,children:[l.jsx(Le,{variant:"ghost",onClick:r,disabled:c==="uploading"||c==="processing",children:"Cancel"}),l.jsx(Le,{variant:"primary",isLoading:c==="uploading"||c==="processing",disabled:!s||c==="done",onClick:P,children:c==="done"?"Uploaded":"Upload"})]})]})},rr={container:"_container_1y30m_1",header:"_header_1y30m_8",headerActions:"_headerActions_1y30m_19",iconBtn:"_iconBtn_1y30m_25",menuWrap:"_menuWrap_1y30m_43",dropdownMenu:"_dropdownMenu_1y30m_47",treeWrapper:"_treeWrapper_1y30m_79",csvModal:"_csvModal_1y30m_95",footer:"_footer_1y30m_105"},$1=({editorMode:e,collapsed:t=!1,onToggleCollapse:r})=>{var ce;const n=h.useRef(null),s=h.useRef(null),i=h.useRef(null),[o,a]=h.useState(400),[c,d]=h.useState(!1),[u,f]=h.useState(!1),[g,y]=h.useState("create"),{treeData:_,selectedNodeId:p,selectNode:v,addNode:m,deleteNode:b,reorderChildren:S,moveNode:w,setTreeData:E}=xe(),T=e==="edit",x=Za(),P=T&&x,F=(((ce=_[0])==null?void 0:ce.children)??[]).some(Q=>Q.isFolder),N=ae(Q=>{var J,ie,B,R;return((ie=(J=Q.editorConfig)==null?void 0:J.context)==null?void 0:ie.contentId)??((R=(B=Q.editorConfig)==null?void 0:B.context)==null?void 0:R.identifier)??""}),M=ae(Q=>{var ie,B;const J=(B=(ie=Q.categoryMeta)==null?void 0:ie.sourcingSettings)==null?void 0:B.collection;return(J==null?void 0:J.enableBulkUpload)!==!1});h.useEffect(()=>{const Q=s.current;if(!Q)return;const J=new ResizeObserver(()=>{a(Q.clientHeight||400)});return J.observe(Q),a(Q.clientHeight||400),()=>J.disconnect()},[]),h.useEffect(()=>{if(!c)return;const Q=J=>{var ie;(ie=i.current)!=null&&ie.contains(J.target)||d(!1)};return document.addEventListener("mousedown",Q),()=>document.removeEventListener("mousedown",Q)},[c]);const j=h.useCallback(Q=>{Q.length>0&&v(Q[0].data.id)},[v]),A=h.useCallback(({parentId:Q,index:J,dragIds:ie})=>{if(!Q)return;const B=ie[0],R=Ja(_,B);if(!R)return;const K=R.parent;if(K===Q){const de=Ja(_,Q);if(!(de!=null&&de.children))return;const Oe=de.children.findIndex(Be=>Be.id===B);if(Oe<0)return;S(Q,Oe,J>Oe?J-1:J)}else w(B,K??"",Q)},[_,S,w]),$=h.useCallback(({ids:Q})=>{Q.forEach(J=>b(J))},[b]),U=h.useCallback(({parentId:Q})=>{var B;const J=Q??((B=_[0])==null?void 0:B.id)??"";if(!J)return{id:crypto.randomUUID()};const ie=m(J,"unit");return ie?{id:ie}:(Ie.error("Maximum depth reached"),{id:crypto.randomUUID()})},[m,_]),Z=h.useCallback(()=>{var J;const Q=(J=_[0])==null?void 0:J.id;Q&&(m(Q,"unit")||Ie.error("Maximum depth reached"))},[_,m]),se=h.useCallback(()=>{p&&(m(p,"subunit")||Ie.error("Maximum depth reached"))},[p,m]),be=h.useCallback(async()=>{if(d(!1),!!N)try{const Q=await Wf(N),J=await fetch(Q).then(R=>R.blob()),ie=URL.createObjectURL(J),B=document.createElement("a");B.href=ie,B.download=`${N}-folders.csv`,B.style.display="none",document.body.appendChild(B),B.click(),document.body.removeChild(B),URL.revokeObjectURL(ie)}catch{Ie.error("Failed to download CSV")}},[N]),Ee=h.useCallback(async()=>{if(f(!1),!!N)try{const{rootNode:Q}=await Zu(N);E([Q]),Ie.success("Course outline refreshed.")}catch{Ie.error("Outline could not be refreshed automatically. Please reload the page.")}},[N,E]);return l.jsxs("div",{className:rr.container,children:[l.jsx("div",{className:rr.header,children:l.jsxs("div",{className:rr.headerActions,children:[T&&l.jsxs("div",{className:rr.menuWrap,ref:i,children:[l.jsx("button",{type:"button",className:rr.iconBtn,onClick:()=>d(Q=>!Q),"aria-label":"More options",title:"More options","aria-haspopup":"true","aria-expanded":c,children:l.jsx(qc,{size:15})}),c&&l.jsx("div",{className:rr.dropdownMenu,role:"menu",children:M&&l.jsxs(l.Fragment,{children:[l.jsx("button",{role:"menuitem",type:"button",disabled:F,title:F?'Folders already exist — use "Update" instead':void 0,onClick:()=>{d(!1),y("create"),f(!0)},children:"Create folders using csv file"}),l.jsx("button",{role:"menuitem",type:"button",disabled:!F,title:F?void 0:'No folders yet — use "Create" first',onClick:be,children:"Download folders as csv file"}),l.jsx("button",{role:"menuitem",type:"button",disabled:!F,title:F?void 0:'No folders yet — use "Create" first',onClick:()=>{d(!1),y("update"),f(!0)},children:"Update folder metadata using csv file"})]})})]}),r&&l.jsx("button",{type:"button",className:rr.iconBtn,onClick:r,"aria-label":t?"Expand outline":"Collapse outline",title:t?"Expand outline":"Collapse outline",children:t?l.jsx(Dv,{size:15}):l.jsx(Iv,{size:15})})]})}),l.jsx("div",{className:rr.treeWrapper,ref:s,children:l.jsx(O1,{ref:n,data:_,idAccessor:"id",childrenAccessor:"children",onSelect:j,onMove:T?A:void 0,onDelete:T?$:void 0,onCreate:T?U:void 0,disableEdit:!T,disableDrop:!T,selection:p??void 0,rowHeight:40,indent:20,paddingBottom:16,height:o,width:"100%",children:Q=>l.jsx(k1,{...Q,editorMode:e})})}),T&&l.jsxs("div",{className:rr.footer,children:[l.jsxs(Le,{variant:"ghost",size:"sm",onClick:Z,disabled:!P,children:[l.jsx(ps,{size:14})," Add Unit"]}),l.jsxs(Le,{variant:"ghost",size:"sm",onClick:se,disabled:!P||!p,children:[l.jsx(Hc,{size:14})," Add Sub-unit"]})]}),u&&l.jsx("div",{className:rr.csvModal,children:l.jsx(F1,{contentId:N,mode:g,onComplete:Ee,onClose:()=>f(!1)})})]})};function Ja(e,t){for(const r of e){if(r.id===t)return r;if(r.children){const n=Ja(r.children,t);if(n)return n}}}const Ds={breadcrumb:"_breadcrumb_zd1aj_1",crumb:"_crumb_zd1aj_10",sep:"_sep_zd1aj_26",current:"_current_zd1aj_31"},j1=({crumbs:e})=>{const t=xe(r=>r.selectNode);return e.length?l.jsxs("nav",{className:Ds.breadcrumb,"aria-label":"Node path",children:[l.jsx("button",{className:Ds.crumb,onClick:()=>t(e[0].id),"aria-label":"Home",children:l.jsx(Ev,{size:13})}),e.map((r,n)=>l.jsxs(h.Fragment,{children:[l.jsx(zc,{size:13,className:Ds.sep}),n<e.length-1?l.jsx("button",{className:Ds.crumb,onClick:()=>t(r.id),children:r.name}):l.jsx("span",{className:Ds.current,children:r.name})]},r.id))]}):null},Ts={tabBar:"_tabBar_qhks1_1",tab:"_tab_qhks1_1",active:"_active_qhks1_29",error:"_error_qhks1_35",errorDot:"_errorDot_qhks1_39"},Qf=[{id:"details",label:"Details"},{id:"audience",label:"Audience & Curriculum"},{id:"licensing",label:"Licensing"}],B1=({activeTab:e,onChange:t,errorTabs:r=[],visibleTabs:n})=>{const s=n?Qf.filter(i=>n.includes(i.id)):Qf;return l.jsx("div",{className:Ts.tabBar,role:"tablist","aria-label":"Metadata sections",children:s.map(i=>l.jsxs("button",{role:"tab","aria-selected":e===i.id,"aria-controls":`panel-${i.id}`,className:[Ts.tab,e===i.id?Ts.active:"",r.includes(i.id)?Ts.error:""].join(" "),onClick:()=>t(i.id),children:[i.label,r.includes(i.id)&&l.jsx("span",{className:Ts.errorDot,"aria-label":"Has errors"})]},i.id))})};var Ns=e=>e.type==="checkbox",Rr=e=>e instanceof Date,ut=e=>e==null;const Kf=e=>typeof e=="object";var He=e=>!ut(e)&&!Array.isArray(e)&&Kf(e)&&!Rr(e),el=e=>He(e)&&e.target?Ns(e.target)?e.target.checked:e.target.value:e,Gf=(e,t)=>t.split(".").some((r,n,s)=>!isNaN(Number(r))&&e.has(s.slice(0,n).join("."))),Yf=e=>{const t=e.constructor&&e.constructor.prototype;return He(t)&&t.hasOwnProperty("isPrototypeOf")},Ri=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function Ge(e){if(e instanceof Date)return new Date(e);const t=typeof FileList<"u"&&e instanceof FileList;if(Ri&&(e instanceof Blob||t))return e;const r=Array.isArray(e);if(!r&&!(He(e)&&Yf(e)))return e;const n=r?[]:Object.create(Object.getPrototypeOf(e));for(const s in e)Object.prototype.hasOwnProperty.call(e,s)&&(n[s]=Ge(e[s]));return n}const Tr={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change",SUBMIT:"submit",TRIGGER:"trigger",VALID:"valid"},Gt={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},Yt={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"},tl="form",Rf="root",Xf=["__proto__","constructor","prototype"];var ks=e=>/^\w*$/.test(e),Ue=e=>e===void 0,Xi=e=>e.split(/[.[\]'"]/g).filter(Boolean),W=(e,t,r)=>{if(!t||!He(e))return r;const n=ks(t)?[t]:Xi(t);if(n.some(i=>Xf.includes(i)))return r;const s=n.reduce((i,o)=>ut(i)?void 0:i[o],e);return Ue(s)||s===e?Ue(e[t])?r:e[t]:s},Pt=e=>typeof e=="boolean",mt=e=>typeof e=="function",je=(e,t,r)=>{let n=-1;const s=ks(t)?[t]:Xi(t),i=s.length,o=i-1;for(;++n<i;){const a=s[n];let c=r;if(n!==o){const d=e[a];c=He(d)||Array.isArray(d)?d:isNaN(+s[n+1])?{}:[]}if(Xf.includes(a))return;e[a]=c,e=e[a]}};const rl=h.createContext(null);rl.displayName="HookFormControlContext";const nl=()=>h.useContext(rl);var Zf=(e,t,r,n=!0)=>{const s={};for(const i in e)Object.defineProperty(s,i,{get:()=>{const o=i;return t._proxyFormState[o]!==Gt.all&&(t._proxyFormState[o]=!n||Gt.all),r&&(r[o]=!0),e[o]}});return s};const sl=Ri?h.useLayoutEffect:h.useEffect;function U1(e){const t=nl(),{control:r=t,disabled:n,name:s,exact:i}=e||{},[o,a]=h.useState(()=>({...r._formState,defaultValues:r._defaultValues})),c=h.useRef({isDirty:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,validatingFields:!1,isValidating:!1,isValid:!1,errors:!1});return sl(()=>r._subscribe({name:s,formState:c.current,exact:i,callback:d=>{!n&&a({...r._formState,...d,defaultValues:r._defaultValues})}}),[s,n,i]),h.useEffect(()=>{c.current.isValid&&r._setValid(!0)},[r]),h.useMemo(()=>Zf(o,r,c.current,!1),[o,r])}var bt=e=>typeof e=="string",il=(e,t,r,n,s)=>bt(e)?(n&&t.watch.add(e),W(r,e,s)):Array.isArray(e)?e.map(i=>(n&&t.watch.add(i),W(r,i))):(n&&(t.watchAll=!0),r),ol=e=>ut(e)||!Kf(e);const Jf=(e,t)=>t.length===0&&!Array.isArray(e)&&!Yf(e);function Mt(e,t,r=new WeakMap){if(e===t)return!0;if(ol(e)||ol(t))return Object.is(e,t);if(Rr(e)&&Rr(t))return Object.is(e.getTime(),t.getTime());const n=Object.keys(e),s=Object.keys(t);if(n.length!==s.length)return!1;if(Jf(e,n)||Jf(t,s))return Object.is(e,t);const i=r.get(e);if(i&&i.has(t))return!0;i?i.add(t):r.set(e,new WeakSet([t]));for(const o of n){const a=e[o];if(!(o in t))return!1;if(o!=="ref"){const c=t[o];if(Rr(a)&&Rr(c)||(He(a)||Array.isArray(a))&&(He(c)||Array.isArray(c))?!Mt(a,c,r):!Object.is(a,c))return!1}}return!0}function z1(e){const t=nl(),{control:r=t,name:n,defaultValue:s,disabled:i,exact:o,compute:a}=e||{},c=h.useRef(s),d=h.useRef(a),u=h.useRef(void 0),f=h.useRef(r),g=h.useRef(n);d.current=a;const[y,_]=h.useState(()=>{const w=r._getWatch(n,c.current);return d.current?d.current(w):w}),p=h.useCallback(w=>{const E=il(n,r._names,w||r._formValues,!1,c.current);return d.current?d.current(E):E},[r._formValues,r._names,n]),v=h.useCallback(w=>{if(!i){const E=il(n,r._names,w||r._formValues,!1,c.current);if(d.current){const T=d.current(E);Mt(T,u.current)||(_(T),u.current=T)}else _(E)}},[r._formValues,r._names,i,n]);sl(()=>((f.current!==r||!Mt(g.current,n))&&(f.current=r,g.current=n,v()),r._subscribe({name:n,formState:{values:!0},exact:o,callback:w=>{v(w.values)}})),[r,o,n,v]),h.useEffect(()=>r._removeUnmounted());const m=f.current!==r,b=g.current,S=h.useMemo(()=>{if(i)return null;const w=!m&&!Mt(b,n);return m||w?p():null},[i,m,n,b,p]);return S!==null?S:y}function Zi(e){const t=nl(),{name:r,disabled:n,control:s=t,shouldUnregister:i,defaultValue:o,exact:a=!0}=e,c=Gf(s._names.array,r),d=h.useMemo(()=>W(s._formValues,r,W(s._defaultValues,r,o)),[s,r,o]),u=z1({control:s,name:r,defaultValue:d,exact:a}),f=U1({control:s,name:r,exact:a}),g=h.useRef(e),y=h.useRef(null),_=h.useRef(s.register(r,{...e.rules,value:u,...Pt(e.disabled)?{disabled:e.disabled}:{}}));g.current=e;const p=h.useMemo(()=>Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!W(f.errors,r)},isDirty:{enumerable:!0,get:()=>!!W(f.dirtyFields,r)},isTouched:{enumerable:!0,get:()=>!!W(f.touchedFields,r)},isValidating:{enumerable:!0,get:()=>!!W(f.validatingFields,r)},error:{enumerable:!0,get:()=>W(f.errors,r)}}),[f,r]),v=h.useCallback(w=>{const E=el(w);return W(s._fields,r)||(_.current=s.register(r,{...g.current.rules,value:E})),_.current.onChange({target:{value:el(w),name:r},type:Tr.CHANGE})},[r,s]),m=h.useCallback(()=>_.current.onBlur({target:{value:W(s._formValues,r),name:r},type:Tr.BLUR}),[r,s._formValues]),b=h.useCallback(w=>{w&&(y.current={focus:()=>mt(w.focus)&&w.focus(),select:()=>mt(w.select)&&w.select(),setCustomValidity:T=>mt(w.setCustomValidity)&&w.setCustomValidity(T),reportValidity:()=>mt(w.reportValidity)&&w.reportValidity()});const E=W(s._fields,r);E&&E._f&&w&&(E._f.ref=y.current)},[s._fields,r]),S=h.useMemo(()=>({name:r,value:u,...Pt(n)||f.disabled?{disabled:f.disabled||n}:{},onChange:v,onBlur:m,ref:b}),[r,n,f.disabled,v,m,b,u]);return h.useEffect(()=>{const w=s._options.shouldUnregister||i;s.register(r,{...g.current.rules,...Pt(g.current.disabled)?{disabled:g.current.disabled}:{}});const E=(T,x)=>{const P=W(s._fields,T);P&&P._f&&(P._f.mount=x)};if(E(r,!0),w){const T=Ge(W(i?s._defaultValues:s._options.values||s._defaultValues,r,W(s._options.defaultValues,r,g.current.defaultValue)));je(s._defaultValues,r,T),Ue(W(s._formValues,r))&&je(s._formValues,r,T)}if(!c&&s.register(r),y.current){const T=W(s._fields,r);T&&T._f&&(T._f.ref=y.current)}return()=>{(c?w&&!s._state.action:w)?s.unregister(r):E(r,!1)}},[r,s,c,i]),h.useEffect(()=>{s._setDisabledField({disabled:n,name:r})},[n,r,s]),h.useMemo(()=>({field:S,formState:f,fieldState:p}),[S,f,p])}const al=h.createContext(null);al.displayName="HookFormContext";const Rt=()=>h.useContext(al),V1=({children:e,watch:t,getValues:r,getFieldState:n,setError:s,clearErrors:i,setValue:o,setValues:a,trigger:c,formState:d,resetField:u,reset:f,handleSubmit:g,unregister:y,control:_,register:p,setFocus:v,subscribe:m})=>{const b=h.useMemo(()=>({watch:t,getValues:r,getFieldState:n,setError:s,clearErrors:i,setValue:o,setValues:a,trigger:c,formState:d,resetField:u,reset:f,handleSubmit:g,unregister:y,control:_,register:p,setFocus:v,subscribe:m}),[i,_,d,n,r,g,p,f,u,s,v,o,a,m,c,y,t]);return h.createElement(al.Provider,{value:b},h.createElement(rl.Provider,{value:b.control},e))};var q1=(e,t,r,n,s)=>t?{...r[e],types:{...r[e]&&r[e].types?r[e].types:{},[n]:s||!0}}:{},eh=e=>Array.isArray(e)?e.filter(Boolean):[],Ji=e=>Array.isArray(e)?e:[e],th=()=>{let e=[];return{get observers(){return e},next:s=>{for(const i of e)i.next&&i.next(s)},subscribe:s=>(e.push(s),{unsubscribe:()=>{e=e.filter(i=>i!==s)}}),unsubscribe:()=>{e=[]}}};function rh(e,t){const r={};for(const n in e)if(e.hasOwnProperty(n)){const s=e[n],i=t[n];if(s&&He(s)&&i){const o=rh(s,i);He(o)&&(r[n]=o)}else e[n]&&(r[n]=i)}return r}var nt=e=>He(e)&&!Object.keys(e).length,ll=e=>e.type==="file",eo=e=>{if(!Ri)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},nh=e=>e.type==="select-multiple",cl=e=>e.type==="radio",H1=e=>cl(e)||Ns(e),ul=e=>eo(e)&&e.isConnected;function W1(e,t){const r=t.slice(0,-1).length;let n=0;for(;n<r;){if(ut(e)){e=void 0;break}e=e[t[n]],n++}return e}function Q1(e){for(const t in e)if(e.hasOwnProperty(t)&&!Ue(e[t]))return!1;return!0}function Ze(e,t){if(bt(t)&&Object.prototype.hasOwnProperty.call(e,t))return delete e[t],e;const r=Array.isArray(t)?t:ks(t)?[t]:Xi(t),n=r.length===1?e:W1(e,r),s=r.length-1,i=r[s];return n&&delete n[i],s!==0&&(He(n)&&nt(n)||Array.isArray(n)&&Q1(n))&&Ze(e,r.slice(0,-1)),e}var K1=e=>{for(const t in e)if(mt(e[t]))return!0;return!1};function sh(e){return Array.isArray(e)||He(e)&&!K1(e)}function dl(e,t={}){for(const r in e){const n=e[r];sh(n)?(t[r]=Array.isArray(n)?[]:{},dl(n,t[r])):Ue(n)||(t[r]=!0)}return t}function fl(e){if(e!==!1){if(e===!0)return!0;if(Array.isArray(e)){const t=e.map(r=>fl(r));return t.some(r=>r!==void 0)?t:void 0}if(He(e)){const t={};for(const r in e){const n=fl(e[r]);Ue(n)||(t[r]=n)}return Object.keys(t).length?t:void 0}}}function Xr(e,t,r){r||(r=dl(t));for(const n in e){const s=e[n];if(sh(s))Ue(t)||ol(r[n])?r[n]=dl(s,Array.isArray(s)?[]:{}):Xr(s,ut(t)?{}:t[n],r[n]);else{const i=t[n];r[n]=!Mt(s,i)}}return fl(r)||{}}const ih={value:!1,isValid:!1},oh={value:!0,isValid:!0};var ah=e=>{if(Array.isArray(e)){if(e.length>1){const t=e.filter(r=>r&&r.checked&&!r.disabled).map(r=>r.value);return{value:t,isValid:!!t.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!Ue(e[0].attributes.value)?Ue(e[0].value)||e[0].value===""?oh:{value:e[0].value,isValid:!0}:oh:ih}return ih},lh=(e,{valueAsNumber:t,valueAsDate:r,setValueAs:n})=>Ue(e)?e:t?e===""?NaN:e&&+e:r&&bt(e)?new Date(e):n?n(e):e;const ch={isValid:!1,value:null};var uh=e=>Array.isArray(e)?e.reduce((t,r)=>r&&r.checked&&!r.disabled?{isValid:!0,value:r.value}:t,ch):ch;function dh(e){const t=e.ref;return ll(t)?t.files:cl(t)?uh(e.refs).value:nh(t)?[...t.selectedOptions].map(({value:r})=>r):Ns(t)?ah(e.refs).value:lh(Ue(t.value)?e.ref.value:t.value,e)}var G1=(e,t,r,n)=>{const s={};for(const i of e){const o=W(t,i);o&&je(s,i,o._f)}return{criteriaMode:r,names:[...e],fields:s,shouldUseNativeValidation:n}},to=e=>e instanceof RegExp,xs=e=>Ue(e)?e:to(e)?e.source:He(e)?to(e.value)?e.value.source:e.value:e,fh=e=>({isOnSubmit:!e||e===Gt.onSubmit,isOnBlur:e===Gt.onBlur,isOnChange:e===Gt.onChange,isOnAll:e===Gt.all,isOnTouch:e===Gt.onTouched});const hh="AsyncFunction";var Y1=e=>!!e&&!!e.validate&&!!(mt(e.validate)&&e.validate.constructor.name===hh||He(e.validate)&&Object.values(e.validate).find(t=>t.constructor.name===hh)),R1=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate),hl=(e,t,r)=>!r&&(t.watchAll||t.watch.has(e)||[...t.watch].some(n=>e.startsWith(`${n}.`)));const As=(e,t,r,n)=>{for(const s of r||Object.keys(e)){const i=W(e,s);if(i){const{_f:o,...a}=i;if(o){if(o.refs&&o.refs[0]&&t(o.refs[0],s)&&!n)return!0;if(o.ref&&t(o.ref,o.name)&&!n)return!0;if(As(a,t))break}else if(He(a)&&As(a,t))break}}};function ph(e,t,r){const n=W(e,r);if(n||ks(r))return{error:n,name:r};const s=r.split(".");for(;s.length;){const i=s.join("."),o=W(t,i),a=W(e,i);if(o&&!Array.isArray(o)&&r!==i)return{name:r};if(a&&a.type)return{name:i,error:a};if(a&&a.root&&a.root.type)return{name:`${i}.root`,error:a.root};s.pop()}return{name:r}}var X1=(e,t,r,n)=>{r(e);const{name:s,...i}=e;return nt(i)||n&&Object.keys(i).length>=Object.keys(t).length||Object.keys(i).find(o=>t[o]===(!n||Gt.all))},Z1=(e,t,r)=>!e||!t||e===t||Ji(e).some(n=>n&&(r?n===t:n.startsWith(t)||t.startsWith(n))),J1=(e,t,r,n,s)=>s.isOnAll?!1:!r&&s.isOnTouch?!(t||e):(r?n.isOnBlur:s.isOnBlur)?!e:(r?n.isOnChange:s.isOnChange)?e:!0,eE=(e,t)=>!eh(W(e,t)).length&&Ze(e,t),gh=(e,t,r)=>{const n=W(e,r),s=Array.isArray(n)?n:[];return je(s,Rf,t[r]),je(e,r,s),e};function yh(e,t,r="validate"){if(bt(e)||Array.isArray(e)&&e.every(bt)||Pt(e)&&!e)return{type:r,message:bt(e)?e:"",ref:t}}var Mn=e=>He(e)&&!to(e)?e:{value:e,message:""},vh=async(e,t,r,n,s,i)=>{const{ref:o,refs:a,required:c,maxLength:d,minLength:u,min:f,max:g,pattern:y,validate:_,name:p,valueAsNumber:v,mount:m}=e._f,b=W(r,p);if(!m||t.has(p))return{};const S=a?a[0]:o,w=j=>{if(s&&S.reportValidity){const A=Pt(j)?"":j||"";a?a.forEach($=>$.setCustomValidity(A)):S.setCustomValidity(A),S.reportValidity()}},E={},T=cl(o),x=Ns(o),P=T||x,F=(v||ll(o))&&Ue(o.value)&&Ue(b)||eo(o)&&o.value===""||b===""||Array.isArray(b)&&!b.length,N=q1.bind(null,p,n,E),M=(j,A,$,U=Yt.maxLength,Z=Yt.minLength)=>{const se=j?A:$;E[p]={type:j?U:Z,message:se,ref:o,...N(j?U:Z,se)}};if(i?!Array.isArray(b)||!b.length:c&&(!P&&(F||ut(b))||Pt(b)&&!b||x&&!ah(a).isValid||T&&!uh(a).isValid)){const{value:j,message:A}=bt(c)?{value:!!c,message:c}:Mn(c);if(j&&(E[p]={type:Yt.required,message:A,ref:S,...N(Yt.required,A)},!n))return w(A),E}if(!F&&(!ut(f)||!ut(g))){let j,A;const $=Mn(g),U=Mn(f);if(!ut(b)&&!isNaN(b)){const Z=o.valueAsNumber||b&&+b;ut($.value)||(j=Z>$.value),ut(U.value)||(A=Z<U.value)}else{const Z=o.valueAsDate||new Date(b),se=ce=>new Date(new Date().toDateString()+" "+ce),be=o.type=="time",Ee=o.type=="week";bt($.value)&&b&&(j=be?se(b)>se($.value):Ee?b>$.value:Z>new Date($.value)),bt(U.value)&&b&&(A=be?se(b)<se(U.value):Ee?b<U.value:Z<new Date(U.value))}if((j||A)&&(M(!!j,$.message,U.message,Yt.max,Yt.min),!n))return w(E[p].message),E}if((d||u)&&!F&&(bt(b)||i&&Array.isArray(b))){const j=Mn(d),A=Mn(u),$=!ut(j.value)&&b.length>+j.value,U=!ut(A.value)&&b.length<+A.value;if(($||U)&&(M($,j.message,A.message),!n))return w(E[p].message),E}if(y&&!F&&bt(b)){const{value:j,message:A}=Mn(y);if(to(j)&&!b.match(j)&&(E[p]={type:Yt.pattern,message:A,ref:o,...N(Yt.pattern,A)},!n))return w(A),E}if(_){if(mt(_)){const j=await _(b,r),A=yh(j,S);if(A&&(E[p]={...A,...N(Yt.validate,A.message)},!n))return w(A.message),E}else if(He(_)){let j={};for(const A in _){if(!nt(j)&&!n)break;const $=yh(await _[A](b,r),S,A);$&&(j={...$,...N(A,$.message)},w($.message),n&&(E[p]=j))}if(!nt(j)&&(E[p]={ref:S,...j},!n))return E}}return w(!0),E};const tE={mode:Gt.onSubmit,reValidateMode:Gt.onChange,shouldFocusError:!0},mh={submitCount:0,isDirty:!1,isReady:!1,isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{}};function rE(e={}){let t={...tE,...e},r={...Ge(mh),isLoading:mt(t.defaultValues),errors:t.errors||{},disabled:t.disabled||!1},n={},s=He(t.defaultValues)||He(t.values)?Ge(t.defaultValues||t.values)||{}:{},i=t.shouldUnregister?{}:Ge(s),o={action:!1,mount:!1,watch:!1,keepIsValid:!1},a={mount:new Set,disabled:new Set,unMount:new Set,array:new Set,watch:new Set,registerName:new Set},c,d=0;const u={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},f={...u};let g={...f};const y={array:th(),state:th()},_=t.criteriaMode===Gt.all,p=C=>D=>{clearTimeout(d),d=setTimeout(C,D)},v=async C=>{if(!o.keepIsValid&&!t.disabled&&(f.isValid||g.isValid||C)){let D;t.resolver?(D=nt((await N()).errors),m()):D=await A({fields:n,onlyCheckValid:!0,eventType:Tr.VALID}),D!==r.isValid&&y.state.next({isValid:D})}},m=(C,D)=>{!t.disabled&&(f.isValidating||f.validatingFields||g.isValidating||g.validatingFields)&&((C||Array.from(a.mount)).forEach(k=>{k&&(D?je(r.validatingFields,k,D):Ze(r.validatingFields,k))}),y.state.next({validatingFields:r.validatingFields,isValidating:!nt(r.validatingFields)}))},b=()=>{r.dirtyFields=Xr(s,i)},S=(C,D=[],k,z,V=!0,G=!0)=>{if(z&&k&&!t.disabled){if(o.action=!0,G&&Array.isArray(W(n,C))){const q=k(W(n,C),z.argA,z.argB);V&&je(n,C,q)}if(G&&Array.isArray(W(r.errors,C))){const q=k(W(r.errors,C),z.argA,z.argB);V&&je(r.errors,C,q),eE(r.errors,C)}if((f.touchedFields||g.touchedFields)&&G&&Array.isArray(W(r.touchedFields,C))){const q=k(W(r.touchedFields,C),z.argA,z.argB);V&&je(r.touchedFields,C,q)}(f.dirtyFields||g.dirtyFields)&&b(),y.state.next({name:C,isDirty:U(C,D),dirtyFields:r.dirtyFields,errors:r.errors,isValid:r.isValid})}else je(i,C,D)},w=(C,D)=>{je(r.errors,C,D),r.errors={...r.errors},y.state.next({errors:r.errors})},E=C=>{r.errors=C,y.state.next({errors:r.errors,isValid:!1})},T=C=>{const D=ks(C)?[C]:Xi(C);let k=i,z=s;for(let V=0;V<D.length-1;V++){const G=D[V];if(k=ut(k)?k:k[G],z=ut(z)?z:z[G],k===null&&z!==null)return!0}return!1},x=(C,D,k,z)=>{const V=W(n,C);if(V){if(T(C))return;const G=Ue(W(i,C)),q=W(i,C,Ue(k)?W(s,C):k);Ue(q)||z&&z.defaultChecked||D?je(i,C,D?q:dh(V._f)):be(C,q),o.mount&&!o.action&&(v(),G&&r.isDirty&&(f.isDirty||g.isDirty)&&(U()||(r.isDirty=!1,y.state.next({...r}))),e.shouldUnregister&&G&&!Ue(W(i,C))&&hl(C,a)&&(o.watch=!0))}},P=(C,D,k,z,V)=>{let G=!1,q=!1;const te={name:C};if(!t.disabled){if(!k||z){(f.isDirty||g.isDirty)&&(q=r.isDirty,r.isDirty=te.isDirty=U(),G=q!==te.isDirty);const me=Mt(W(s,C),D);q=!!W(r.dirtyFields,C),me!==r.isDirty?r.dirtyFields=Xr(s,i):me?Ze(r.dirtyFields,C):je(r.dirtyFields,C,!0),te.dirtyFields=r.dirtyFields,G=G||(f.dirtyFields||g.dirtyFields)&&q!==!me}if(k){const me=W(r.touchedFields,C);me||(je(r.touchedFields,C,k),te.touchedFields=r.touchedFields,G=G||(f.touchedFields||g.touchedFields)&&me!==k)}G&&V&&y.state.next(te)}return G?te:{}},F=(C,D,k,z)=>{const V=W(r.errors,C),G=(f.isValid||g.isValid)&&Pt(D)&&r.isValid!==D;if(t.delayError&&k?(c=p(()=>w(C,k)),c(t.delayError)):(clearTimeout(d),c=null,k?je(r.errors,C,k):Ze(r.errors,C),r.errors={...r.errors}),(k?!Mt(V,k):V)||!nt(z)||G){const q={...z,...G&&Pt(D)?{isValid:D}:{},errors:r.errors,name:C};r={...r,...q},y.state.next(q)}},N=async C=>(m(C,!0),await t.resolver(i,t.context,G1(C||a.mount,n,t.criteriaMode,t.shouldUseNativeValidation))),M=async C=>{const{errors:D}=await N(C);if(m(C),C){for(const k of C){const z=W(D,k);z?a.array.has(k)&&He(z)&&!Object.keys(z).some(V=>!Number.isNaN(Number(V)))?gh(r.errors,{[k]:z},k):je(r.errors,k,z):Ze(r.errors,k)}r.errors={...r.errors}}else r.errors=D;return D},j=async({name:C,eventType:D})=>{if(e.validate){const k=await e.validate({formValues:i,formState:r,name:C,eventType:D});if(He(k))for(const z in k){const V=k[z];V&&Be(`${tl}.${z}`,{message:bt(V.message)?V.message:"",type:V.type||Yt.validate})}else bt(k)||!k?Be(tl,{message:k||"",type:Yt.validate}):Oe(tl);return k}return!0},A=async({fields:C,onlyCheckValid:D,name:k,eventType:z,context:V={valid:!0,runRootValidation:!1}})=>{if(e.validate&&(V.runRootValidation=!0,!await j({name:k,eventType:z})&&(V.valid=!1,D)))return V.valid;for(const G in C){const q=C[G];if(q){const{_f:te,...me}=q;if(te){const Ke=a.array.has(te.name),kt=q._f&&Y1(q._f),xt=f.validatingFields||f.isValidating||g.validatingFields||g.isValidating;kt&&xt&&m([te.name],!0);const vr=await vh(q,a.disabled,i,_,t.shouldUseNativeValidation&&!D,Ke);if(kt&&xt&&m([te.name]),vr[te.name]&&(V.valid=!1,D)||(!D&&(W(vr,te.name)?Ke?gh(r.errors,vr,te.name):je(r.errors,te.name,vr[te.name]):Ze(r.errors,te.name)),e.shouldUseNativeValidation&&vr[te.name]))break}!nt(me)&&await A({context:V,onlyCheckValid:D,fields:me,name:G,eventType:z})}}return V.valid},$=()=>{for(const C of a.unMount){const D=W(n,C);D&&(D._f.refs?D._f.refs.every(k=>!ul(k)):!ul(D._f.ref))&&$e(C)}a.unMount=new Set},U=(C,D)=>!t.disabled&&(C&&D&&je(i,C,D),!Mt(K(),s)),Z=(C,D,k)=>il(C,a,{...o.mount?i:Ue(D)?s:bt(C)?{[C]:D}:D},k,D),se=C=>eh(W(o.mount?i:s,C,t.shouldUnregister?W(s,C,[]):[])),be=(C,D,k={},z=!1)=>{const V=W(n,C);let G=D;if(V){const q=V._f;q&&(!q.disabled&&je(i,C,lh(D,q)),G=eo(q.ref)&&ut(D)?"":D,nh(q.ref)?[...q.ref.options].forEach(te=>te.selected=G.includes(te.value)):q.refs?Ns(q.ref)?q.refs.forEach(te=>{(!te.defaultChecked||!te.disabled)&&(Array.isArray(G)?te.checked=!!G.find(me=>me===te.value):te.checked=G===te.value||!!G)}):q.refs.forEach(te=>te.checked=te.value===G):ll(q.ref)?q.ref.value="":(q.ref.value=G,q.ref.type||y.state.next({name:C,values:z?i:Ge(i)})))}(k.shouldDirty||k.shouldTouch)&&P(C,G,k.shouldTouch,k.shouldDirty,!0),k.shouldValidate&&R(C)},Ee=(C,D,k,z=!1)=>{for(const V in D){if(!D.hasOwnProperty(V))return;const G=D[V],q=C+"."+V,te=W(n,q);(a.array.has(C)||He(G)||te&&!te._f)&&!Rr(G)?Ee(q,G,k,z):be(q,G,k,z)}},ce=(C,D,k,z)=>{const V=W(n,C),G=a.array.has(C),q=z?D:Ge(D),te=W(i,C),me=Mt(te,q);if(me||je(i,C,q),G)y.array.next({name:C,values:z?i:Ge(i)}),(f.isDirty||f.dirtyFields||g.isDirty||g.dirtyFields)&&k.shouldDirty&&(b(),y.state.next({name:C,dirtyFields:r.dirtyFields,isDirty:U(C,q)}));else{const Ke=Array.isArray(q)&&!q.length||nt(q);!V||V._f||ut(q)||Ke?be(C,q,k,z):Ee(C,q,k,z)}if(!me){const Ke=hl(C,a),kt=z?i:Ge(i);y.state.next({...Ke&&r,name:o.mount||Ke?C:void 0,values:kt})}},Q=(C,D,k={})=>ce(C,D,k,!1),J=(C,D={})=>{const k=mt(C)?C(i):C;if(!Mt(i,k)){i={...i,...k};for(const z of a.mount)ce(z,W(k,z),D,!0);y.state.next({...r,name:void 0,type:void 0,values:i}),D.shouldValidate&&v()}},ie=async C=>{o.mount=!0;const D=C.target;let k=D.name,z=!0;const V=W(n,k),G=me=>{z=Number.isNaN(me)||Rr(me)&&isNaN(me.getTime())||Mt(me,W(i,k,me))},q=fh(t.mode),te=fh(t.reValidateMode);if(V){let me,Ke;const kt=D.type?dh(V._f):el(C),xt=C.type===Tr.BLUR||C.type===Tr.FOCUS_OUT,vr=!R1(V._f)&&!e.validate&&!t.resolver&&!W(r.errors,k)&&!V._f.deps||J1(xt,W(r.touchedFields,k),r.isSubmitted,te,q),qs=hl(k,a,xt);je(i,k,kt),xt?(!D||!D.readOnly)&&(V._f.onBlur&&V._f.onBlur(C),c&&c(0)):V._f.onChange&&V._f.onChange(C);const fn=P(k,kt,xt),at=!nt(fn)||qs;if(!xt&&y.state.next({name:k,type:C.type,values:Ge(i)}),vr)return(f.isValid||g.isValid)&&(t.mode==="onBlur"?xt&&v():xt||v()),at&&y.state.next({name:k,...qs?{}:fn});if(!t.resolver&&e.validate&&await j({name:k,eventType:C.type}),!xt&&qs&&y.state.next({...r}),t.resolver){const{errors:wt}=await N([k]);if(m([k]),G(kt),!z){!nt(fn)&&y.state.next(fn);return}const Et=ph(r.errors,n,k),Jt=ph(wt,n,Et.name||k);me=Jt.error,k=Jt.name,Ke=nt(wt)}else m([k],!0),me=(await vh(V,a.disabled,i,_,t.shouldUseNativeValidation))[k],m([k]),G(kt),z&&(me?Ke=!1:(f.isValid||g.isValid)&&(Ke=await A({fields:n,onlyCheckValid:!0,name:k,eventType:C.type})));z&&(V._f.deps&&(!Array.isArray(V._f.deps)||V._f.deps.length>0)&&R(V._f.deps),F(k,Ke,me,fn))}},B=(C,D)=>{if(W(r.errors,D)&&C.focus)return C.focus(),1},R=async(C,D={})=>{let k,z;const V=Ji(C);if(t.resolver){const G=await M(Ue(C)?C:V);k=nt(G),z=C?!V.some(q=>W(G,q)):k}else C?(z=(await Promise.all(V.map(async G=>{const q=W(n,G);return await A({fields:q&&q._f?{[G]:q}:q,eventType:Tr.TRIGGER})}))).every(Boolean),!(!z&&!r.isValid)&&v()):z=k=await A({fields:n,name:C,eventType:Tr.TRIGGER});return y.state.next({...!bt(C)||(f.isValid||g.isValid)&&k!==r.isValid?{}:{name:C},...t.resolver||!C?{isValid:k}:{},errors:r.errors}),D.shouldFocus&&!z&&As(n,B,C?V:a.mount),z},K=(C,D)=>{let k={...o.mount?i:s};return D&&(k=rh(D.dirtyFields?r.dirtyFields:r.touchedFields,k)),Ue(C)?k:bt(C)?W(k,C):C.map(z=>W(k,z))},de=(C,D)=>({invalid:!!W((D||r).errors,C),isDirty:!!W((D||r).dirtyFields,C),error:W((D||r).errors,C),isValidating:!!W(r.validatingFields,C),isTouched:!!W((D||r).touchedFields,C)}),Oe=C=>{const D=C?Ji(C):void 0;D==null||D.forEach(k=>Ze(r.errors,k)),D?D.forEach(k=>{y.state.next({name:k,errors:r.errors})}):y.state.next({errors:{}})},Be=(C,D,k)=>{const z=(W(n,C,{_f:{}})._f||{}).ref,V=W(r.errors,C)||{},{ref:G,message:q,type:te,...me}=V;je(r.errors,C,{...me,...D,ref:z}),y.state.next({name:C,errors:r.errors,isValid:!1}),k&&k.shouldFocus&&z&&z.focus&&z.focus()},ve=(C,D)=>mt(C)?y.state.subscribe({next:k=>"values"in k&&C(k.values||Z(void 0,D),k)}):Z(C,D,!0),ue=C=>y.state.subscribe({next:D=>{if(Z1(C.name,D.name,C.exact)&&X1(D,C.formState||f,gr,C.reRenderRoot)){const k={...i};C.callback({values:k,...r,...D,defaultValues:s})}}}).unsubscribe,ge=C=>(o.mount=!0,g={...g,...C.formState},ue({...C,formState:{...u,...C.formState}})),$e=(C,D={})=>{for(const k of C?Ji(C):a.mount)a.mount.delete(k),a.array.delete(k),D.keepValue||(Ze(n,k),Ze(i,k)),!D.keepError&&Ze(r.errors,k),!D.keepDirty&&Ze(r.dirtyFields,k),!D.keepTouched&&Ze(r.touchedFields,k),!D.keepIsValidating&&Ze(r.validatingFields,k),!t.shouldUnregister&&!D.keepDefaultValue&&Ze(s,k);y.state.next({values:Ge(i)}),y.state.next({...r,...D.keepDirty?{isDirty:U()}:{}}),!D.keepIsValid&&v()},qe=({disabled:C,name:D})=>{if(Pt(C)&&o.mount||C||a.disabled.has(D)){const V=a.disabled.has(D)!==!!C;C?a.disabled.add(D):a.disabled.delete(D),V&&o.mount&&!o.action&&v()}},ke=(C,D={})=>{let k=W(n,C);const z=Pt(D.disabled)||Pt(t.disabled),V=!a.registerName.has(C)&&k&&k._f&&!k._f.mount;return je(n,C,{...k||{},_f:{...k&&k._f?k._f:{ref:{name:C}},name:C,mount:!0,...D}}),a.mount.add(C),k&&!V?qe({disabled:Pt(D.disabled)?D.disabled:t.disabled,name:C}):x(C,!0,D.value),{...z?{disabled:D.disabled||t.disabled}:{},...t.progressive?{required:!!D.required,min:xs(D.min),max:xs(D.max),minLength:xs(D.minLength),maxLength:xs(D.maxLength),pattern:xs(D.pattern)}:{},name:C,onChange:ie,onBlur:ie,ref:G=>{if(G){a.registerName.add(C),ke(C,D),a.registerName.delete(C),k=W(n,C);const q=Ue(G.value)&&G.querySelectorAll&&G.querySelectorAll("input,select,textarea")[0]||G,te=H1(q),me=k._f.refs||[];if(te?me.find(Ke=>Ke===q):q===k._f.ref)return;je(n,C,{_f:{...k._f,...te?{refs:[...me.filter(ul),q,...Array.isArray(W(s,C))?[{}]:[]],ref:{type:q.type,name:C}}:{ref:q}}}),x(C,!1,void 0,q)}else k=W(n,C,{}),k._f&&(k._f.mount=!1),(t.shouldUnregister||D.shouldUnregister)&&!(Gf(a.array,C)&&o.action)&&a.unMount.add(C)}}},ee=()=>t.shouldFocusError&&!t.shouldUseNativeValidation&&As(n,B,a.mount),Qe=C=>{Pt(C)&&(y.state.next({disabled:C}),As(n,(D,k)=>{const z=W(n,k);z&&(D.disabled=z._f.disabled||C,Array.isArray(z._f.refs)&&z._f.refs.forEach(V=>{V.disabled=z._f.disabled||C}))},0,!1))},tt=(C,D)=>async k=>{let z;k&&(k.preventDefault&&k.preventDefault(),k.persist&&k.persist());let V=Ge(i);if(y.state.next({isSubmitting:!0}),t.resolver){const{errors:G,values:q}=await N();m(),r.errors=G,V=Ge(q)}else await A({fields:n,eventType:Tr.SUBMIT});if(a.disabled.size)for(const G of a.disabled)Ze(V,G);if(Ze(r.errors,Rf),nt(r.errors)){y.state.next({errors:{}});try{await C(V,k)}catch(G){z=G}}else D&&await D({...r.errors},k),ee(),setTimeout(ee);if(y.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:nt(r.errors)&&!z,submitCount:r.submitCount+1,errors:r.errors}),z)throw z},H=(C,D={})=>{W(n,C)&&(Ue(D.defaultValue)?Q(C,Ge(W(s,C))):(Q(C,D.defaultValue),je(s,C,Ge(D.defaultValue))),D.keepTouched||Ze(r.touchedFields,C),D.keepDirty||(Ze(r.dirtyFields,C),r.isDirty=D.defaultValue?U(C,Ge(W(s,C))):U()),D.keepError||(Ze(r.errors,C),f.isValid&&v()),y.state.next({...r}))},re=(C,D={})=>{const k=C?Ge(C):s,z=Ge(k),V=nt(C),G=z;if(D.keepDefaultValues||(s=k),!D.keepValues){if(D.keepDirtyValues){const q=new Set([...a.mount,...Object.keys(Xr(s,i))]);for(const te of Array.from(q)){const me=W(r.dirtyFields,te),Ke=W(i,te),kt=W(G,te);me&&!Ue(Ke)?je(G,te,Ke):!me&&!Ue(kt)&&Q(te,kt)}}else{if(Ri&&Ue(C))for(const q of a.mount){const te=W(n,q);if(te&&te._f){const me=Array.isArray(te._f.refs)?te._f.refs[0]:te._f.ref;if(eo(me)){const Ke=me.closest("form");if(Ke){Ke.reset();break}}}}if(D.keepFieldsRef)for(const q of a.mount)Q(q,W(G,q));else n={}}if(t.shouldUnregister){if(i=D.keepDefaultValues?Ge(s):{},D.keepFieldsRef)for(const q of a.mount)je(i,q,W(G,q))}else i=Ge(G);y.array.next({values:{...G}}),y.state.next({values:{...G}})}a={mount:D.keepDirtyValues?a.mount:new Set,unMount:new Set,array:new Set,registerName:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:""},o.mount=!f.isValid||!!D.keepIsValid||!!D.keepDirtyValues||!t.shouldUnregister&&!nt(G),o.watch=!!t.shouldUnregister,o.keepIsValid=!!D.keepIsValid,o.action=!1,D.keepErrors||(r.errors={}),y.state.next({submitCount:D.keepSubmitCount?r.submitCount:0,isDirty:V?!1:D.keepDirty?r.isDirty:D.keepValues?U():!!(D.keepDefaultValues&&!Mt(C,s)),isSubmitted:D.keepIsSubmitted?r.isSubmitted:!1,dirtyFields:V?{}:D.keepDirtyValues?D.keepDefaultValues&&i?Xr(s,i):r.dirtyFields:D.keepDefaultValues&&C?Xr(s,C):D.keepDirty?r.dirtyFields:{},touchedFields:D.keepTouched?r.touchedFields:{},errors:D.keepErrors?r.errors:{},isSubmitSuccessful:D.keepIsSubmitSuccessful?r.isSubmitSuccessful:!1,isSubmitting:!1,defaultValues:s})},oe=(C,D)=>re(mt(C)?C(i):C,{...t.resetOptions,...D}),Re=(C,D={})=>{const k=W(n,C),z=k&&k._f;if(z){const V=z.refs?z.refs[0]:z.ref;V.focus&&setTimeout(()=>{V.focus(),D.shouldSelect&&mt(V.select)&&V.select()})}},gr=C=>{r={...r,...C}},Yn={control:{register:ke,unregister:$e,getFieldState:de,handleSubmit:tt,setError:Be,_subscribe:ue,_runSchema:N,_updateIsValidating:m,_focusError:ee,_getWatch:Z,_getDirty:U,_setValid:v,_setFieldArray:S,_setDisabledField:qe,_setErrors:E,_getFieldArray:se,_reset:re,_resetDefaultValues:()=>mt(t.defaultValues)&&t.defaultValues().then(C=>{oe(C,t.resetOptions),y.state.next({isLoading:!1})}),_removeUnmounted:$,_disableForm:Qe,_subjects:y,_proxyFormState:f,get _fields(){return n},get _formValues(){return i},get _state(){return o},set _state(C){o=C},get _defaultValues(){return s},get _names(){return a},set _names(C){a=C},get _formState(){return r},get _options(){return t},set _options(C){t={...t,...C}}},subscribe:ge,trigger:R,register:ke,handleSubmit:tt,watch:ve,setValue:Q,setValues:J,getValues:K,reset:oe,resetField:H,resetDefaultValues:(C,D={})=>{if(s=Ge(C),!D.keepDirty){const k=Xr(s,i);r.dirtyFields=k,r.isDirty=!nt(k)}D.keepIsValid||v(),y.state.next({...r,defaultValues:s})},clearErrors:Oe,unregister:$e,setError:Be,setFocus:Re,getFieldState:de};return{...Yn,formControl:Yn}}function nE(e={}){const t=h.useRef(void 0),r=h.useRef(void 0),n=h.useRef(e.formControl),[s,i]=h.useState(()=>({...Ge(mh),isLoading:mt(e.defaultValues),errors:e.errors||{},disabled:e.disabled||!1,defaultValues:mt(e.defaultValues)?void 0:e.defaultValues}));if(!t.current||e.formControl&&n.current!==e.formControl)if(n.current=e.formControl,e.formControl)t.current={...e.formControl,formState:s},e.defaultValues&&!mt(e.defaultValues)&&e.formControl.reset(e.defaultValues,e.resetOptions);else{const{formControl:a,...c}=rE(e);t.current={...c,formState:s}}const o=t.current.control;return o._options=e,sl(()=>{const a=o._subscribe({formState:o._proxyFormState,callback:()=>i({...o._formState,defaultValues:o._defaultValues}),reRenderRoot:!0});return i(c=>({...c,isReady:!0})),o._formState.isReady=!0,a},[o]),h.useEffect(()=>o._disableForm(e.disabled),[o,e.disabled]),h.useEffect(()=>{e.mode&&(o._options.mode=e.mode),e.reValidateMode&&(o._options.reValidateMode=e.reValidateMode)},[o,e.mode,e.reValidateMode]),h.useEffect(()=>{e.errors&&(o._setErrors(e.errors),o._focusError())},[o,e.errors]),h.useEffect(()=>{e.shouldUnregister&&o._subjects.state.next({values:o._getWatch()})},[o,e.shouldUnregister]),h.useEffect(()=>{if(o._proxyFormState.isDirty){const a=o._getDirty();a!==s.isDirty&&o._subjects.state.next({isDirty:a})}},[o,s.isDirty]),h.useEffect(()=>{var a;e.values&&!Mt(e.values,r.current)?(o._reset(e.values,{keepFieldsRef:!0,...o._options.resetOptions}),!((a=o._options.resetOptions)===null||a===void 0)&&a.keepIsValid||o._setValid(),r.current=e.values,i(c=>({...c}))):o._resetDefaultValues()},[o,e.values]),h.useEffect(()=>{o._state.mount||(o._setValid(),o._state.mount=!0),o._state.watch&&(o._state.watch=!1,o._subjects.state.next({...o._formState})),o._removeUnmounted()}),t.current.formState=h.useMemo(()=>Zf(s,o),[o,s]),t.current}async function bh(e){var r,n;return(n=(r=(await Ae.get(`/api/framework/v1/read/${e}`)).data)==null?void 0:r.result)==null?void 0:n.framework}async function sE(e){var r,n;return((n=(r=(await Ae.post("/action/composite/v3/search",{request:{filters:{objectType:"Framework",status:["Live"],...e.type?{type:e.type}:{},...e.identifier?{identifier:e.identifier}:{},...e.channel?{channel:e.channel}:{},...e.systemDefault?{systemDefault:e.systemDefault}:{}}}})).data)==null?void 0:r.result)==null?void 0:n.Framework)??[]}function _h(e,t){const r=ts({queryKey:["framework",e],queryFn:()=>bh(e),enabled:!!e,staleTime:3e5}),n=t==null?void 0:t[0],s=ts({queryKey:["framework",n],queryFn:()=>bh(n),enabled:!!n,staleTime:5*60*1e3}),i=s.data?[s.data]:[];return{organisationFramework:r.data,targetFrameworks:i,isLoading:r.isLoading||s.isLoading}}function iE(e,t,r){const n=e??[],s=new Set(n.map(u=>u.type).filter(Boolean)),i=(t??[]).filter(u=>!s.has(u)),{data:o}=ts({queryKey:["framework-search",i.sort().join(","),r],queryFn:()=>sE({type:i,systemDefault:"Yes"}),enabled:i.length>0,staleTime:10*60*1e3}),a=t&&t.length?n.filter(u=>u.type&&t.includes(u.type)):n,c=[...(o??[]).map(u=>({label:u.name,value:u.identifier})),...a.map(u=>({label:u.name,value:u.identifier}))],d=new Set;return c.filter(u=>d.has(u.value)?!1:(d.add(u.value),!0))}async function oE(e){var r,n;return(n=(r=(await Ae.get(`/api/channel/v1/read/${e}`)).data)==null?void 0:r.result)==null?void 0:n.channel}function aE(e){var r,n,s,i,o,a;const t=ts({queryKey:["channel",e],queryFn:()=>oE(e),enabled:!!e,staleTime:6e5});return{identifier:((r=t.data)==null?void 0:r.identifier)??e??"",name:(n=t.data)==null?void 0:n.name,frameworks:(s=t.data)==null?void 0:s.frameworks,collectionAdditionalCategories:(i=t.data)==null?void 0:i.collectionAdditionalCategories,contentAdditionalCategories:(o=t.data)==null?void 0:o.contentAdditionalCategories,defaultLicense:(a=t.data)==null?void 0:a.defaultLicense,isLoading:t.isLoading}}const lE={"First Section":{title:"Basic Information",description:"Core details that define the content identity."},"Second Section":{title:"Categorisation",description:"Category and type classification for the content."},"Third Section":{title:"Categorisation",description:"Category and type classification for the content."},"Organisation Framework Terms":{title:"Curriculum",description:"Framework-aligned categorisation."},"Target Framework Terms":{title:"Target Audience",description:"Curriculum alignment for the intended learners."},"Fourth Section":{title:"Licensing & Attribution",description:"Copyright and usage rights information."},"Sixth Section":{title:"Licensing & Attribution",description:"Copyright and usage rights information."}},cE=new Set(["review","read","sourcingreview","orgreview"]),ro={"First Section":"details","Second Section":"details","Third Section":"details","Organisation Framework Terms":"details","Target Framework Terms":"audience","Fourth Section":"licensing","Sixth Section":"licensing"},uE={Categorisation:"Second Section","Basic Information":"First Section","Licensing & Attribution":"Fourth Section",Curriculum:"Organisation Framework Terms","Target Audience":"Target Framework Terms"},dE={name:"details",description:"details",keywords:"details",appIcon:"details",primaryCategory:"details",additionalCategories:"details",board:"details",boardIds:"details",subject:"details",subjectIds:"details",medium:"details",framework:"details",topicsIds:"details",topic:"details",dialcodeRequired:"details",dialcodes:"details",audience:"audience",targetBoardIds:"audience",targetMediumIds:"audience",targetGradeLevelIds:"audience",targetSubjectIds:"audience",gradeLevel:"audience",creator:"licensing",author:"licensing",attributions:"licensing",license:"licensing",copyright:"licensing",copyrightYear:"licensing"},pl={board:"board",boardIds:"board",medium:"medium",gradeLevel:"gradeLevel",subject:"subject",subjectIds:"subject",topicsIds:"topic",topic:"topic",targetBoardIds:"board",targetMediumIds:"medium",targetGradeLevelIds:"gradeLevel",targetSubjectIds:"subject"},wh=new Set(["targetBoardIds","targetMediumIds","targetGradeLevelIds","targetSubjectIds"]);function fE(e,t,r,n,s={}){if(!(e!=null&&e.length))return IE(t,n,r);const i=new Map;for(const a of e){const c=a.code;c&&!i.has(c)&&i.set(c,a)}const o=new Set;return e.filter(a=>{if(n&&(a.code==="dialCode"||a.code==="dialcode")||a.visible===!1)return!1;const c=a.code;return o.has(c)?!1:(o.add(c),!0)}).map(a=>{const c=a.code??"",d=bE(a),u=_E(a,r,t,i,s),f=t[c],g=pE(c,Sh(f,d),d,t,s),y={code:c,label:a.label??c,inputType:d,required:!!(a.required===!0||Array.isArray(a.validations)&&a.validations.some(_=>_.type==="required")),editable:hE(c,a.editable!==!1,s),placeholder:a.placeholder,maxLength:a.maxLength,options:vE(u,g,d,r),depends:a.depends,tab:mE(a),section:a.section,defaultValue:a.defaultValue??a.default,currentValue:g};if(c==="dialcodes"){const _=t.dialcodeRequired==="Yes";return{...y,required:_,visible:_}}return y})}function hE(e,t,r){var i;const n=r.editorMode??"edit";if(!cE.has(n))return t!==!1;const s=(i=r.editableFields)==null?void 0:i[n];return!!(s&&s.includes(e))}function pE(e,t,r,n,s){const i=t==null||t===""||Array.isArray(t)&&t.length===0;switch(e){case"license":return i?s.defaultLicense??"":t;case"copyright":return i&&s.setDefaultCopyRight&&s.channelName?s.channelName:t;case"author":case"creator":return i&&s.userFullName?s.userFullName:t;case"instructions":{const o=n.instructions;return o&&typeof o=="object"&&!Array.isArray(o)?o.default??"":typeof t=="object"&&t!==null?"":t}case"maxTime":case"warningTime":{if(!i)return t;const o=n.timeLimits,a=o==null?void 0:o[e];return a!=null&&a!==""?gE(Number(a)):t}default:return t}}function gE(e){if(!Number.isFinite(e)||e<0)return"";const t=Math.floor(e%60),r=Math.floor(e/60%60),n=Math.floor(e/3600),s=i=>String(i).padStart(2,"0");return n>0?`${s(n)}:${s(r)}:${s(t)}`:`${s(r)}:${s(t)}`}function yE(e){var n,s,i;const t=new Map,r=o=>o==null?void 0:o.forEach(a=>{a.identifier&&t.set(a.identifier,a.name),a.name&&t.set(a.name,a.name)});return(s=(n=e.organisationFramework)==null?void 0:n.categories)==null||s.forEach(o=>r(o.terms)),(i=e.targetFrameworks)==null||i.forEach(o=>{var a;return(a=o.categories)==null?void 0:a.forEach(c=>r(c.terms))}),t}function vE(e,t,r,n){if(r!=="select"&&r!=="multiselect"&&r!=="radio")return e;const s=Array.isArray(t)?t:t!=null&&t!==""?[t]:[];if(!s.length)return e;const i=e?[...e]:[],o=new Set(i.map(c=>c.value)),a=yE(n);for(const c of s){const d=String(c);o.has(d)||(i.push({label:a.get(d)??d,value:d}),o.add(d))}return i}function mE(e){const t=e.section;if(t){if(ro[t])return ro[t];const n=uE[t];if(n&&ro[n])return ro[n]}const r=e.code??"";return dE[r]??"details"}function Sh(e,t){const r=new Set(["multiselect","chips","keywords","tagsinput"]),n=new Set(["select","text","textarea","radio","datepicker","datetime","license"]);return r.has(t)?Array.isArray(e)?e:e!=null&&e!==""?[e]:[]:n.has(t)?Array.isArray(e)?e[0]??"":e??"":e}function bE(e){const t=(e.inputType??e.dataType??"").toLowerCase(),n=(e.dataType??"").toLowerCase()==="list";return t==="select"?"select":t==="framework"||t==="frameworkcategoryselect"?n?"multiselect":"select":t==="topicselector"?"chips":t==="multiselect"||t==="multi-select"?"multiselect":t==="keywords"||e.code==="keywords"||e.code==="topic"||e.code==="topicsIds"?"chips":t==="radio"?"radio":e.code==="appIcon"||t==="appicon"?"appIcon":t==="textarea"||e.code==="description"?"textarea":t==="datepicker"||t==="date"?"datepicker":t==="datetime"||t==="datetime-local"?"datetime":t==="tagsinput"?"tagsinput":t==="nestedselect"||t==="nested-select"?n?"multiselect":"select":t==="license"?"license":t==="dialcode"||t==="dial-code"?"dialcode":"text"}function _E(e,t,r,n,s){const i=e.code??"";if(i==="maxQuestions"){const d=s.childCount??0;if(d>0)return Array.from({length:d},(u,f)=>({label:String(f+1),value:String(f+1)}))}const o=e.range;if(Array.isArray(o)&&o.length)return typeof o[0]=="string"?o.map(d=>({label:d,value:d})):o.map(d=>({label:d.name,value:d.identifier}));const a=e.enum;if(a!=null&&a.length)return a.map(d=>({label:d,value:d}));if(i==="framework")return t.orgFrameworks;if(i==="additionalCategories"){const u=(s.objectType??"")==="QuestionSet"?s.contentAdditionalCategories??s.collectionAdditionalCategories:s.collectionAdditionalCategories??s.contentAdditionalCategories,f=(u&&u.length?u:s.contextAdditionalCategories)??t.channelAdditionalCategories;return f!=null&&f.length?EE(f).map(g=>({label:g,value:g})):void 0}const c=e.sourceCategory??pl[i];if(c)return Ch(i,c,e,t,r,n)}function wE(e,t){return wh.has(e)||t.output==="identifier"||typeof t.section=="string"&&t.section.includes("Target")}function SE(e,t){return wh.has(e)||typeof t.section=="string"&&t.section.includes("Target")}function gl(e,t,r){var i,o,a,c,d;const n=(o=(i=e.organisationFramework)==null?void 0:i.categories)==null?void 0:o.find(u=>u.code===t),s=(d=(c=(a=e.targetFrameworks)==null?void 0:a[0])==null?void 0:c.categories)==null?void 0:d.find(u=>u.code===t);return r?(s==null?void 0:s.terms)??(n==null?void 0:n.terms)??[]:(n==null?void 0:n.terms)??(s==null?void 0:s.terms)??[]}function CE(e){const t=new Set,r=[];for(const n of e){const s=n.identifier??n.name;s&&!t.has(s)&&(t.add(s),r.push(n))}return r}function EE(e){return Array.from(new Set(e))}function OE(e){return Array.isArray(e)?e:e!=null&&e!==""?[e]:[]}function Ch(e,t,r,n,s,i){const o=wE(e,r),a=SE(e,r),c=p=>({label:p.name,value:o?p.identifier:p.name}),d=r.depends;if(!(d!=null&&d.length))return gl(n,t,a).map(c);const u=d.flatMap(p=>OE(s[p])).map(String);if(!u.length)return[];const f=[];for(const p of d){const v=i.get(p),m=(v==null?void 0:v.sourceCategory)??pl[p]??p;f.push(...gl(n,m,a))}const y=f.filter(p=>u.includes(String(p.name))||u.includes(String(p.identifier))||u.includes(String(p.code))).flatMap(p=>p.associations??[]).filter(p=>String(p.category??"").toLowerCase()===t.toLowerCase()),_=CE(y);return _.length?_.map(c):gl(n,t,a).map(c)}function Ps(e,t){const r=pl[e];if(r)return Ch(e,r,{},t,{},new Map)}function dt(e,t,r){return Sh(e[t],r)}function IE(e,t,r){var s;const n=[{code:"name",label:"Title",inputType:"text",required:!0,editable:!0,tab:"details",section:"First Section",maxLength:200,currentValue:dt(e,"name","text")},{code:"description",label:"Description",inputType:"textarea",editable:!0,tab:"details",section:"First Section",maxLength:2e3,currentValue:dt(e,"description","textarea")},{code:"keywords",label:"Keywords",inputType:"chips",editable:!0,tab:"details",section:"First Section",currentValue:dt(e,"keywords","chips")}];return t&&(n.push({code:"primaryCategory",label:"Category",inputType:"select",editable:!1,tab:"details",section:"Second Section",currentValue:dt(e,"primaryCategory","select")},{code:"additionalCategories",label:"Additional Category",inputType:"multiselect",editable:!0,tab:"details",section:"Second Section",currentValue:dt(e,"additionalCategories","multiselect"),options:(s=r.channelAdditionalCategories)==null?void 0:s.map(i=>({label:i,value:i}))},{code:"framework",label:"Course Type",inputType:"select",required:!0,editable:!0,tab:"details",section:"Organisation Framework Terms",options:r.orgFrameworks,currentValue:dt(e,"framework","select")},{code:"subjectIds",label:"Subjects covered",inputType:"multiselect",required:!0,editable:!0,tab:"details",section:"Organisation Framework Terms",options:Ps("subjectIds",r),currentValue:dt(e,"subjectIds","multiselect")}),n.push({code:"audience",label:"Audience Type",inputType:"multiselect",editable:!0,tab:"audience",section:"Target Framework Terms",currentValue:dt(e,"audience","multiselect")},{code:"targetBoardIds",label:"Board/Syllabus of the audience",inputType:"select",required:!0,editable:!0,tab:"audience",section:"Target Framework Terms",options:Ps("targetBoardIds",r),currentValue:dt(e,"targetBoardIds","select")},{code:"targetMediumIds",label:"Medium(s) of the audience",inputType:"multiselect",required:!0,editable:!0,tab:"audience",section:"Target Framework Terms",depends:["targetBoardIds"],options:Ps("targetMediumIds",r),currentValue:dt(e,"targetMediumIds","multiselect")},{code:"targetGradeLevelIds",label:"Class(es) of the audience",inputType:"multiselect",required:!0,editable:!0,tab:"audience",section:"Target Framework Terms",depends:["targetMediumIds"],options:Ps("targetGradeLevelIds",r),currentValue:dt(e,"targetGradeLevelIds","multiselect")},{code:"targetSubjectIds",label:"Subject(s) of the audience",inputType:"multiselect",required:!0,editable:!0,tab:"audience",section:"Target Framework Terms",depends:["targetGradeLevelIds"],options:Ps("targetSubjectIds",r),currentValue:dt(e,"targetSubjectIds","multiselect")}),n.push({code:"creator",label:"Author",inputType:"text",editable:!0,tab:"licensing",section:"Fourth Section",currentValue:dt(e,"creator","text")},{code:"attributions",label:"Attributions",inputType:"text",editable:!0,tab:"licensing",section:"Fourth Section",currentValue:dt(e,"attributions","text")},{code:"copyright",label:"Copyright",inputType:"text",required:!0,editable:!0,tab:"licensing",section:"Fourth Section",currentValue:dt(e,"copyright","text")},{code:"copyrightYear",label:"Copyright Year",inputType:"text",required:!0,editable:!0,tab:"licensing",section:"Fourth Section",currentValue:dt(e,"copyrightYear","text")},{code:"license",label:"License",inputType:"select",required:!0,editable:!0,tab:"licensing",section:"Fourth Section",currentValue:dt(e,"license","select")})),n}const DE=["allowECM","levels","setPeriod","instances"];function Eh(e){const t={};return e.forEach((r,n)=>{t[`L${n+1}`]={label:r}}),t}function TE(e,t={}){const r={...e};for(const i of DE)delete r[i];const n=e.levels;Array.isArray(n)&&n.length&&(r.outcomeDeclaration={levels:Eh(n)});const s=e.instances;return s!=null&&s!==""&&(r.instances={label:s}),t.isReview&&(r.name===void 0||r.name===null||r.name==="")&&t.nodeTitle&&(r.name=t.nodeTitle),r}function NE(e,t){return e==="allowECM"||e==="setPeriod"?null:e==="levels"?{outcomeDeclaration:{levels:Array.isArray(t)?Eh(t):{}}}:e==="instances"?{instances:t!=null&&t!==""?{label:t}:""}:{[e]:t}}function kE(e,t){const{watch:r,setValue:n}=e,s=h.useRef(!1);h.useEffect(()=>{const i=r((o,{name:a})=>{var c;if(!(!a||s.current)){s.current=!0;try{const d=new Set([a]);let u=!0;for(;u;){u=!1;for(const f of t)d.has(f.code)||(c=f.depends)!=null&&c.some(g=>d.has(g))&&(n(f.code,f.inputType==="multiselect"||f.inputType==="chips"?[]:"",{shouldDirty:!0}),d.add(f.code),u=!0)}}finally{s.current=!1}}});return()=>i.unsubscribe()},[r,n,t])}const Ln={section:"_section_ylgu8_1",header:"_header_ylgu8_11",title:"_title_ylgu8_17",description:"_description_ylgu8_24",divider:"_divider_ylgu8_30",fields:"_fields_ylgu8_36"},xE=({title:e,description:t,children:r})=>l.jsxs("div",{className:Ln.section,children:[l.jsxs("div",{className:Ln.header,children:[l.jsx("h3",{className:Ln.title,children:e}),t&&l.jsx("p",{className:Ln.description,children:t})]}),l.jsx("hr",{className:Ln.divider}),l.jsx("div",{className:Ln.fields,children:r})]}),L={field:"_field_1s288_1",fullWidth:"_fullWidth_1s288_7",label:"_label_1s288_11",required:"_required_1s288_19",input:"_input_1s288_24",textarea:"_textarea_1s288_45",inputError:"_inputError_1s288_50",error:"_error_1s288_54",selectBtn:"_selectBtn_1s288_59",selectOpen:"_selectOpen_1s288_83",placeholder:"_placeholder_1s288_87",selectedVal:"_selectedVal_1s288_91",chevronUp:"_chevronUp_1s288_95",dropdown:"_dropdown_1s288_100",option:"_option_1s288_116",optionSelected:"_optionSelected_1s288_134",noOpts:"_noOpts_1s288_139",chipGroup:"_chipGroup_1s288_146",chipInput:"_chipInput_1s288_158",addChipBtn:"_addChipBtn_1s288_167",radioGroup:"_radioGroup_1s288_184",radioLabel:"_radioLabel_1s288_191",iconWrap:"_iconWrap_1s288_199",iconPreview:"_iconPreview_1s288_214",iconPlaceholder:"_iconPlaceholder_1s288_220",removeIconBtn:"_removeIconBtn_1s288_233",tagChip:"_tagChip_1s288_252",tagChipRemove:"_tagChipRemove_1s288_264",nestedSelectRow:"_nestedSelectRow_1s288_278",dialcodeRow:"_dialcodeRow_1s288_287",validateBtn:"_validateBtn_1s288_293",dialcodeValid:"_dialcodeValid_1s288_315",dialcodeSpinner:"_dialcodeSpinner_1s288_325"},Oh=({name:e,label:t,required:r,disabled:n,multiline:s,maxLength:i,placeholder:o})=>{const{register:a,formState:{errors:c}}=Rt(),d=c[e],u={required:r?`${t} is required`:!1,maxLength:i?{value:i,message:`Max ${i} characters`}:void 0};return l.jsxs("div",{className:[L.field,s?L.fullWidth:""].join(" "),children:[l.jsxs("label",{className:L.label,htmlFor:e,children:[t,r&&l.jsx("span",{className:L.required,children:"*"})]}),s?l.jsx("textarea",{id:e,className:[L.input,L.textarea,d?L.inputError:""].join(" "),disabled:n,placeholder:o,rows:3,...a(e,u)}):l.jsx("input",{id:e,type:"text",className:[L.input,d?L.inputError:""].join(" "),disabled:n,placeholder:o,...a(e,u)}),d&&l.jsx("span",{className:L.error,children:String(d.message)})]})},AE=({name:e,label:t,options:r,required:n,disabled:s})=>{var p;const[i,o]=h.useState(!1),a=h.useRef(null),{register:c,watch:d,setValue:u,formState:{errors:f}}=Rt(),g=d(e),y=((p=r.find(v=>v.value===g))==null?void 0:p.label)??"Select…",_=f[e];return h.useEffect(()=>{if(!i)return;const v=m=>{var b;(b=a.current)!=null&&b.contains(m.target)||o(!1)};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[i]),l.jsxs("div",{className:L.field,ref:a,style:{position:"relative"},children:[l.jsxs("label",{className:L.label,children:[t,n&&l.jsx("span",{className:L.required,children:"*"})]}),l.jsx("input",{type:"hidden",...c(e,{required:n?`${t} is required`:!1})}),l.jsxs("button",{type:"button",disabled:s,className:[L.selectBtn,_?L.inputError:"",i?L.selectOpen:""].join(" "),onClick:()=>o(v=>!v),children:[l.jsx("span",{className:g?L.selectedVal:L.placeholder,children:y}),l.jsx(hs,{size:14,className:i?L.chevronUp:""})]}),i&&l.jsxs("div",{className:L.dropdown,children:[r.map(v=>l.jsxs("button",{type:"button",className:[L.option,g===v.value?L.optionSelected:""].join(" "),onClick:()=>{u(e,v.value,{shouldDirty:!0,shouldValidate:!0}),o(!1)},children:[l.jsx("span",{children:v.label}),g===v.value&&l.jsx(vn,{size:13})]},v.value)),!r.length&&l.jsx("span",{className:L.noOpts,children:"No options"})]}),_&&l.jsx("span",{className:L.error,children:String(_.message)})]})},PE=({name:e,label:t,options:r,required:n,disabled:s})=>{const[i,o]=h.useState(!1),a=h.useRef(null),{register:c,watch:d,setValue:u,formState:{errors:f}}=Rt(),g=d(e)??[],y=f[e],_=g.length?`${g.length} selected`:"Select…";h.useEffect(()=>{if(!i)return;const v=m=>{var b;(b=a.current)!=null&&b.contains(m.target)||o(!1)};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[i]);const p=v=>{const m=g.includes(v)?g.filter(b=>b!==v):[...g,v];u(e,m,{shouldDirty:!0,shouldValidate:!0})};return l.jsxs("div",{className:L.field,ref:a,style:{position:"relative"},children:[l.jsxs("label",{className:L.label,children:[t,n&&l.jsx("span",{className:L.required,children:"*"})]}),l.jsx("input",{type:"hidden",...c(e,{required:n?`${t} is required`:!1})}),l.jsxs("button",{type:"button",disabled:s,className:[L.selectBtn,y?L.inputError:"",i?L.selectOpen:""].join(" "),onClick:()=>o(v=>!v),children:[l.jsx("span",{className:g.length?L.selectedVal:L.placeholder,children:_}),l.jsx(hs,{size:14,className:i?L.chevronUp:""})]}),i&&l.jsxs("div",{className:L.dropdown,children:[r.map(v=>l.jsxs("button",{type:"button",className:[L.option,g.includes(v.value)?L.optionSelected:""].join(" "),onClick:()=>p(v.value),children:[l.jsx(vn,{size:13,style:{opacity:g.includes(v.value)?1:0}}),l.jsx("span",{children:v.label})]},v.value)),!r.length&&l.jsx("span",{className:L.noOpts,children:"No options"})]}),y&&l.jsx("span",{className:L.error,children:String(y.message)})]})},ME=({name:e,label:t,required:r,disabled:n,placeholder:s="Add…"})=>{const[i,o]=h.useState(""),[a,c]=h.useState(!1),d=h.useRef(null),{watch:u,setValue:f,formState:{errors:g}}=Rt(),y=u(e)??[],_=g[e],p=()=>{const m=i.trim();m&&!y.includes(m)&&f(e,[...y,m],{shouldDirty:!0}),o(""),c(!1)},v=m=>f(e,y.filter(b=>b!==m),{shouldDirty:!0});return l.jsxs("div",{className:[L.field,L.fullWidth].join(" "),children:[l.jsxs("label",{className:L.label,children:[t,r&&l.jsx("span",{className:L.required,children:"*"})]}),l.jsxs("div",{className:L.chipGroup,children:[y.map(m=>l.jsxs("span",{className:"sbx-chip filled",children:[m,!n&&l.jsx("button",{type:"button",className:"sbx-chip-remove",onClick:()=>v(m),"aria-label":`Remove ${m}`,children:"×"})]},m)),!n&&(a?l.jsx("input",{ref:d,autoFocus:!0,className:L.chipInput,value:i,onChange:m=>o(m.target.value),onKeyDown:m=>{m.key==="Enter"&&(m.preventDefault(),p()),m.key==="Escape"&&(o(""),c(!1))},onBlur:p,placeholder:s}):l.jsxs("button",{type:"button",className:L.addChipBtn,onClick:()=>{c(!0),setTimeout(()=>{var m;return(m=d.current)==null?void 0:m.focus()},50)},children:[l.jsx(ps,{size:12})," Add"]}))]}),_&&l.jsx("span",{className:L.error,children:String(_.message)})]})},LE=({name:e,label:t,options:r,required:n,disabled:s})=>{const{register:i,formState:{errors:o}}=Rt(),a=o[e];return l.jsxs("div",{className:L.field,children:[l.jsxs("label",{className:L.label,children:[t,n&&l.jsx("span",{className:L.required,children:"*"})]}),l.jsx("div",{className:L.radioGroup,children:r.map(c=>l.jsxs("label",{className:L.radioLabel,children:[l.jsx("input",{type:"radio",value:c.value,disabled:s,...i(e,{required:n?`${t} is required`:!1})}),c.label]},c.value))}),a&&l.jsx("span",{className:L.error,children:String(a.message)})]})};async function FE(e,t,r,n){var o,a;const i=(a=(o=(await Ae.post("/action/asset/v1/create",{request:{asset:{primaryCategory:"asset",language:["English"],code:crypto.randomUUID(),name:e,mediaType:"image",mimeType:t,createdBy:r,creator:null,channel:n,keywords:""}}})).data)==null?void 0:o.result)==null?void 0:a.node_id;if(!i)throw new Error("Asset creation failed: no node_id returned");return i}async function $E(e,t){var s,i;const n=(i=(s=(await Ae.post(`/action/content/v3/upload/url/${e}`,{request:{content:{fileName:t}}})).data)==null?void 0:s.result)==null?void 0:i.pre_signed_url;if(!n)throw new Error("Pre-signed URL fetch failed");return n}async function jE(e,t,r={}){const n=await fetch(e,{method:"PUT",body:t,headers:{"x-ms-blob-type":"BlockBlob","Content-Type":"application/octet-stream",...r}});if(!n.ok)throw new Error(`Blob upload failed: ${n.status} ${n.statusText}`)}async function BE(e,t,r){var o,a;const n=new FormData;n.append("fileUrl",t),n.append("mimeType",r);const i=(a=(o=(await Ae.post(`/action/asset/v1/upload/${e}`,n,{params:{enctype:"multipart/form-data",processData:!1,contentType:!1,cache:!1}})).data)==null?void 0:o.result)==null?void 0:a.content_url;if(!i)throw new Error("Asset finalize failed: no content_url returned");return i}const pe={overlay:"_overlay_ga6eh_1",modal:"_modal_ga6eh_12",header:"_header_ga6eh_24",title:"_title_ga6eh_33",closeBtn:"_closeBtn_ga6eh_39",tabs:"_tabs_ga6eh_57",tab:"_tab_ga6eh_57",activeTab:"_activeTab_ga6eh_83",body:"_body_ga6eh_88",searchWrap:"_searchWrap_ga6eh_99",searchIcon:"_searchIcon_ga6eh_104",searchInput:"_searchInput_ga6eh_113",grid:"_grid_ga6eh_132",imgCell:"_imgCell_ga6eh_148",imgCellSelected:"_imgCellSelected_ga6eh_166",thumb:"_thumb_ga6eh_171",noThumb:"_noThumb_ga6eh_177",checkBadge:"_checkBadge_ga6eh_183",loadMoreBtn:"_loadMoreBtn_ga6eh_198",loadingRow:"_loadingRow_ga6eh_220",empty:"_empty_ga6eh_230",spinner:"_spinner_ga6eh_237",uploadArea:"_uploadArea_ga6eh_247",dropZone:"_dropZone_ga6eh_256",uploadIcon:"_uploadIcon_ga6eh_277",dropText:"_dropText_ga6eh_281",dropSubtext:"_dropSubtext_ga6eh_288",uploadPreview:"_uploadPreview_ga6eh_294",hiddenInput:"_hiddenInput_ga6eh_301",fileName:"_fileName_ga6eh_305",errorText:"_errorText_ga6eh_311",footer:"_footer_ga6eh_318",cancelBtn:"_cancelBtn_ga6eh_328",confirmBtn:"_confirmBtn_ga6eh_345"},Ih=18,Dh=({nodeId:e,currentValue:t,onSelect:r,onClose:n})=>{const[s,i]=h.useState("my"),[o,a]=h.useState(""),[c,d]=h.useState([]),[u,f]=h.useState(0),[g,y]=h.useState(!1),[_,p]=h.useState(null),[v,m]=h.useState(0),[b,S]=h.useState(null),[w,E]=h.useState(""),[T,x]=h.useState(!1),[P,F]=h.useState(""),N=h.useRef(null),M=ae(B=>{var R,K;return((K=(R=B.editorConfig)==null?void 0:R.context)==null?void 0:K.channel)??""}),j=ae(B=>{var R,K;return((K=(R=B.editorConfig)==null?void 0:R.context)==null?void 0:K.uid)??""}),A=ae(B=>{var R,K,de;return((de=(K=(R=B.editorConfig)==null?void 0:R.context)==null?void 0:K.cloudStorage)==null?void 0:de.presigned_headers)??{}}),$=ae(B=>{var R,K,de;return((de=(K=(R=B.editorConfig)==null?void 0:R.config)==null?void 0:K.assetConfig)==null?void 0:de.size)??1*1024*1024}),U=ae(B=>{var R,K,de;return((de=(K=(R=B.editorConfig)==null?void 0:R.config)==null?void 0:K.assetConfig)==null?void 0:de.accepted)??"image/png,image/jpeg"}),Z=h.useCallback(async(B,R,K=!1)=>{var de;y(!0);try{const Oe={status:["Live"],mediaType:["image"],mimeType:["image/png","image/jpeg","image/jpg","image/gif","image/svg+xml"]};s==="my"&&j&&(Oe.createdBy=j),M&&(Oe.channel=M);const ve=((de=(await Ae.post("/action/composite/v3/search",{request:{filters:Oe,query:B,limit:Ih,offset:R,sort_by:{createdOn:"desc"},fields:["identifier","name","appIcon","artifactUrl","downloadUrl"]}},{headers:{"X-Source":"web"}})).data)==null?void 0:de.result)??{},ue=ve.content??[];f(ve.count??0),d(ge=>K?[...ge,...ue]:ue)}catch{}finally{y(!1)}},[s,j,M]);h.useEffect(()=>{s!=="upload"&&(d([]),m(0),Z(o,0))},[s]);const se=h.useRef(),be=B=>{a(B),clearTimeout(se.current),se.current=setTimeout(()=>{d([]),m(0),Z(B,0)},400)},Ee=()=>{const B=v+Ih;m(B),Z(o,B,!0)},ce=()=>{const B=(_==null?void 0:_.artifactUrl)??(_==null?void 0:_.appIcon)??(_==null?void 0:_.downloadUrl)??"";B&&r(B)};h.useEffect(()=>()=>{w&&URL.revokeObjectURL(w)},[w]);const Q=B=>{var de;const R=(de=B.target.files)==null?void 0:de[0];if(B.target.value="",!R)return;const K=U.split(",").map(Oe=>Oe.trim());if(!K.includes(R.type)){const Oe=K.map(Be=>Be.replace("image/","").toUpperCase()).join(", ");F(`Only ${Oe} files are accepted.`);return}if(R.size>$){const Oe=($/1048576).toFixed(0);F(`Image must be under ${Oe} MB.`);return}w&&URL.revokeObjectURL(w),S(R),E(URL.createObjectURL(R)),F("")},J=async()=>{if(b){x(!0),F("");try{const B=await FE(b.name.split(".").slice(0,-1).join(".")||b.name,b.type,j,M),R=await $E(B,b.name);await jE(R,b,A);const K=R.split("?")[0],de=await BE(B,K,b.type);r(de)}catch(B){F(B instanceof Error?B.message:"Upload failed.")}finally{x(!1)}}},ie=c.length<u;return l.jsx("div",{className:pe.overlay,role:"dialog","aria-modal":"true","aria-label":"Select App Icon",children:l.jsxs("div",{className:pe.modal,children:[l.jsxs("div",{className:pe.header,children:[l.jsx("span",{className:pe.title,children:"Select App Icon"}),l.jsx("button",{className:pe.closeBtn,onClick:n,"aria-label":"Close",children:l.jsx(zr,{size:18})})]}),l.jsxs("div",{className:pe.tabs,role:"tablist",children:[l.jsx("button",{role:"tab","aria-selected":s==="my",className:`${pe.tab} ${s==="my"?pe.activeTab:""}`,onClick:()=>i("my"),children:"My Images"}),l.jsx("button",{role:"tab","aria-selected":s==="all",className:`${pe.tab} ${s==="all"?pe.activeTab:""}`,onClick:()=>i("all"),children:"All Images"}),l.jsxs("button",{role:"tab","aria-selected":s==="upload",className:`${pe.tab} ${s==="upload"?pe.activeTab:""}`,onClick:()=>i("upload"),children:[l.jsx(Gc,{size:13,style:{marginRight:4}}),"Upload"]})]}),l.jsx("div",{className:pe.body,children:s!=="upload"?l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:pe.searchWrap,children:[l.jsx(Go,{size:14,className:pe.searchIcon}),l.jsx("input",{type:"search",className:pe.searchInput,placeholder:"Search images…",value:o,onChange:B=>be(B.target.value)})]}),g&&c.length===0?l.jsxs("div",{className:pe.loadingRow,children:[l.jsx(yi,{size:20,className:pe.spinner}),l.jsx("span",{children:"Loading…"})]}):c.length===0?l.jsx("div",{className:pe.empty,children:"No images found"}):l.jsx("div",{className:pe.grid,children:c.map(B=>{const R=B.appIcon??B.artifactUrl??B.downloadUrl??"",K=(_==null?void 0:_.identifier)===B.identifier;return l.jsxs("button",{type:"button",className:`${pe.imgCell} ${K?pe.imgCellSelected:""}`,onClick:()=>p(B),title:B.name,children:[R?l.jsx("img",{src:R,alt:B.name,className:pe.thumb}):l.jsx("div",{className:pe.noThumb,children:"IMG"}),K&&l.jsx("div",{className:pe.checkBadge,children:l.jsx(vn,{size:12})})]},B.identifier)})}),ie&&!g&&l.jsx("button",{className:pe.loadMoreBtn,onClick:Ee,children:"Load More"}),g&&c.length>0&&l.jsx("div",{className:pe.loadingRow,children:l.jsx(yi,{size:16,className:pe.spinner})})]}):l.jsxs("div",{className:pe.uploadArea,children:[l.jsx("div",{className:pe.dropZone,onClick:()=>{var B;return(B=N.current)==null?void 0:B.click()},onDragOver:B=>B.preventDefault(),onDrop:B=>{B.preventDefault();const R=B.dataTransfer.files[0];R&&Q({target:{files:[R],value:""}})},children:w?l.jsx("img",{src:w,alt:"Preview",className:pe.uploadPreview}):l.jsxs(l.Fragment,{children:[l.jsx(Gc,{size:32,className:pe.uploadIcon}),l.jsx("p",{className:pe.dropText,children:"Drag & drop or click to browse"}),l.jsxs("p",{className:pe.dropSubtext,children:[U.split(",").map(B=>B.replace("image/","").toUpperCase()).join(", ")," · max ",($/(1024*1024)).toFixed(0)," MB"]})]})}),l.jsx("input",{ref:N,type:"file",accept:U,className:pe.hiddenInput,onChange:Q}),b&&l.jsx("p",{className:pe.fileName,children:b.name}),P&&l.jsx("p",{className:pe.errorText,children:P})]})}),l.jsxs("div",{className:pe.footer,children:[l.jsx("button",{className:pe.cancelBtn,onClick:n,children:"Cancel"}),s==="upload"?l.jsx("button",{className:pe.confirmBtn,disabled:!b||T,onClick:J,children:T?l.jsxs(l.Fragment,{children:[l.jsx(yi,{size:14,className:pe.spinner})," Uploading…"]}):"Upload & Use"}):l.jsx("button",{className:pe.confirmBtn,disabled:!_,onClick:ce,children:"Use Selected"})]})]})})},UE=({name:e,label:t,nodeId:r,required:n,disabled:s})=>{const[i,o]=h.useState(!1),{watch:a,setValue:c,register:d,formState:{errors:u}}=Rt(),f=a(e),g=u[e],y=p=>{c(e,p,{shouldDirty:!0,shouldValidate:!0}),o(!1)},_=()=>{c(e,"",{shouldDirty:!0,shouldValidate:!0})};return l.jsxs("div",{className:L.field,children:[l.jsxs("label",{className:L.label,children:[t,n&&l.jsx("span",{className:L.required,children:"*"})]}),l.jsx("input",{type:"hidden",...d(e,{required:n?`${t} is required`:!1})}),l.jsx("div",{className:L.iconWrap,role:"button",tabIndex:s?-1:0,"aria-label":"Select app icon",onClick:()=>!s&&o(!0),onKeyDown:p=>{(p.key==="Enter"||p.key===" ")&&!s&&o(!0)},children:f?l.jsx("img",{src:f,alt:"App icon",className:L.iconPreview}):l.jsxs("div",{className:L.iconPlaceholder,children:[l.jsx(Qc,{size:20}),l.jsx("span",{children:"Select icon"})]})}),f&&!s&&l.jsxs("button",{type:"button",className:L.removeIconBtn,onClick:_,"aria-label":"Remove app icon",children:[l.jsx(Yo,{size:13}),l.jsx("span",{children:"Remove"})]}),g&&l.jsx("span",{className:L.error,children:String(g.message)}),i&&l.jsx(Dh,{nodeId:r,currentValue:f,onSelect:y,onClose:()=>o(!1)})]})},zE=({name:e,label:t,required:r,disabled:n})=>{const{control:s}=Rt(),{field:i,fieldState:{error:o}}=Zi({name:e,control:s,rules:{required:r?`${t} is required`:!1}});return l.jsxs("div",{className:L.field,children:[l.jsxs("label",{className:L.label,htmlFor:e,children:[t,r&&l.jsx("span",{className:L.required,children:"*"})]}),l.jsx("input",{id:e,type:"datetime-local",className:[L.input,o?L.inputError:""].join(" "),disabled:n,value:i.value??"",onChange:i.onChange,onBlur:i.onBlur,ref:i.ref}),o&&l.jsx("span",{className:L.error,children:String(o.message)})]})},VE=({name:e,label:t,required:r,disabled:n})=>{const{control:s}=Rt(),{field:i,fieldState:{error:o}}=Zi({name:e,control:s,rules:{required:r?`${t} is required`:!1},defaultValue:[]}),[a,c]=h.useState(""),d=h.useRef(null),u=i.value??[],f=p=>{const v=p.trim();!v||u.includes(v)||i.onChange([...u,v])},g=p=>{i.onChange(u.filter(v=>v!==p))},y=p=>{p.key==="Enter"||p.key===","?(p.preventDefault(),f(a),c("")):p.key==="Backspace"&&a===""&&u.length>0&&g(u[u.length-1])},_=()=>{a.trim()&&(f(a),c("")),i.onBlur()};return l.jsxs("div",{className:[L.field,L.fullWidth].join(" "),children:[l.jsxs("label",{className:L.label,children:[t,r&&l.jsx("span",{className:L.required,children:"*"})]}),l.jsxs("div",{className:[L.chipGroup,o?L.inputError:""].join(" "),onClick:()=>{var p;return!n&&((p=d.current)==null?void 0:p.focus())},style:{cursor:n?"not-allowed":"text"},children:[u.map(p=>l.jsxs("span",{className:L.tagChip,children:[p,!n&&l.jsx("button",{type:"button",className:L.tagChipRemove,onClick:v=>{v.stopPropagation(),g(p)},"aria-label":`Remove ${p}`,children:l.jsx(zr,{size:11})})]},p)),!n&&l.jsx("input",{ref:d,className:L.chipInput,value:a,onChange:p=>c(p.target.value),onKeyDown:y,onBlur:_,placeholder:u.length===0?"Type and press Enter or comma…":"",style:{flexGrow:1,minWidth:120}})]}),o&&l.jsx("span",{className:L.error,children:String(o.message)})]})},qE=({name:e,label:t,levels:r,required:n,disabled:s})=>{const{control:i}=Rt(),{field:o,fieldState:{error:a}}=Zi({name:e,control:i,rules:{required:n?`${t} is required`:!1},defaultValue:{}}),c=o.value??{},d=(u,f,g)=>{const y={};for(let _=0;_<f;_++)y[r[_].code]=c[r[_].code]??"";y[u]=g;for(let _=f+1;_<r.length;_++)y[r[_].code]="";o.onChange(y)};return l.jsxs("div",{className:[L.field,L.fullWidth].join(" "),children:[l.jsxs("label",{className:L.label,children:[t,n&&l.jsx("span",{className:L.required,children:"*"})]}),l.jsx("div",{className:L.nestedSelectRow,children:r.map((u,f)=>{const g=f>0&&!c[r[f-1].code];return l.jsxs("div",{className:L.field,style:{flex:1},children:[l.jsx("label",{className:L.label,htmlFor:`${e}_${u.code}`,children:u.label}),l.jsxs("select",{id:`${e}_${u.code}`,className:[L.input,a?L.inputError:""].join(" "),disabled:s||g,value:c[u.code]??"",onChange:y=>d(u.code,f,y.target.value),onBlur:o.onBlur,children:[l.jsx("option",{value:"",children:"Select…"}),u.options.map(y=>l.jsx("option",{value:y.value,children:y.label},y.value))]})]},u.code)})}),a&&l.jsx("span",{className:L.error,children:String(a.message)})]})},Th=[{label:"CC BY 4.0",value:"CC BY 4.0"},{label:"CC BY-SA 4.0",value:"CC BY-SA 4.0"},{label:"CC BY-NC 4.0",value:"CC BY-NC 4.0"},{label:"CC BY-NC-SA 4.0",value:"CC BY-NC-SA 4.0"},{label:"CC BY-ND 4.0",value:"CC BY-ND 4.0"},{label:"CC0 1.0 (Public Domain)",value:"CC0 1.0"}],HE=({name:e,label:t,required:r,disabled:n})=>{const[s,i]=h.useState(!1),o=h.useRef(null),{register:a,watch:c,setValue:d,formState:{errors:u}}=Rt(),f=c(e),g=Th.find(p=>p.value===f),y=(g==null?void 0:g.label)??"Select license…",_=u[e];return h.useEffect(()=>{if(!s)return;const p=v=>{var m;(m=o.current)!=null&&m.contains(v.target)||i(!1)};return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[s]),l.jsxs("div",{className:L.field,ref:o,style:{position:"relative"},children:[l.jsxs("label",{className:L.label,children:[t,r&&l.jsx("span",{className:L.required,children:"*"})]}),l.jsx("input",{type:"hidden",...a(e,{required:r?`${t} is required`:!1})}),l.jsxs("button",{type:"button",disabled:n,className:[L.selectBtn,_?L.inputError:"",s?L.selectOpen:""].join(" "),onClick:()=>i(p=>!p),"aria-haspopup":"listbox","aria-expanded":s,children:[l.jsx("span",{className:f?L.selectedVal:L.placeholder,children:y}),l.jsx(hs,{size:14,className:s?L.chevronUp:""})]}),s&&l.jsx("div",{className:L.dropdown,role:"listbox",children:Th.map(p=>l.jsxs("button",{type:"button",role:"option","aria-selected":f===p.value,className:[L.option,f===p.value?L.optionSelected:""].join(" "),onClick:()=>{d(e,p.value,{shouldDirty:!0,shouldValidate:!0}),i(!1)},children:[l.jsx("span",{children:p.label}),f===p.value&&l.jsx(vn,{size:13})]},p.value))}),_&&l.jsx("span",{className:L.error,children:String(_.message)})]})},WE=({name:e,label:t,required:r,disabled:n})=>{const{control:s}=Rt(),{field:i,fieldState:{error:o}}=Zi({name:e,control:s,rules:{required:r?`${t} is required`:!1},defaultValue:""}),[a,c]=h.useState("idle"),[d,u]=h.useState(""),f=async()=>{const y=(i.value??"").trim();if(!y){c("invalid"),u("Enter a dial code to validate.");return}c("loading"),u("");try{const _=await o_(y),p=_==null?void 0:_.result,v=p==null?void 0:p.dialcodes;Array.isArray(v)&&v.length>0?(c("valid"),u("Dial code is valid.")):(c("invalid"),u("Dial code not found."))}catch{c("invalid"),u("Validation failed. Please try again.")}},g=()=>a==="loading"?l.jsx(yi,{size:16,className:L.dialcodeSpinner}):a==="valid"?l.jsx(Vc,{size:16,color:"var(--sbx-success, #2e7d32)"}):a==="invalid"?l.jsx(qo,{size:16,color:"var(--sbx-error)"}):null;return l.jsxs("div",{className:L.field,children:[l.jsxs("label",{className:L.label,htmlFor:e,children:[t,r&&l.jsx("span",{className:L.required,children:"*"})]}),l.jsxs("div",{className:L.dialcodeRow,children:[l.jsx("input",{id:e,type:"text",className:[L.input,o?L.inputError:""].join(" "),disabled:n,value:i.value??"",onChange:y=>{i.onChange(y),c("idle"),u("")},onBlur:i.onBlur,ref:i.ref,placeholder:"e.g. A1B2C3",style:{flex:1}}),l.jsx("button",{type:"button",className:L.validateBtn,onClick:f,disabled:n||a==="loading","aria-label":"Validate dial code",children:a==="loading"?"Validating…":"Validate"}),g()]}),o&&l.jsx("span",{className:L.error,children:String(o.message)}),!o&&d&&l.jsx("span",{className:a==="valid"?L.dialcodeValid:L.error,children:d})]})},yl={form:"_form_szqex_1",ungrouped:"_ungrouped_szqex_7",noFields:"_noFields_szqex_18"},QE=({nodeMetadata:e,activeTab:t,isRoot:r,isFolder:n,editorMode:s,onFormValueChange:i,onFormStatusChange:o})=>{var ge,$e,qe,ke,ee,Qe,tt;const a=ae(H=>H.editorConfig),c=ae(H=>H.rootFormConfig),d=ae(H=>H.unitFormConfig),u=ae(H=>H.categoryMeta),f=ae(H=>H.contentFramework),g=ae(H=>H.contentTargetFWIds),{organisationFramework:y,targetFrameworks:_,isLoading:p}=_h(f??((ge=a==null?void 0:a.context)==null?void 0:ge.framework),g??(($e=a==null?void 0:a.context)==null?void 0:$e.targetFWIds)),{frameworks:v,collectionAdditionalCategories:m,contentAdditionalCategories:b,defaultLicense:S,name:w}=aE((qe=a==null?void 0:a.context)==null?void 0:qe.channel),E=iE(v,(ke=u==null?void 0:u.frameworkMetadata)==null?void 0:ke.orgFWType,(ee=a==null?void 0:a.context)==null?void 0:ee.channel),T={organisationFramework:y,targetFrameworks:_,orgFrameworks:E,channelAdditionalCategories:m},x=xe(H=>H.selectedNodeId),P=xe(H=>H.treeData),F=xe(H=>H.treeCache),N=x?F[x]??{}:{},M={...e,...N},j=h.useMemo(()=>{var re;if(!x)return 0;const H=[...P];for(;H.length;){const oe=H.shift();if(oe.id===x)return((re=oe.children)==null?void 0:re.length)??0;oe.children&&H.push(...oe.children)}return 0},[P,x]),A=(a==null?void 0:a.config)??{},$=(a==null?void 0:a.context)??{},U={editorMode:s,editableFields:A.editableFields,objectType:A.objectType,setDefaultCopyRight:A.setDefaultCopyRight===!0,defaultLicense:$.defaultLicense??S,contextAdditionalCategories:$.additionalCategories,userFullName:(Qe=$.user)==null?void 0:Qe.fullName,channelName:w,collectionAdditionalCategories:m,contentAdditionalCategories:b,childCount:j},Z=r?c:d,se=Z||(((tt=a==null?void 0:a.config.hierarchy)==null?void 0:tt.formConfig)??[]),be=fE(se,M,T,r,U),Ee=be.filter(H=>H.tab===t&&H.inputType!=="appIcon"&&H.visible!==!1),ce=nE({mode:"onChange",defaultValues:Object.fromEntries(be.map(H=>{const re=["multiselect","chips","keywords","tagsinput"],oe=["nestedselect"];return re.includes(H.inputType)?[H.code,H.currentValue??H.defaultValue??[]]:oe.includes(H.inputType)?[H.code,H.currentValue??H.defaultValue??{}]:[H.code,H.currentValue??H.defaultValue??""]}))});kE(ce,be);const{updateNode:Q}=xe(),J=h.useRef(be);J.current=be;const ie=h.useRef(x);ie.current=x;const B=h.useRef(i);B.current=i;const R=h.useRef(o);R.current=o;const K=h.useRef(typeof M.shuffle=="boolean"?M.shuffle:void 0),de=h.useRef(M.name??"");de.current=M.name??"";const Oe=h.useRef(s);Oe.current=s;const Be=["review","read","sourcingreview","orgreview"];h.useEffect(()=>{const H=ie.current;if(H){const re=Object.fromEntries(J.current.filter(oe=>oe.currentValue!==void 0&&oe.currentValue!==null).map(oe=>[oe.code,oe.currentValue]));Object.keys(re).length>0&&Q(H,re)}ce.trigger().then(()=>{const re=ce.formState.errors,oe=J.current,Re=Array.from(new Set(Object.keys(re).map(gr=>{var yr;return(yr=oe.find(dn=>dn.code===gr))==null?void 0:yr.tab}).filter(Boolean)));R.current(Object.keys(re).length===0,Re)})},[]),h.useEffect(()=>{const H=ce.watch((re,{name:oe})=>{const Re=ie.current;if(!Re)return;const gr=J.current,yr=new Set(gr.map(C=>C.code));if(oe&&yr.has(oe)){let C=ce.getValues(oe);oe==="dialcodes"&&(C=Array.isArray(C)?C:C?[C]:[]),oe==="shuffle"&&(C===!0&&K.current===!1&&Ie("Shuffling is enabled for this question set.",{icon:"ℹ️"}),K.current=C);const D=NE(oe,C);D&&(Q(Re,D),B.current(D))}else if(!oe){const C=ce.getValues(),D=Object.fromEntries(Object.entries(C).filter(([z])=>yr.has(z))),k=TE(D,{isReview:Be.includes(Oe.current),nodeTitle:de.current});Object.keys(k).length>0&&(Q(Re,k),B.current(k))}const dn=ce.formState.errors,Yn=Array.from(new Set(Object.keys(dn).map(C=>{var D;return(D=gr.find(k=>k.code===C))==null?void 0:D.tab}).filter(Boolean)));R.current(Object.keys(dn).length===0,Yn)});return()=>H.unsubscribe()},[ce]);const ve=Ee.reduce((H,re)=>{const oe=H[H.length-1];return oe&&oe.section===re.section?oe.fields.push(re):H.push({section:re.section,fields:[re]}),H},[]),ue=H=>{const re={key:H.code,name:H.code,label:H.label,required:H.required,disabled:H.editable===!1};switch(H.inputType){case"textarea":return l.jsx(Oh,{...re,multiline:!0,maxLength:H.maxLength});case"select":return l.jsx(AE,{...re,options:H.options??[]});case"multiselect":return l.jsx(PE,{...re,options:H.options??[]});case"chips":return l.jsx(ME,{...re});case"radio":return l.jsx(LE,{...re,options:H.options??[]});case"appIcon":return l.jsx(UE,{...re,nodeId:x??""});case"datepicker":case"datetime":return l.jsx(zE,{...re});case"keywords":case"tagsinput":return l.jsx(VE,{...re});case"nestedselect":return l.jsx(qE,{...re,levels:H.levels??[]});case"license":return l.jsx(HE,{...re});case"dialcode":return l.jsx(WE,{...re});default:return l.jsx(Oh,{...re,maxLength:H.maxLength})}};return l.jsx(V1,{...ce,children:l.jsxs("div",{className:yl.form,children:[ve.map((H,re)=>{const oe=H.section?lE[H.section]:void 0;return oe?l.jsx(xE,{title:oe.title,description:oe.description,children:H.fields.map(ue)},H.section??re):l.jsx("div",{className:yl.ungrouped,children:H.fields.map(ue)},re)}),Ee.length===0&&!p&&l.jsx("p",{className:yl.noFields,children:"No fields configured for this tab."})]})})};function Nh(e,t,r){const n=e.slice();return n.splice(r<0?n.length+r:r,0,n.splice(t,1)[0]),n}function KE(e,t){return e.reduce((r,n,s)=>{const i=t.get(n);return i&&(r[s]=i),r},Array(e.length))}function no(e){return e!==null&&e>=0}function GE(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(e[r]!==t[r])return!1;return!0}function YE(e){return typeof e=="boolean"?{draggable:e,droppable:e}:e}const kh=e=>{let{rects:t,activeIndex:r,overIndex:n,index:s}=e;const i=Nh(t,n,r),o=t[s],a=i[s];return!a||!o?null:{x:a.left-o.left,y:a.top-o.top,scaleX:a.width/o.width,scaleY:a.height/o.height}},so={scaleX:1,scaleY:1},RE=e=>{var t;let{activeIndex:r,activeNodeRect:n,index:s,rects:i,overIndex:o}=e;const a=(t=i[r])!=null?t:n;if(!a)return null;if(s===r){const d=i[o];return d?{x:0,y:r<o?d.top+d.height-(a.top+a.height):d.top-a.top,...so}:null}const c=XE(i,s,r);return s>r&&s<=o?{x:0,y:-a.height-c,...so}:s<r&&s>=o?{x:0,y:a.height+c,...so}:{x:0,y:0,...so}};function XE(e,t,r){const n=e[t],s=e[t-1],i=e[t+1];return n?r<t?s?n.top-(s.top+s.height):i?i.top-(n.top+n.height):0:i?i.top-(n.top+n.height):s?n.top-(s.top+s.height):0:0}const xh="Sortable",Ah=h.createContext({activeIndex:-1,containerId:xh,disableTransforms:!1,items:[],overIndex:-1,useDragOverlay:!1,sortedRects:[],strategy:kh,disabled:{draggable:!1,droppable:!1}});function ZE(e){let{children:t,id:r,items:n,strategy:s=kh,disabled:i=!1}=e;const{active:o,dragOverlay:a,droppableRects:c,over:d,measureDroppableContainers:u}=jc(),f=os(xh,r),g=a.rect!==null,y=h.useMemo(()=>n.map(T=>typeof T=="object"&&"id"in T?T.id:T),[n]),_=o!=null,p=o?y.indexOf(o.id):-1,v=d?y.indexOf(d.id):-1,m=h.useRef(y),b=!GE(y,m.current),S=v!==-1&&p===-1||b,w=YE(i);Wt(()=>{b&&_&&u(y)},[b,y,_,u]),h.useEffect(()=>{m.current=y},[y]);const E=h.useMemo(()=>({activeIndex:p,containerId:f,disabled:w,disableTransforms:S,items:y,overIndex:v,useDragOverlay:g,sortedRects:KE(y,c),strategy:s}),[p,f,w.draggable,w.droppable,S,y,v,c,g,s]);return h.createElement(Ah.Provider,{value:E},t)}const JE=e=>{let{id:t,items:r,activeIndex:n,overIndex:s}=e;return Nh(r,n,s).indexOf(t)},eO=e=>{let{containerId:t,isSorting:r,wasDragging:n,index:s,items:i,newIndex:o,previousItems:a,previousContainerId:c,transition:d}=e;return!d||!n||a!==i&&s===o?!1:r?!0:o!==s&&t===c},tO={duration:200,easing:"ease"},Ph="transform",rO=Er.Transition.toString({property:Ph,duration:0,easing:"linear"}),nO={roleDescription:"sortable"};function sO(e){let{disabled:t,index:r,node:n,rect:s}=e;const[i,o]=h.useState(null),a=h.useRef(r);return Wt(()=>{if(!t&&r!==a.current&&n.current){const c=s.current;if(c){const d=yn(n.current,{ignoreTransform:!0}),u={x:c.left-d.left,y:c.top-d.top,scaleX:c.width/d.width,scaleY:c.height/d.height};(u.x||u.y)&&o(u)}}r!==a.current&&(a.current=r)},[t,r,n,s]),h.useEffect(()=>{i&&o(null)},[i]),i}function iO(e){let{animateLayoutChanges:t=eO,attributes:r,disabled:n,data:s,getNewIndex:i=JE,id:o,strategy:a,resizeObserverConfig:c,transition:d=tO}=e;const{items:u,containerId:f,activeIndex:g,disabled:y,disableTransforms:_,sortedRects:p,overIndex:v,useDragOverlay:m,strategy:b}=h.useContext(Ah),S=oO(n,y),w=u.indexOf(o),E=h.useMemo(()=>({sortable:{containerId:f,index:w,items:u},...s}),[f,s,w,u]),T=h.useMemo(()=>u.slice(u.indexOf(o)),[u,o]),{rect:x,node:P,isOver:F,setNodeRef:N}=tv({id:o,data:E,disabled:S.droppable,resizeObserverConfig:{updateMeasurementsFor:T,...c}}),{active:M,activatorEvent:j,activeNodeRect:A,attributes:$,setNodeRef:U,listeners:Z,isDragging:se,over:be,setActivatorNodeRef:Ee,transform:ce}=$c({id:o,data:E,attributes:{...nO,...r},disabled:S.draggable}),Q=Ug(N,U),J=!!M,ie=J&&!_&&no(g)&&no(v),B=!m&&se,R=B&&ie?ce:null,de=ie?R??(a??b)({rects:p,activeNodeRect:A,activeIndex:g,overIndex:v,index:w}):null,Oe=no(g)&&no(v)?i({id:o,items:u,activeIndex:g,overIndex:v}):w,Be=M==null?void 0:M.id,ve=h.useRef({activeId:Be,items:u,newIndex:Oe,containerId:f}),ue=u!==ve.current.items,ge=t({active:M,containerId:f,isDragging:se,isSorting:J,id:o,index:w,items:u,newIndex:ve.current.newIndex,previousItems:ve.current.items,previousContainerId:ve.current.containerId,transition:d,wasDragging:ve.current.activeId!=null}),$e=sO({disabled:!ge,index:w,node:P,rect:x});return h.useEffect(()=>{J&&ve.current.newIndex!==Oe&&(ve.current.newIndex=Oe),f!==ve.current.containerId&&(ve.current.containerId=f),u!==ve.current.items&&(ve.current.items=u)},[J,Oe,f,u]),h.useEffect(()=>{if(Be===ve.current.activeId)return;if(Be&&!ve.current.activeId){ve.current.activeId=Be;return}const ke=setTimeout(()=>{ve.current.activeId=Be},50);return()=>clearTimeout(ke)},[Be]),{active:M,activeIndex:g,attributes:$,data:E,rect:x,index:w,newIndex:Oe,items:u,isOver:F,isSorting:J,isDragging:se,listeners:Z,node:P,overIndex:v,over:be,setNodeRef:Q,setActivatorNodeRef:Ee,setDroppableNodeRef:N,setDraggableNodeRef:U,transform:$e??de,transition:qe()};function qe(){if($e||ue&&ve.current.newIndex===w)return rO;if(!(B&&!ai(j)||!d)&&(J||ge))return Er.Transition.toString({...d,property:Ph})}}function oO(e,t){var r,n;return typeof e=="boolean"?{draggable:e,droppable:!1}:{draggable:(r=e==null?void 0:e.draggable)!=null?r:t.draggable,droppable:(n=e==null?void 0:e.droppable)!=null?n:t.droppable}}function io(e){if(!e)return!1;const t=e.data.current;return!!(t&&"sortable"in t&&typeof t.sortable=="object"&&"containerId"in t.sortable&&"items"in t.sortable&&"index"in t.sortable)}const aO=[Se.Down,Se.Right,Se.Up,Se.Left],lO=(e,t)=>{let{context:{active:r,collisionRect:n,droppableRects:s,droppableContainers:i,over:o,scrollableAncestors:a}}=t;if(aO.includes(e.code)){if(e.preventDefault(),!r||!n)return;const c=[];i.getEnabled().forEach(f=>{if(!f||f!=null&&f.disabled)return;const g=s.get(f.id);if(g)switch(e.code){case Se.Down:n.top<g.top&&c.push(f);break;case Se.Up:n.top>g.top&&c.push(f);break;case Se.Left:n.left>g.left&&c.push(f);break;case Se.Right:n.left<g.left&&c.push(f);break}});const d=ny({collisionRect:n,droppableRects:s,droppableContainers:c});let u=cc(d,"id");if(u===(o==null?void 0:o.id)&&d.length>1&&(u=d[1].id),u!=null){const f=i.get(r.id),g=i.get(u),y=g?s.get(g.id):null,_=g==null?void 0:g.node.current;if(_&&y&&f&&g){const v=ui(_).some((T,x)=>a[x]!==T),m=Mh(f,g),b=cO(f,g),S=v||!m?{x:0,y:0}:{x:b?n.width-y.width:0,y:b?n.height-y.height:0},w={x:y.left,y:y.top};return S.x&&S.y?w:as(w,S)}}}};function Mh(e,t){return!io(e)||!io(t)?!1:e.data.current.sortable.containerId===t.data.current.sortable.containerId}function cO(e,t){return!io(e)||!io(t)||!Mh(e,t)?!1:e.data.current.sortable.index<t.data.current.sortable.index}const Zr={row:"_row_11nth_1",removeBtn:"_removeBtn_11nth_14",grip:"_grip_11nth_17",ctIcon:"_ctIcon_11nth_34",info:"_info_11nth_38",name:"_name_11nth_46",meta:"_meta_11nth_55"},uO={video:Ro,pdf:Ho,h5p:Wo,scorm:Ko,audio:Qo,quiz:Vo,default:mn},dO=({item:e,onRemove:t,isEditable:r})=>{const n=Yi(e),s=uO[n.key]??mn,{attributes:i,listeners:o,setNodeRef:a,transform:c,transition:d,isDragging:u}=iO({id:e.id,disabled:!r}),f={transform:Er.Transform.toString(c),transition:d,opacity:u?.5:1};return l.jsxs("div",{ref:a,style:f,className:Zr.row,role:"listitem",children:[r&&l.jsx("span",{className:Zr.grip,...i,...o,"aria-label":"Drag to reorder",children:l.jsx(Wc,{size:15})}),l.jsx("span",{className:[`sbx-ct-sq--${n.key}`,Zr.ctIcon].join(" "),"aria-hidden":"true",children:l.jsx(s,{size:14})}),l.jsxs("div",{className:Zr.info,children:[l.jsx("span",{className:Zr.name,title:e.name,children:e.name}),l.jsx("span",{className:Zr.meta,children:n.label})]}),l.jsx("span",{className:`sbx-ct-badge--${n.key}`,children:n.label}),r&&l.jsx("button",{type:"button",className:Zr.removeBtn,onClick:()=>t(e.id),"aria-label":`Remove ${e.name}`,children:l.jsx(zr,{size:14})})]})},Jr={container:"_container_lzvke_1",header:"_header_lzvke_7",heading:"_heading_lzvke_13",count:"_count_lzvke_21",list:"_list_lzvke_30",emptyState:"_emptyState_lzvke_36",addRow:"_addRow_lzvke_52"},fO=({editorMode:e})=>{const{selectedNodeId:t,getChildrenOf:r,reorderChildren:n,deleteNode:s}=xe(),i=t?r(t):[],o=e==="edit",a=ic(xo(di,{activationConstraint:{distance:5}}),xo(Fo,{coordinateGetter:lO})),c=h.useCallback(u=>{const{active:f,over:g}=u;if(!g||f.id===g.id||!t)return;const y=xe.getState().getChildrenOf(t),_=y.findIndex(v=>v.id===f.id),p=y.findIndex(v=>v.id===g.id);_<0||p<0||n(t,_,p)},[t,n]),d=h.useCallback(u=>{window.confirm("Remove this content from the unit?")&&s(u)},[s]);return t?l.jsxs("div",{className:Jr.container,children:[l.jsxs("div",{className:Jr.header,children:[l.jsx("span",{className:Jr.heading,children:"Content in this unit"}),l.jsx("span",{className:Jr.count,children:i.length})]}),i.length>0?l.jsx(Lc,{sensors:a,collisionDetection:ry,onDragEnd:c,children:l.jsx(ZE,{items:i.map(u=>u.id),strategy:RE,children:l.jsx("div",{className:Jr.list,role:"list",children:i.map(u=>l.jsx(dO,{item:u,onRemove:d,isEditable:o},u.id))})})}):l.jsxs("div",{className:Jr.emptyState,children:[l.jsx("p",{children:"No content yet"}),l.jsx("span",{children:"Drag from the library or click Add content"})]}),o&&l.jsxs("button",{className:Jr.addRow,type:"button","aria-label":"Add content to unit",children:[l.jsx(ps,{size:14})," Add content"]})]}):null},Lh={dropZone:"_dropZone_ijo5w_1",active:"_active_ijo5w_14"},hO=({isActive:e,label:t="Drop here",nodeId:r,className:n})=>l.jsx("div",{className:`${Lh.dropZone} ${e?Lh.active:""} ${n??""}`,"data-droppable":e?"true":void 0,"data-node-id":r,"aria-label":t,role:"region",children:l.jsx("span",{children:t})});async function pO(e){var o;const t={status:["Live"],...e.filters??{}};e.channel&&(t.channel=e.channel);const n=((o=(await Ae.post("/action/composite/v3/search",{request:{filters:t,query:e.query??"",limit:e.limit??20,offset:e.offset??0,sort_by:e.sortBy??{lastUpdatedOn:"desc"},fields:e.fields??["identifier","name","mimeType","contentType","primaryCategory","appIcon","channel","organisation","pkgVersion"]}},{headers:{"X-Source":"web","X-msgid":Math.random().toString(36).slice(2)}})).data)==null?void 0:o.result)??{},s=new Set(["count","facets"]);return{content:Object.entries(n).filter(([a])=>!s.has(a)).flatMap(([,a])=>Array.isArray(a)?a:[]),count:n.count??0}}async function gO(e){var r,n;return(n=(r=(await Ae.get(`/action/content/v3/read/${e}`)).data)==null?void 0:r.result)==null?void 0:n.content}const Fh="application/vnd.sunbird.question";function $h(e){return{cardinality:"single",type:"integer",defaultValue:e.maxScore??1}}function jh(e,t,r){if(!e)return null;if(e.identifier===t)return{question:e,parent:r};for(const n of e.children??[]){const s=jh(n,t,e);if(s)return s}return null}function yO(e,t){const r=jh(e,t);if(!r)return null;const{question:n,parent:s}=r,i={...e,children:[n],childNodes:[t],shuffle:s==null?void 0:s.shuffle,showSolutions:(s==null?void 0:s.showSolutions)??"No",showFeedback:(s==null?void 0:s.showFeedback)??"No"};return(s==null?void 0:s.shuffle)===!0?i.maxScore=1:n.qType==="SA"?delete i.maxScore:n.maxScore!=null&&(i.maxScore=n.maxScore),i}function vO(e,t){const r=((t==null?void 0:t.enabled)??!0)&&!!e;return ts({queryKey:["quml","questionset",e],enabled:r,queryFn:async()=>{const n=await Xu(e),s=u=>{if(!u)return[];const f=u.mimeType===Fh&&u.identifier?[u.identifier]:[],g=(u.children??[]).flatMap(s);return[...f,...g]},i=s(n),o=new Map;i.length&&(await Xb(i)).forEach(f=>{const g=f.identifier;g&&o.set(g,f)});const a=u=>{if(!u)return u;if(u.mimeType===Fh&&u.identifier){const f=o.get(u.identifier)??u,g=f.outcomeDeclaration;return g!=null&&g.maxScore||(f.outcomeDeclaration={...g??{},maxScore:$h(f)}),f}return Array.isArray(u.children)&&(u.children=u.children.map(f=>a(f))),u},c=a(n),d=c.outcomeDeclaration;return d!=null&&d.maxScore||(c.outcomeDeclaration={...d??{},maxScore:$h(c)}),c}})}const Bh="/assets/quml-player/sunbird-quml-player.js",mO="/assets/quml-player/styles.css",bO="/action/question/v2/list",Uh="sunbird-quml-player",ot=class ot{constructor(){Ks(this,"eventHandlers",new WeakMap)}loadScript(){return ot.scriptLoaded||customElements.get(Uh)?(ot.scriptLoaded=!0,Promise.resolve()):(ot.scriptLoading||(ot.scriptLoading=new Promise((t,r)=>{const n=document.createElement("script");n.src=Bh,n.setAttribute("data-quml-player-script","true"),n.onload=()=>{ot.scriptLoaded=!0,ot.scriptLoading=void 0,t()},n.onerror=()=>{ot.scriptLoading=void 0,r(new Error(`Failed to load QuML player script: ${Bh}`))},document.body.appendChild(n)})),ot.scriptLoading)}loadStyles(){if(window.questionListUrl=bO,ot.stylesLoaded||document.querySelector('[data-quml-player-styles="true"]')){ot.stylesLoaded=!0;return}const t=document.createElement("link");t.rel="stylesheet",t.href=mO,t.setAttribute("data-quml-player-styles","true"),document.head.appendChild(t),ot.stylesLoaded=!0}static unloadStyles(){var t;(t=document.querySelector('[data-quml-player-styles="true"]'))==null||t.remove(),ot.stylesLoaded=!1}async createConfig(t,r,n){var o,a,c;await this.loadScript();const s={...t};return n!=null&&n.singleQuestion&&(s.maxQuestions=1,s.showStartPage="No",s.showTimer="No",s.requiresSubmit="No"),{context:{mode:(n==null?void 0:n.mode)??"play",pdata:{id:((o=r==null?void 0:r.pdata)==null?void 0:o.id)??"sunbird.portal",ver:((a=r==null?void 0:r.pdata)==null?void 0:a.ver)??"1.0",pid:((c=r==null?void 0:r.pdata)==null?void 0:c.pid)??"sunbird-portal"},contentId:t.identifier??"",sid:(r==null?void 0:r.sid)??"",uid:(r==null?void 0:r.uid)??(r==null?void 0:r.userId)??"",channel:(r==null?void 0:r.channel)??"",did:(r==null?void 0:r.did)??"",tags:(r==null?void 0:r.tags)??[],contextRollup:(n==null?void 0:n.contextRollup)??(r==null?void 0:r.rollup)??{},objectRollup:(n==null?void 0:n.objectRollup)??{},...n!=null&&n.cdata?{cdata:n.cdata}:{},...n!=null&&n.singleQuestion?{threshold:1}:{}},config:{sideMenu:{enable:!1,showShare:!1,showDownload:!1,showReplay:!0,showExit:!1},...n!=null&&n.singleQuestion?{showLegend:!1}:{}},metadata:s}}createElement(t){this.loadStyles();const r=document.createElement(Uh);return r.setAttribute("player-config",JSON.stringify(t)),r.setAttribute("data-player-id",t.metadata.identifier??"quml"),r}attachEventListeners(t,r,n){this.removeEventListeners(t);const s=o=>r==null?void 0:r(o),i=o=>n==null?void 0:n(o.detail);t.addEventListener("playerEvent",s),t.addEventListener("telemetryEvent",i),this.eventHandlers.set(t,{player:s,telemetry:i})}removeEventListeners(t){const r=this.eventHandlers.get(t);r&&(t.removeEventListener("playerEvent",r.player),t.removeEventListener("telemetryEvent",r.telemetry),this.eventHandlers.delete(t))}};Ks(ot,"scriptLoaded",!1),Ks(ot,"scriptLoading"),Ks(ot,"stylesLoaded",!1);let oo=ot;const ao=new oo,ze={contentPlayerRoot:"_contentPlayerRoot_ryh6z_1",stage:"_stage_ryh6z_9",playerHeader:"_playerHeader_ryh6z_19",playerHeaderThumb:"_playerHeaderThumb_ryh6z_33",playerHeaderTitle:"_playerHeaderTitle_ryh6z_43",typeBadge:"_typeBadge_ryh6z_53",typeDot:"_typeDot_ryh6z_92",aspectRatio:"_aspectRatio_ryh6z_99",playerFrame:"_playerFrame_ryh6z_112",coverOverlay:"_coverOverlay_ryh6z_120",coverHidden:"_coverHidden_ryh6z_132",coverThumb:"_coverThumb_ryh6z_137",coverPlayRing:"_coverPlayRing_ryh6z_146",coverPlayIcon:"_coverPlayIcon_ryh6z_159",coverLabel:"_coverLabel_ryh6z_168",coverSkeleton:"_coverSkeleton_ryh6z_174",playerWrapper:"_playerWrapper_ryh6z_200",infoStrip:"_infoStrip_ryh6z_210",infoChip:"_infoChip_ryh6z_226",infoChipLabel:"_infoChipLabel_ryh6z_245",infoChipIcon:"_infoChipIcon_ryh6z_254",playerError:"_playerError_ryh6z_260",playerErrorIcon:"_playerErrorIcon_ryh6z_274",playerErrorMsg:"_playerErrorMsg_ryh6z_279",qumlRoot:"_qumlRoot_ryh6z_286"},_O="application/vnd.sunbird.questionset";function wO(e,t){const r=new Map,n=i=>{for(const o of i)r.set(o.id,o),o.children&&n(o.children)};n(e);let s=r.get(t);for(;s;){if(s.mimeType===_O)return s.identifier;s=s.parent?r.get(s.parent):void 0}return null}const SO=[{key:"video",mimes:["video/mp4","video/webm","video/ogg"],label:"Video",icon:"🎬"},{key:"audio",mimes:["audio/mp3","audio/mpeg","audio/ogg","audio/wav"],label:"Audio",icon:"🎵"},{key:"pdf",mimes:["application/pdf"],label:"PDF",icon:"📄"},{key:"epub",mimes:["application/epub"],label:"ePub",icon:"📖"},{key:"ecml",mimes:["application/vnd.ekstep.ecml-archive"],label:"ECML",icon:"✏️"},{key:"h5p",mimes:["application/vnd.ekstep.h5p-archive"],label:"H5P",icon:"🎮"},{key:"scorm",mimes:["application/vnd.ekstep.content-collection"],label:"SCORM",icon:"📦"}];function CO(e){return SO.find(t=>t.mimes.includes(e))??{key:"other",label:"Content",icon:"📱"}}const EO={"pdf-player":["application/pdf"],"video-player":["video/mp4","video/webm"],"epub-player":["application/epub"]},OO={"pdf-player":"/assets/sunbird-pdf-player.js","video-player":"/assets/sunbird-video-player.js","epub-player":"/assets/sunbird-epub-player.js"},IO={"pdf-player":"sunbird-pdf-player","video-player":"sunbird-video-player","epub-player":"sunbird-epub-player"},DO="/content/preview/preview.html?webview=true&build_number=2.8.0.e552fcd";function vl(e){for(const[t,r]of Object.entries(EO))if(r.includes(e))return t;return"default-player"}function TO(e,t,r){var i;const n=r==null?void 0:r.context,s=t.mimeType??e.mimeType??"";return{context:{mode:"play",partner:[],pdata:{id:((i=n==null?void 0:n.pdata)==null?void 0:i.id)??"sunbird.portal",ver:1,pid:"sunbird-portal"},contentId:e.identifier,sid:(n==null?void 0:n.sid)??"",uid:(n==null?void 0:n.uid)??"",channel:(n==null?void 0:n.channel)??"",did:(n==null?void 0:n.did)??"",timeDiff:0,contextRollup:{},tags:[],app:[(n==null?void 0:n.channel)??""],dims:""},config:{showEndPage:!1,showStartPage:!0,host:"",overlay:{showUser:!1},splash:{text:"",icon:"",bgImage:"",webLink:""},sideMenu:{showDownload:!0,showExit:!1,showShare:!0},apislug:"/action",repos:["/sunbird-plugins/renderer"],plugins:[{id:"org.sunbird.iframeEvent",ver:1,type:"plugin"},{id:"org.sunbird.player.endpage",ver:1.1,type:"plugin"}],enableTelemetryValidation:!1},metadata:t,data:s==="application/vnd.ekstep.ecml-archive"?t.body??{}:{}}}function NO(e){return document.querySelector(`script[src="${e}"]`)?Promise.resolve():new Promise((t,r)=>{const n=document.createElement("script");n.src=e,n.onload=()=>t(),n.onerror=()=>r(new Error(`Failed to load ${e}`)),document.head.appendChild(n)})}async function kO(e,t,r=100){await NO(OO[t]??""),!customElements.get(e)&&await new Promise((n,s)=>{let i=0;const o=setInterval(()=>{i++,customElements.get(e)?(clearInterval(o),n()):i>=r&&(clearInterval(o),s(new Error(`Custom element <${e}> did not register`)))},100)})}const xO=[{key:"author",label:"Author",icon:"👤"},{key:"license",label:"License",icon:"⚖️"},{key:"language",label:"Language",icon:"🌐"},{key:"gradeLevel",label:"Class",icon:"🏫"},{key:"subject",label:"Subject",icon:"📚"},{key:"contentType",label:"Type",icon:"🏷️"}];function AO({node:e}){const t=e.metadata??{},r=xO.flatMap(n=>{const s=t[n.key];if(!s)return[];const i=Array.isArray(s)?s.join(", "):String(s);return i?[{...n,val:i}]:[]});return r.length?l.jsx("div",{className:ze.infoStrip,children:r.map(n=>l.jsxs("div",{className:ze.infoChip,children:[n.icon&&l.jsx("span",{className:ze.infoChipIcon,children:n.icon}),l.jsx("span",{className:ze.infoChipLabel,children:n.label}),n.val]},n.key))}):null}function zh({node:e,hidden:t}){var n;const r=e.appIcon??((n=e.metadata)==null?void 0:n.appIcon);return l.jsx("div",{className:`${ze.coverOverlay} ${t?ze.coverHidden:""}`,children:r?l.jsxs(l.Fragment,{children:[l.jsx("img",{src:r,alt:e.name,className:ze.coverThumb}),l.jsx("div",{className:ze.coverPlayRing,children:l.jsx("div",{className:ze.coverPlayIcon})}),l.jsx("span",{className:ze.coverLabel,children:"Loading preview…"})]}):l.jsx("div",{className:ze.coverSkeleton})})}function Vh({message:e}){return l.jsxs("div",{className:ze.playerError,children:[l.jsx("span",{className:ze.playerErrorIcon,children:"⚠"}),l.jsx("span",{className:ze.playerErrorMsg,children:e})]})}function PO({mimeType:e}){const t=CO(e);return l.jsxs("span",{className:ze.typeBadge,"data-type":t.key,children:[l.jsx("span",{className:ze.typeDot}),t.label]})}const ml=({node:e,editorMode:t,type:r,singleQuestion:n})=>{var i;if(r==="quml")return l.jsx(LO,{node:e,editorMode:t,singleQuestion:!!n});const s=e.appIcon??((i=e.metadata)==null?void 0:i.appIcon);return l.jsxs("div",{className:ze.contentPlayerRoot,children:[l.jsxs("div",{className:ze.stage,children:[l.jsxs("div",{className:ze.playerHeader,children:[s&&l.jsx("img",{src:s,alt:"",className:ze.playerHeaderThumb}),l.jsx("span",{className:ze.playerHeaderTitle,children:e.name}),l.jsx(PO,{mimeType:e.mimeType??""})]}),l.jsx(MO,{node:e})]}),l.jsx(AO,{node:e})]})};function MO({node:e}){var v;const t=ae(m=>m.editorConfig),[r,n]=h.useState(()=>vl(e.mimeType??"")),[s,i]=h.useState(!1),[o,a]=h.useState(null),[c,d]=h.useState(e.metadata??{}),[u,f]=h.useState(!1),g=h.useRef(null),y=h.useRef(null),_=((v=t==null?void 0:t.config)==null?void 0:v.previewCdnUrl)??DO;h.useEffect(()=>{let m=!1;return f(!1),i(!1),a(null),d(e.metadata??{}),n(vl(e.mimeType??"")),gO(e.identifier).then(b=>{if(m)return;const S={...e.metadata??{},...b};d(S);const w=b.mimeType??e.mimeType??"";n(vl(w)),f(!0)}).catch(()=>{m||f(!0)}),()=>{m=!0}},[e.identifier]);const p=TO(e,c,t);return h.useEffect(()=>{if(!u||r!=="default-player")return;const m=g.current;if(!m)return;m.src=_;const b=()=>{try{const w=m.contentWindow;if(typeof(w==null?void 0:w.initializePreview)!="function"){a("Preview player unavailable. Check that /content/preview is reachable.");return}w.initializePreview(p),setTimeout(()=>i(!0),300)}catch(w){console.error("[ContentPlayer] initializePreview failed",w),a("Failed to initialize the content player.")}},S=()=>a("Preview player could not be loaded.");return m.addEventListener("load",b),m.addEventListener("error",S),()=>{m.removeEventListener("load",b),m.removeEventListener("error",S),m.src=""}},[e.identifier,r,_,u]),h.useEffect(()=>{if(!u||r==="default-player")return;const m=y.current;if(!m)return;const b=IO[r];if(!b)return;const S=p;kO(b,r).then(()=>{if(!y.current)return;if(!customElements.get(b)){n("default-player");return}const w=document.createElement(b);w.setAttribute("player-config",JSON.stringify(S)),w.addEventListener("playerEvent",()=>{}),w.addEventListener("telemetryEvent",()=>{}),m.innerHTML="",m.appendChild(w),setTimeout(()=>{try{w.playerConfig=S}catch{}i(!0)},200)}).catch(()=>{console.warn(`[ContentPlayer] ${r} script unavailable, falling back to iframe`),n("default-player")})},[e.identifier,r,u]),l.jsxs("div",{className:ze.aspectRatio,children:[o?l.jsx(Vh,{message:o}):l.jsx(zh,{node:e,hidden:s}),r==="default-player"?l.jsx("iframe",{ref:g,id:"contentPlayer",title:e.name,className:ze.playerFrame,name:"contentPlayer",allowFullScreen:!0}):l.jsx("div",{ref:y,className:ze.playerFrame})]})}function LO({node:e,editorMode:t,singleQuestion:r}){const n=ae(g=>g.editorConfig),s=xe(g=>g.treeData),i=h.useRef(null),o=r?wO(s,e.id):e.identifier,{data:a,isLoading:c,error:d}=vO(o??"",{enabled:!!o}),u=h.useMemo(()=>a?r?yO(a,e.identifier):a:null,[a,r,e.identifier]);h.useEffect(()=>{const g=i.current;if(!g||!u)return;let y=null,_=!1;return(async()=>{try{const p=await ao.createConfig(u,n==null?void 0:n.context,{mode:t==="edit"?"edit":"play",singleQuestion:r});if(_||!i.current)return;const v=ao.createElement(p);y=v,ao.attachEventListeners(v,m=>console.debug("[QumlPlayer] playerEvent",m.detail),m=>console.debug("[QumlPlayer] telemetryEvent",m)),g.innerHTML="",g.appendChild(v)}catch(p){console.error("[QumlPlayer] failed to initialize",p)}})(),()=>{_=!0,y&&(ao.removeEventListeners(y),y.remove()),oo.unloadStyles()}},[u,n,t,r]);const f=d?`Unable to load questionset: ${d.message}`:r&&!o?"Could not resolve the parent questionset for this question.":r&&a&&!u?"Question not found in the questionset.":null;return l.jsxs("div",{className:ze.qumlRoot,children:[f?l.jsx(Vh,{message:f}):c||!u?l.jsx(zh,{node:e,hidden:!1}):null,l.jsx("div",{ref:i,className:ze.playerWrapper})]})}const Vt={overlay:"_overlay_ifddx_1",modal:"_modal_ifddx_11",header:"_header_ifddx_21",body:"_body_ifddx_37",hint:"_hint_ifddx_43",list:"_list_ifddx_49",item:"_item_ifddx_55",selected:"_selected_ifddx_68",empty:"_empty_ifddx_73",footer:"_footer_ifddx_79",cancelBtn:"_cancelBtn_ifddx_87",moveBtn:"_moveBtn_ifddx_95"};function FO(e,t,r){const n=[],s=i=>{var o;for(const a of i)a.isFolder&&a.id!==r&&a.id!==t&&n.push(a),(o=a.children)!=null&&o.length&&s(a.children)};return s(e),n}const $O=({resourceId:e,resourceName:t,currentUnitId:r,onClose:n})=>{var u;const{treeData:s,moveNode:i}=xe(),o=FO(s,((u=s[0])==null?void 0:u.id)??"",r),[a,c]=h.useState(null),d=()=>{a&&(i(e,r,a),n())};return l.jsx("div",{className:Vt.overlay,role:"dialog","aria-label":"Move resource",children:l.jsxs("div",{className:Vt.modal,children:[l.jsxs("div",{className:Vt.header,children:[l.jsxs("span",{children:['Move "',t,'"']}),l.jsx("button",{onClick:n,"aria-label":"Close",children:l.jsx(zr,{size:16})})]}),l.jsxs("div",{className:Vt.body,children:[l.jsx("p",{className:Vt.hint,children:"Select a unit to move this content to:"}),l.jsxs("ul",{className:Vt.list,children:[o.map(f=>l.jsxs("li",{className:`${Vt.item} ${a===f.id?Vt.selected:""}`,onClick:()=>c(f.id),children:[l.jsx(Sv,{size:14}),l.jsx("span",{children:f.name})]},f.id)),o.length===0&&l.jsx("li",{className:Vt.empty,children:"No other units available"})]})]}),l.jsxs("div",{className:Vt.footer,children:[l.jsx("button",{className:Vt.cancelBtn,onClick:n,children:"Cancel"}),l.jsx("button",{className:Vt.moveBtn,onClick:d,disabled:!a,children:"Move here"})]})]})})},nr={overlay:"_overlay_16at9_1",modal:"_modal_16at9_11",header:"_header_16at9_21",body:"_body_16at9_37",table:"_table_16at9_43",pageInput:"_pageInput_16at9_61",empty:"_empty_16at9_68",footer:"_footer_16at9_74",cancelBtn:"_cancelBtn_16at9_82",saveBtn:"_saveBtn_16at9_90"};function jO(e){const t=[],r=n=>{var s;for(const i of n)!i.isFolder&&(!i.children||i.children.length===0)?t.push(i):(s=i.children)!=null&&s.length&&r(i.children)};return r(e),t}const BO=({onClose:e})=>{const{treeData:t,updateNode:r}=xe(),n=jO(t),[s,i]=h.useState(()=>Object.fromEntries(n.map(a=>{var c;return[a.id,String(((c=a.metadata)==null?void 0:c.pageNumber)??"")]}))),o=h.useCallback(()=>{for(const[a,c]of Object.entries(s))c!==""&&r(a,{pageNumber:parseInt(c,10)||void 0});e()},[s,r,e]);return l.jsx("div",{className:nr.overlay,role:"dialog","aria-label":"Assign Page Numbers",children:l.jsxs("div",{className:nr.modal,children:[l.jsxs("div",{className:nr.header,children:[l.jsx("span",{children:"Assign Page Numbers"}),l.jsx("button",{onClick:e,"aria-label":"Close",children:l.jsx(zr,{size:16})})]}),l.jsx("div",{className:nr.body,children:n.length===0?l.jsx("p",{className:nr.empty,children:"No content items found in this collection."}):l.jsxs("table",{className:nr.table,children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{children:"Content"}),l.jsx("th",{children:"Page Number"})]})}),l.jsx("tbody",{children:n.map(a=>l.jsxs("tr",{children:[l.jsx("td",{children:a.name}),l.jsx("td",{children:l.jsx("input",{type:"number",min:1,value:s[a.id]??"",onChange:c=>i(d=>({...d,[a.id]:c.target.value})),className:nr.pageInput})})]},a.id))})]})}),l.jsxs("div",{className:nr.footer,children:[l.jsx("button",{className:nr.cancelBtn,onClick:e,children:"Cancel"}),l.jsxs("button",{className:nr.saveBtn,onClick:o,children:[l.jsx(xv,{size:14})," Save"]})]})]})})},We={container:"_container_1a7t2_1",panelHeader:"_panelHeader_1a7t2_10",panelHeaderLeft:"_panelHeaderLeft_1a7t2_19",panelCollapseBtn:"_panelCollapseBtn_1a7t2_27",titleRow:"_titleRow_1a7t2_46",field:"_field_1a7t2_47",moveBtn:"_moveBtn_1a7t2_64",icon:"_icon_1a7t2_84",nameInput:"_nameInput_1a7t2_93",fieldHeader:"_fieldHeader_1a7t2_118",label:"_label_1a7t2_124",fieldCount:"_fieldCount_1a7t2_133",chips:"_chips_1a7t2_170",chip:"_chip_1a7t2_170",chipRemove:"_chipRemove_1a7t2_188",keywordInput:"_keywordInput_1a7t2_202",input:"_input_1a7t2_207",addBtn:"_addBtn_1a7t2_220",radioGroup:"_radioGroup_1a7t2_234",radioLabel:"_radioLabel_1a7t2_239"},UO=({node:e,editorMode:t,onMoveClick:r,reorderDialog:n})=>{var M,j;const{updateNode:s,markDirty:i}=xe(),o=t==="edit",a=Yi(e),c=ae(A=>A.relationalFormConfig),d=A=>c==null?void 0:c.find($=>$.code===A),u=A=>!c||!!d(A),f=(A,$)=>{var U;return((U=d(A))==null?void 0:U.label)||$},[g,y]=h.useState(!0),_=((M=e.metadata)==null?void 0:M.relationalMetadata)??{},[p,v]=h.useState(_.name??e.name??""),[m,b]=h.useState(""),[S,w]=h.useState(Array.isArray(_.keywords)?_.keywords:Array.isArray((j=e.metadata)==null?void 0:j.keywords)?e.metadata.keywords:[]),[E,T]=h.useState(!!_.optional);h.useEffect(()=>{var $,U;const A=(($=e.metadata)==null?void 0:$.relationalMetadata)??{};v(A.name??e.name??""),w(Array.isArray(A.keywords)?A.keywords:Array.isArray((U=e.metadata)==null?void 0:U.keywords)?e.metadata.keywords:[]),T(!!A.optional)},[e.id]);const x=()=>{p.trim()&&p!==e.name&&(s(e.id,{name:p.trim()}),i())},P=()=>{const A=m.trim();if(A&&!S.includes(A)){const $=[...S,A];w($),s(e.id,{keywords:$}),i()}b("")},F=A=>{const $=S.filter(U=>U!==A);w($),s(e.id,{keywords:$}),i()},N=A=>{T(A),s(e.id,{optional:A}),i()};return l.jsxs("div",{className:We.container,children:[l.jsxs("div",{className:We.panelHeader,children:[l.jsxs("div",{className:We.panelHeaderLeft,children:[l.jsx("span",{className:`sbx-ct-badge--${a.key}`,children:a.label}),o&&l.jsx("button",{type:"button",className:We.moveBtn,onClick:r,children:"Move to another unit"})]}),l.jsx("button",{type:"button",className:We.panelCollapseBtn,onClick:()=>y(A=>!A),"aria-expanded":g,"aria-label":g?"Collapse metadata panel":"Expand metadata panel",title:g?"Collapse":"Expand",children:g?l.jsx(hs,{size:15}):l.jsx(bv,{size:15})})]}),g&&l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:We.titleRow,children:[e.appIcon&&l.jsx("img",{src:e.appIcon,alt:"icon",className:We.icon}),l.jsx("input",{type:"text",className:We.nameInput,value:p,disabled:!o,onChange:A=>v(A.target.value),onBlur:x,placeholder:"Content name"})]}),u("keywords")&&l.jsxs("div",{className:We.field,children:[l.jsx("div",{className:We.fieldHeader,children:l.jsxs("label",{className:We.label,children:[f("keywords","Keywords"),S.length>0&&l.jsx("span",{className:We.fieldCount,children:S.length})]})}),S.length>0&&l.jsx("div",{className:We.chips,children:S.map(A=>l.jsxs("span",{className:We.chip,children:[A,o&&l.jsx("button",{type:"button",className:We.chipRemove,onClick:()=>F(A),children:"×"})]},A))}),o&&l.jsxs("div",{className:We.keywordInput,children:[l.jsx("input",{type:"text",className:We.input,value:m,placeholder:"Add keyword and press Enter",onChange:A=>b(A.target.value),onKeyDown:A=>{A.key==="Enter"&&(A.preventDefault(),P())}}),l.jsx("button",{type:"button",className:We.addBtn,onClick:P,children:"Add"})]})]}),u("optional")&&l.jsxs("div",{className:We.field,children:[l.jsx("label",{className:We.label,children:f("optional","Optional in Collection")}),l.jsxs("div",{className:We.radioGroup,children:[l.jsxs("label",{className:We.radioLabel,children:[l.jsx("input",{type:"radio",name:`optional-${e.id}`,checked:E===!0,onChange:()=>N(!0),disabled:!o}),"Yes"]}),l.jsxs("label",{className:We.radioLabel,children:[l.jsx("input",{type:"radio",name:`optional-${e.id}`,checked:E===!1,onChange:()=>N(!1),disabled:!o}),"No"]})]})]})]}),n]})},Ms={iconBtn:"_iconBtn_vl14u_1",editable:"_editable_vl14u_14",iconImg:"_iconImg_vl14u_26",placeholder:"_placeholder_vl14u_34",removeBtn:"_removeBtn_vl14u_41"},zO=({nodeId:e,value:t,editable:r})=>{const[n,s]=h.useState(!1),{updateNode:i,markDirty:o}=xe(),a=d=>{i(e,{appIcon:d}),o(),s(!1)},c=d=>{d.stopPropagation(),i(e,{appIcon:""}),o()};return l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:[Ms.iconBtn,r?Ms.editable:""].filter(Boolean).join(" "),role:r?"button":void 0,tabIndex:r?0:-1,"aria-label":r?"Select app icon":"App icon",onClick:()=>r&&s(!0),onKeyDown:d=>{r&&(d.key==="Enter"||d.key===" ")&&s(!0)},children:[t?l.jsx("img",{src:t,alt:"App icon",className:Ms.iconImg}):l.jsx("div",{className:Ms.placeholder,children:l.jsx(Qc,{size:18})}),t&&r&&l.jsx("button",{type:"button",className:Ms.removeBtn,onClick:c,"aria-label":"Remove icon",children:l.jsx(Yo,{size:11})})]}),n&&l.jsx(Dh,{nodeId:e,currentValue:t,onSelect:a,onClose:()=>s(!1)})]})},Xt={leafContentLayout:"_leafContentLayout_1osey_1",container:"_container_1osey_17",emptyState:"_emptyState_1osey_26",titleRow:"_titleRow_1osey_36",nodeTitle:"_nodeTitle_1osey_52",formArea:"_formArea_1osey_74",contentListArea:"_contentListArea_1osey_78",dropZone:"_dropZone_1osey_83",reviewComment:"_reviewComment_1osey_90",reviewCommentLabel:"_reviewCommentLabel_1osey_103",reviewCommentText:"_reviewCommentText_1osey_109"},VO="application/vnd.sunbird.questionset",qh="application/vnd.sunbird.question",qO=[VO,qh],HO=({editorMode:e,onToolbarEvent:t})=>{var j,A,$,U;const[r,n]=h.useState("details"),[s,i]=h.useState([]),[o,a]=h.useState(null),[c,d]=h.useState(!1),u=h.useRef(null),f=h.useRef(),{selectedNodeId:g,breadcrumb:y,activeNodeMeta:_,updateNode:p,treeData:v}=xe(),m=ae(Z=>{var se,be,Ee,ce;return((be=(se=Z.editorConfig)==null?void 0:se.context)==null?void 0:be.contentId)??((ce=(Ee=Z.editorConfig)==null?void 0:Ee.context)==null?void 0:ce.identifier)??""}),b=g?Hh(v,g):null,S=!!b&&!b.parent,w=!!(b!=null&&b.isFolder),E=b&&qO.includes(b.mimeType??""),T=(b==null?void 0:b.mimeType)===qh,x=b&&!b.isFolder&&!E&&!S,P=((j=b==null?void 0:b.metadata)==null?void 0:j.rejectComment)??(S?($=(A=v[0])==null?void 0:A.metadata)==null?void 0:$.rejectComment:void 0),F=h.useCallback(()=>{const Z=u.current;if(!Z||!g)return;const se=Z.innerText.trim();clearTimeout(f.current),f.current=setTimeout(()=>{p(g,{name:se})},600)},[g,p]),N=h.useCallback(Z=>{t({action:"onFormValueChange",data:Z})},[t]),M=h.useCallback((Z,se)=>{i(se),t({action:"onFormStatusChange",data:{isValid:Z,nodeId:g}})},[t,g]);return b?E?l.jsx(ml,{node:b,editorMode:e,type:"quml",singleQuestion:T}):x?l.jsxs("div",{className:Xt.leafContentLayout,children:[l.jsx(ml,{node:b,editorMode:e,type:"content"}),l.jsx(UO,{node:b,editorMode:e,onMoveClick:()=>a(b.identifier),reorderDialog:o?l.jsx($O,{resourceId:o,resourceName:b.name,currentUnitId:b.parent??"",onClose:()=>a(null)}):null})]}):l.jsxs("div",{className:Xt.container,children:[l.jsx(j1,{crumbs:y}),P&&l.jsxs("div",{className:Xt.reviewComment,role:"alert",children:[l.jsx("span",{className:Xt.reviewCommentLabel,children:"Reviewer comment:"}),l.jsx("span",{className:Xt.reviewCommentText,children:P})]}),l.jsxs("div",{className:Xt.titleRow,children:[S&&g&&l.jsx(zO,{nodeId:g,value:String(b.appIcon??((U=b.metadata)==null?void 0:U.appIcon)??""),editable:e==="edit"}),l.jsx("div",{ref:u,className:Xt.nodeTitle,contentEditable:e==="edit",suppressContentEditableWarning:!0,onInput:F,onBlur:F,"data-placeholder":"Untitled","aria-label":"Node title",children:b.name})]}),l.jsx(B1,{activeTab:r,onChange:Z=>n(Z),errorTabs:s,visibleTabs:S?void 0:["details"]}),l.jsx("div",{className:Xt.formArea,children:l.jsx(QE,{nodeMetadata:_,activeTab:r,isRoot:S,isFolder:w,editorMode:e,onFormValueChange:N,onFormStatusChange:M},`${g??"none"}:${S?"root":"node"}`)}),(w||S)&&r==="details"&&l.jsx("div",{className:Xt.contentListArea,children:l.jsx(fO,{editorMode:e})}),l.jsx(hO,{isActive:!1,label:"Drop to add content to this unit",nodeId:g??void 0,className:Xt.dropZone}),c&&l.jsx(BO,{contentId:m,onClose:()=>d(!1)})]}):l.jsx("div",{className:Xt.emptyState,children:l.jsx("p",{children:"Select a unit from the outline to edit its details"})})};function Hh(e,t){for(const r of e){if(r.id===t)return r;if(r.children){const n=Hh(r.children,t);if(n)return n}}}const Wh=mi((e,t)=>({allContent:[],filteredContent:[],searchQuery:"",activeFilter:"all",advancedFilters:{},isLoading:!1,totalCount:0,offset:0,sortAZ:!1,setContent:(r,n)=>{e({allContent:r,totalCount:n,offset:r.length}),t().applyFilter()},appendContent:(r,n)=>{const i=[...t().allContent,...r];e({allContent:i,totalCount:n,offset:i.length}),t().applyFilter()},setFilter:r=>{e({activeFilter:r}),t().applyFilter()},setSearch:r=>{e({searchQuery:r}),t().applyFilter()},setLoading:r=>e({isLoading:r}),setAdvancedFilters:r=>e({advancedFilters:r}),setOffset:r=>e({offset:r}),setSortAZ:r=>e({sortAZ:r}),applyFilter:()=>{const{allContent:r,activeFilter:n,searchQuery:s}=t();let i=r;if(n&&n!=="all"){const o=n.toLowerCase();i=i.filter(a=>[a.mimeType??"",a.primaryCategory??"",a.contentType??""].join(" ").toLowerCase().includes(o))}if(s&&s.trim()!==""){const o=s.toLowerCase().trim();i=i.filter(a=>(a.name??"").toLowerCase().includes(o))}e({filteredContent:i})}})),WO=20;function Qh(){var d;const e=ae(u=>u.editorConfig),t=xe(u=>u.selectedNodeId),r=xe(u=>u.treeData),n=h.useCallback(()=>{if(!t||!r.length)return 0;function u(f,g,y=0){var _;for(const p of f){if(p.id===g)return y;if((_=p.children)!=null&&_.length){const v=u(p.children,g,y+1);if(v>=0)return v}}return-1}return Math.max(0,u(r,t))},[t,r])(),s=(d=e==null?void 0:e.config)==null?void 0:d.hierarchy;if(!s)return[...Hf];const i=`level${n}`,o=s[i],a=o==null?void 0:o.children,c=a==null?void 0:a.Content;return c!=null&&c.length?c:[...Hf]}function QO(){const e=Wh(),t=ae(f=>{var g,y;return((y=(g=f.editorConfig)==null?void 0:g.context)==null?void 0:y.channel)??""}),r=Qh(),n=h.useRef(),s=h.useCallback(async(f="",g="all",y={},_=!0,p=!1)=>{var v,m,b,S,w;e.setLoading(!0);try{const E={status:["Live"],primaryCategory:g&&g!=="all"?[g]:r};(v=y==null?void 0:y.board)!=null&&v.length&&(E.board=y.board),(m=y==null?void 0:y.medium)!=null&&m.length&&(E.medium=y.medium),(b=y==null?void 0:y.gradeLevel)!=null&&b.length&&(E.gradeLevel=y.gradeLevel),(S=y==null?void 0:y.subject)!=null&&S.length&&(E.subject=y.subject),(w=y==null?void 0:y.primaryCategory)!=null&&w.length&&(E.primaryCategory=y.primaryCategory);const T=_?0:e.offset,{content:x,count:P}=await pO({filters:E,query:f,limit:f?50:WO,offset:T,channel:t||void 0,sortBy:p?{name:"asc"}:{lastUpdatedOn:"desc"}});_?e.setContent(x,P):e.appendContent(x,P)}catch(E){console.error("[useLibrary] load error:",E)}finally{e.setLoading(!1)}},[r,t]);h.useEffect(()=>{s()},[t]);const i=h.useCallback(f=>{e.setSearch(f),clearTimeout(n.current),n.current=setTimeout(()=>s(f,e.activeFilter,e.advancedFilters,!0,e.sortAZ),300)},[e.activeFilter,e.advancedFilters,e.sortAZ,s]),o=h.useCallback(f=>{e.setFilter(f),s(e.searchQuery,f,e.advancedFilters,!0,e.sortAZ)},[e.searchQuery,e.advancedFilters,e.sortAZ,s]),a=h.useCallback(f=>{e.setAdvancedFilters(f),s(e.searchQuery,e.activeFilter,f,!0,e.sortAZ)},[e.searchQuery,e.activeFilter,e.sortAZ,s]),c=h.useCallback(()=>{const f=!e.sortAZ;e.setSortAZ(f),s(e.searchQuery,e.activeFilter,e.advancedFilters,!0,f)},[e.sortAZ,e.searchQuery,e.activeFilter,e.advancedFilters,s]),d=h.useCallback(()=>{e.isLoading||s(e.searchQuery,e.activeFilter,e.advancedFilters,!1,e.sortAZ)},[e.isLoading,e.searchQuery,e.activeFilter,e.advancedFilters,e.sortAZ,s]),u=e.allContent.length<e.totalCount;return{content:e.filteredContent,isLoading:e.isLoading,totalCount:e.totalCount,activeFilter:e.activeFilter,advancedFilters:e.advancedFilters,searchQuery:e.searchQuery,sortAZ:e.sortAZ,hasMore:u,search:i,setFilter:o,applyAdvancedFilters:a,toggleSort:c,loadMore:d,refetch:()=>s(e.searchQuery,e.activeFilter,e.advancedFilters,!0,e.sortAZ)}}const sr={card:"_card_jzciw_1",addBtn:"_addBtn_jzciw_17",dragging:"_dragging_jzciw_24",ctIcon:"_ctIcon_jzciw_29",info:"_info_jzciw_33",name:"_name_jzciw_41",meta:"_meta_jzciw_50",addBtnMuted:"_addBtnMuted_jzciw_78",added:"_added_jzciw_87",addedBadge:"_addedBadge_jzciw_96"},KO={video:Ro,pdf:Ho,h5p:Wo,scorm:Ko,audio:Qo,quiz:Vo,default:mn},GO=({item:e,onAdd:t,onPreview:r,isDraggable:n,isAdded:s})=>{var p,v;const i=Yi(e),o=KO[i.key]??mn,a=Za(),c=I1(),d=a&&!s&&c,{attributes:u,listeners:f,setNodeRef:g,isDragging:y}=$c({id:e.identifier,disabled:!n||!a||!c,data:{type:"library-item",item:e}}),_=()=>{r&&r(e)};return l.jsxs("div",{ref:g,className:[sr.card,y?sr.dragging:"",s?sr.added:""].join(" "),"aria-label":e.name,...n?{...u,...f}:{},role:"listitem",onClick:_,children:[l.jsx("span",{className:[`sbx-ct-sq--${i.key}`,sr.ctIcon].join(" "),"aria-hidden":"true",children:l.jsx(o,{size:14})}),l.jsxs("div",{className:sr.info,children:[l.jsx("span",{className:sr.name,title:e.name,children:e.name}),l.jsxs("span",{className:sr.meta,children:[((p=e.organisation)==null?void 0:p[0])??e.channel??"",(v=e.organisation)!=null&&v[0]&&e.primaryCategory?" · ":"",e.primaryCategory??""]})]}),s&&l.jsx("span",{className:sr.addedBadge,"aria-label":"Already added",title:"Already added to this collection",children:l.jsx(vn,{size:12})}),!s&&l.jsx("button",{type:"button",className:[sr.addBtn,!d&&a?sr.addBtnMuted:""].join(" "),onClick:m=>{m.stopPropagation(),t(e)},disabled:!a,"aria-disabled":!d,"aria-label":`Add ${e.name} to unit`,title:a?c?"Add to unit":"Select a unit to add":"Only Draft content can be added",children:l.jsx(ps,{size:14})})]})},Kh={chips:"_chips_xhhaq_1",chip:"_chip_xhhaq_1"},YO=({filters:e,active:t,onChange:r})=>l.jsx("div",{className:Kh.chips,role:"group","aria-label":"Content type filters",children:e.map(n=>l.jsx("button",{type:"button",role:"radio","aria-checked":t===n.value,className:["sbx-chip",t===n.value?"filled":"outline",Kh.chip].join(" "),onClick:()=>r(n.value),children:n.label},n.value))}),st={panel:"_panel_1cl11_1",header:"_header_1cl11_10",headerTitle:"_headerTitle_1cl11_19",closeBtn:"_closeBtn_1cl11_25",body:"_body_1cl11_43",section:"_section_1cl11_59",sectionLabel:"_sectionLabel_1cl11_65",chips:"_chips_1cl11_73",chip:"_chip_1cl11_73",active:"_active_1cl11_96",footer:"_footer_1cl11_102",resetBtn:"_resetBtn_1cl11_112",applyBtn:"_applyBtn_1cl11_129"},RO=[{key:"board",label:"Board"},{key:"medium",label:"Medium"},{key:"gradeLevel",label:"Class"},{key:"subject",label:"Subject"}],XO=new Set(["board","medium","gradeLevel","subject","topic"]),ZO=({local:e,toggle:t})=>{const r=Qh();return r.length?l.jsxs("div",{className:st.section,children:[l.jsx("div",{className:st.sectionLabel,children:"Primary Category"}),l.jsx("div",{className:st.chips,children:r.map(n=>l.jsx("button",{type:"button",className:[st.chip,(e.primaryCategory??[]).includes(n)?st.active:""].join(" "),onClick:()=>t("primaryCategory",n),children:n},n))})]}):null},JO=({isOpen:e,filters:t,onApply:r,onClose:n})=>{var p,v;const s=ae(m=>m.editorConfig),i=ae(m=>m.searchFormConfig),o=ae(m=>m.contentFramework),a=ae(m=>m.contentTargetFWIds),{organisationFramework:c}=_h(o??((p=s==null?void 0:s.context)==null?void 0:p.framework),a??((v=s==null?void 0:s.context)==null?void 0:v.targetFWIds)),[d,u]=h.useState(t),f=i!=null&&i.length?i.filter(m=>XO.has(m.code)).map(m=>({key:m.code,label:m.label||m.code})):RO;h.useEffect(()=>{u(t)},[t]);const g=(m,b)=>{u(S=>{const w=S[m]??[],E=w.includes(b)?w.filter(T=>T!==b):[...w,b];return{...S,[m]:E}})},y=(c==null?void 0:c.categories)??[],_=m=>{var b;return((b=y.find(S=>S.code===m))==null?void 0:b.terms)??[]};return e?l.jsxs("div",{className:st.panel,role:"dialog","aria-label":"Filter library","aria-modal":"true",children:[l.jsxs("div",{className:st.header,children:[l.jsx("span",{className:st.headerTitle,children:"Filters"}),l.jsx("button",{type:"button",className:st.closeBtn,onClick:n,"aria-label":"Close filters",children:l.jsx(zr,{size:16})})]}),l.jsxs("div",{className:st.body,children:[f.map(({key:m,label:b})=>{const S=_(m);return S.length?l.jsxs("div",{className:st.section,children:[l.jsx("div",{className:st.sectionLabel,children:b}),l.jsx("div",{className:st.chips,children:S.slice(0,20).map(w=>l.jsx("button",{type:"button",className:[st.chip,(d[m]??[]).includes(w.name)?st.active:""].join(" "),onClick:()=>g(m,w.name),children:w.name},w.identifier))})]},m):null}),l.jsx(ZO,{local:d,toggle:g})]}),l.jsxs("div",{className:st.footer,children:[l.jsx("button",{type:"button",className:st.resetBtn,onClick:()=>u({}),children:"Reset"}),l.jsx("button",{type:"button",className:st.applyBtn,onClick:()=>{r(d),n()},children:"Apply"})]})]}):null},fr={header:"_header_6qdpu_10",title:"_title_6qdpu_20",headerActions:"_headerActions_6qdpu_31",iconBtn:"_iconBtn_6qdpu_38",playerArea:"_playerArea_6qdpu_56",footer:"_footer_6qdpu_64",addBtn:"_addBtn_6qdpu_73",modalOverlay:"_modalOverlay_6qdpu_92",modalPanel:"_modalPanel_6qdpu_103"},eI=({content:e,onAdd:t,onClose:r})=>{if(!e)return null;const n={id:e.identifier,identifier:e.identifier,name:e.name??"",mimeType:e.mimeType,primaryCategory:e.primaryCategory,contentType:e.contentType,appIcon:e.appIcon,status:e.status,isFolder:!1,children:[],metadata:e};return Me.createPortal(l.jsx("div",{className:fr.modalOverlay,role:"dialog","aria-modal":"true","aria-label":"Content preview",onClick:r,children:l.jsxs("div",{className:fr.modalPanel,onClick:s=>s.stopPropagation(),children:[l.jsxs("div",{className:fr.header,children:[l.jsx("span",{className:fr.title,title:e.name,children:e.name}),l.jsx("div",{className:fr.headerActions,children:l.jsx("button",{type:"button",className:fr.iconBtn,onClick:r,"aria-label":"Close preview",children:l.jsx(zr,{size:16})})})]}),l.jsx("div",{className:fr.playerArea,children:l.jsx(ml,{node:n,editorMode:"read",type:"content"})}),l.jsx("div",{className:fr.footer,children:l.jsx("button",{type:"button",className:fr.addBtn,onClick:()=>t(e),children:"+ Add to Unit"})})]})}),document.body)},Ve={dock:"_dock_1lpg0_1",header:"_header_1lpg0_8",headerLeft:"_headerLeft_1lpg0_17",headerTitle:"_headerTitle_1lpg0_24",count:"_count_1lpg0_30",searchRow:"_searchRow_1lpg0_39",searchWrap:"_searchWrap_1lpg0_47",searchIcon:"_searchIcon_1lpg0_53",searchInput:"_searchInput_1lpg0_62",filterToggleBtn:"_filterToggleBtn_1lpg0_80",filterToggleBtnActive:"_filterToggleBtnActive_1lpg0_99",filterBadge:"_filterBadge_1lpg0_105",filters:"_filters_1lpg0_124",mainArea:"_mainArea_1lpg0_134",sidePanelOverlay:"_sidePanelOverlay_1lpg0_143",cardList:"_cardList_1lpg0_152",skeleton:"_skeleton_1lpg0_168",skeletonIcon:"_skeletonIcon_1lpg0_178",skeletonText:"_skeletonText_1lpg0_186",skeletonLine:"_skeletonLine_1lpg0_193",skeletonLineSm:"_skeletonLineSm_1lpg0_200",loadMoreBtn:"_loadMoreBtn_1lpg0_215",emptyState:"_emptyState_1lpg0_240",collapseBtn:"_collapseBtn_1lpg0_260"};function tI(e){const t=new Set,r=[...e];for(;r.length>0;){const n=r.shift();n.isFolder||t.add(n.identifier),n.children&&r.push(...n.children)}return t}const rI=({editorMode:e,collapsed:t=!1,onToggleCollapse:r})=>{const{content:n,isLoading:s,totalCount:i,activeFilter:o,searchQuery:a,sortAZ:c,hasMore:d,search:u,setFilter:f,applyAdvancedFilters:g,toggleSort:y,loadMore:_}=QO(),{addResource:p,selectedNodeId:v,treeData:m}=xe(),b=e==="edit",[S,w]=h.useState(!1),[E,T]=h.useState({}),[x,P]=h.useState(null),F=h.useMemo(()=>tI(m),[m]),N=h.useCallback(U=>{var be;if(!v){Ie.error("Select a unit first");return}const Z=(be=m[0])==null?void 0:be.id;if(v===Z){Ie("Select a unit from the outline to add content — resources cannot be added directly to the course.",{icon:"ℹ️",duration:4e3});return}if(p(U,v)===!1){Ie.error(`"${U.name}" is already in this collection`);return}Ie.success(`Added "${U.name}"`)},[v,p,m]),M=h.useCallback(U=>{T(U),g(U)},[g]),j=h.useCallback(U=>{P(U)},[]),A=h.useCallback(U=>{N(U),P(null)},[N]),$=h.useMemo(()=>Object.values(E).reduce((U,Z)=>U+((Z==null?void 0:Z.length)??0),0),[E]);return l.jsxs("div",{className:Ve.dock,children:[l.jsx("div",{className:Ve.header,children:l.jsxs("div",{className:Ve.headerLeft,children:[l.jsx("button",{type:"button",className:Ve.collapseBtn,onClick:r,"aria-label":"Collapse library panel",title:"Collapse library",children:l.jsx(Tv,{size:15})}),l.jsx(Ov,{size:16}),l.jsx("span",{className:Ve.headerTitle,children:"Library"}),i>0&&l.jsx("span",{className:Ve.count,children:i})]})}),l.jsxs("div",{className:Ve.searchRow,children:[l.jsxs("div",{className:Ve.searchWrap,children:[l.jsx(Go,{size:14,className:Ve.searchIcon}),l.jsx("input",{type:"search",className:Ve.searchInput,placeholder:"Search content…",value:a,onChange:U=>u(U.target.value),"aria-label":"Search library"})]}),l.jsx("button",{type:"button",className:[Ve.filterToggleBtn,c?Ve.filterToggleBtnActive:""].join(" "),onClick:y,"aria-label":c?"Sort: A–Z (click for Recent)":"Sort: Recent (click for A–Z)",title:c?"A–Z":"Recent",children:c?l.jsx(vv,{size:15}):l.jsx(_v,{size:15})}),l.jsxs("button",{type:"button",className:[Ve.filterToggleBtn,S?Ve.filterToggleBtnActive:""].join(" "),onClick:()=>w(U=>!U),"aria-label":"Toggle advanced filters","aria-pressed":S,title:"Advanced filters",children:[l.jsx(Mv,{size:15}),$>0&&l.jsx("span",{className:Ve.filterBadge,children:$})]})]}),l.jsx("div",{className:Ve.filters,children:l.jsx(YO,{filters:D1,active:o,onChange:f})}),l.jsxs("div",{className:Ve.mainArea,children:[l.jsx("div",{className:Ve.cardList,role:"list","aria-label":"Library content",children:s&&n.length===0?Array.from({length:4}).map((U,Z)=>l.jsxs("div",{className:Ve.skeleton,"aria-hidden":"true",children:[l.jsx("div",{className:Ve.skeletonIcon}),l.jsxs("div",{className:Ve.skeletonText,children:[l.jsx("div",{className:Ve.skeletonLine}),l.jsx("div",{className:Ve.skeletonLineSm})]})]},Z)):n.length>0?l.jsxs(l.Fragment,{children:[n.map(U=>l.jsx(GO,{item:U,onAdd:N,onPreview:j,isDraggable:b,isAdded:F.has(U.identifier)},U.identifier)),d&&l.jsx("button",{type:"button",className:Ve.loadMoreBtn,onClick:_,disabled:s,"aria-label":"Load more content",children:s?"Loading…":"Load More"})]}):l.jsxs("div",{className:Ve.emptyState,children:[l.jsx(Go,{size:24}),l.jsx("p",{children:"No content found"}),l.jsx("span",{children:"Try a different search or filter"})]})}),S&&l.jsx("div",{className:Ve.sidePanelOverlay,children:l.jsx(JO,{isOpen:S,filters:E,onApply:M,onClose:()=>w(!1)})}),x&&l.jsx(eI,{content:x,onAdd:A,onClose:()=>P(null)})]})]})};function nI(e,t,r){const n={},s={},i=new Set(["id","isFolder","children","parent","isNew","breadcrumb","title","relationalMetadata","optional"]),o=new Set(["targetBoardIds","targetMediumIds","targetGradeLevelIds","targetSubjectIds","targetFWIds","targetTopicIds","topic","topicsIds"]),a=new Set(["audience","attributions","keywords","language","additionalCategories","medium","gradeLevel","subject","boardIds","mediumIds","gradeLevelIds","subjectIds","targetBoardIds","targetMediumIds","targetGradeLevelIds","targetSubjectIds","dialcodes"]),c=new Set(["copyrightYear","compatibilityLevel","version"]);function d(g,y=!1){const _={};for(const[p,v]of Object.entries(g))if(!i.has(p)&&!(y&&o.has(p)))if(a.has(p))Array.isArray(v)?_[p]=v:v!=null&&v!==""?_[p]=[v]:_[p]=[];else if(c.has(p)){const m=Number(v);isNaN(m)||(_[p]=m)}else _[p]=v;return _}function u(g){var _;const y={};for(const p of g.children??[]){if(p.isFolder)continue;const v=t[p.identifier];if(!v)continue;const{isNew:m,...b}=v;if(Object.keys(b).length===0)continue;const S=((_=p.metadata)==null?void 0:_.relationalMetadata)??{};y[p.identifier]={name:p.name,...S,...b}}return y}function f(g,y){var S,w;const _=g.identifier,p=t[_],v=_.startsWith("temp-")||!!(p!=null&&p.isNew),m=!g.isFolder&&!y;if(y||v||p&&!m){let E;if(v)E={mimeType:"application/vnd.ekstep.content-collection",code:_,contentType:((S=g.metadata)==null?void 0:S.contentType)??"CourseUnit",primaryCategory:((w=g.metadata)==null?void 0:w.primaryCategory)??"Course Unit",name:g.name,visibility:"Parent",channel:r,...d(g.metadata??{})};else if(y){const{isNew:T,...x}=p??{};E={...d(g.metadata??{},!0),...d(x,!1),name:g.name}}else{const{isNew:T,...x}=p??{};E={name:g.name,visibility:"Parent",...d(x,!0)}}n[_]={metadata:E,objectType:g.objectType||(g.isFolder?"Collection":"Content"),root:y,isNew:v}}const b=g.isFolder?u(g):{};s[_]={name:g.name,children:(g.children??[]).map(E=>E.identifier),...Object.keys(b).length>0?{relationalMetadata:b}:{},root:y},(g.children??[]).forEach(E=>f(E,!1))}return e.forEach((g,y)=>f(g,y===0)),{nodesModified:n,hierarchy:s}}function sI(){const[e,t]=h.useState(!1),r=xe(u=>u.treeCache),n=xe(u=>u.treeData),s=ae(u=>u.isDirty),i=ae(u=>u.lastSaved),{setIsDirty:o,setLastSaved:a}=ae(),c=ae(u=>u.editorConfig);return{save:h.useCallback(async()=>{if(!c||e)return;const u=c.context.contentId??c.context.identifier??"";if(!u)return;const f=c.context.channel??"",g=c.context.userId??c.context.uid??"";t(!0);try{const{nodesModified:y,hierarchy:_}=nI(n,r,f),{identifiers:p}=await Jb(u,y,_,g);p&&Object.keys(p).length>0&&xe.getState().replaceNodeIds(p);const v=new Date().toISOString();a(v),o(!1)}catch(y){console.error("[useSaveHierarchy] save failed:",y),Ie.error("Failed to save. Please try again.")}finally{t(!1)}},[c,e,n,r,o,a]),isSaving:e,isDirty:s,lastSaved:i}}function iI(e){const t=ae(o=>o.editorConfig),r=ae(o=>o.setButtonLoader),n=ae(o=>o.validateAllForms),s=xe(o=>o.treeData);return{runAction:h.useCallback(async(o,a)=>{var u,f,g,y;const c=((u=t==null?void 0:t.context)==null?void 0:u.contentId)??((f=t==null?void 0:t.context)==null?void 0:f.identifier)??"";if(!c)return Ie.error("No content identifier found."),!1;const d=((g=t==null?void 0:t.context)==null?void 0:g.userId)??((y=t==null?void 0:t.context)==null?void 0:y.uid)??"";try{switch(o){case"sendForReview":return n(s)?(r("saveCollection",!0),await e(),await r_(c),Ie.success("Content sent for review"),!0):(Ie.error("Some units have missing required fields. Please fill them before sending for review."),!1);case"reject":{r("rejectCollection",!0);const _=(a==null?void 0:a.comment)??"";return await n_(c,_),Ie.success("Content rejected and sent back to the author"),!0}case"publish":return n(s)?(r("publishCollection",!0),await e(),await e_(c,d),Ie.success("Content published successfully"),!0):(Ie.error("Some units have missing required fields. Please fill them before publishing."),!1);default:return!1}}catch(_){console.error(`[useToolbarActions] ${o} failed`,_);const p=o==="sendForReview"?"send for review":o==="reject"?"reject":"publish";return Ie.error(`Failed to ${p}. Please try again.`),!1}finally{r("saveCollection",!1),r("rejectCollection",!1),r("publishCollection",!1)}},[t,e,r])}}const Lt={shell:"_shell_90fon_1",workspace:"_workspace_90fon_8",sidebarCollapsed:"_sidebarCollapsed_90fon_16",dockCollapsed:"_dockCollapsed_90fon_19",dock:"_dock_90fon_19",outline:"_outline_90fon_40",reopenTab:"_reopenTab_90fon_45",outlineHidden:"_outlineHidden_90fon_79",editor:"_editor_90fon_86",dockHidden:"_dockHidden_90fon_101",dockReopenTab:"_dockReopenTab_90fon_108",dragChip:"_dragChip_90fon_133",dragChipLabel:"_dragChipLabel_90fon_148"},oI=({editorMode:e,onToolbarEvent:t,onContentAdded:r,onHierarchySaved:n})=>{const[s,i]=h.useState(null),[o,a]=h.useState(!1),[c,d]=h.useState(!1),[u,f]=h.useState(!1),{addResource:g,treeData:y}=xe(),_=ae(A=>A.setFormStatus),[p,v]=h.useState(!0),m=xe(A=>A.selectedNodeId),{save:b,isSaving:S,isDirty:w,lastSaved:E}=sI(),{runAction:T}=iI(b);h.useEffect(()=>{if(!w)return;const A=$=>{$.preventDefault(),$.returnValue=""};return window.addEventListener("beforeunload",A),()=>window.removeEventListener("beforeunload",A)},[w]);const x=ic(xo(di,{activationConstraint:{distance:8}})),P=h.useCallback(A=>{var U;const $=(U=A.active.data.current)==null?void 0:U.item;$&&i($)},[]),F=h.useCallback(A=>{var Ee,ce;i(null);const $=(Ee=A.active.data.current)==null?void 0:Ee.item;if(!$)return;const U=A.over,Z=(U==null?void 0:U.id)??m??void 0;if(!Z){Ie.error("Drop onto a unit to add content");return}const se=(ce=y[0])==null?void 0:ce.id;if(Z===se){Ie.error("Drop content onto a unit, not directly on the course.");return}if(!g($,Z)){Ie.error(`"${$.name}" is already in this collection`);return}r==null||r($,Z),Ie.success(`Added "${$.name}" to unit`)},[m,g,r]),N=h.useCallback(async A=>{if(A.action==="onFormStatusChange"){const{isValid:$,nodeId:U}=A.data??{},Z=$!==!1;v(Z),U&&_(U,Z);return}if(A.action==="back"&&w){f(!0);return}if(A.action==="saveCollection"){if(!p){Ie.error("Please fill the required metadata");return}await b(),n==null||n(y),t==null||t(A);return}if(A.action==="sendForReview"||A.action==="reject"||A.action==="publish"){await T(A.action,A.data)&&(t==null||t(A));return}t==null||t(A)},[b,T,t,n,y,w,p]),M=h.useCallback(async()=>{await b(),f(!1),n==null||n(y),t==null||t({action:"back"})},[b,n,t,y]),j=h.useCallback(()=>{f(!1),t==null||t({action:"back"})},[t]);return l.jsxs(Lc,{sensors:x,onDragStart:P,onDragEnd:F,children:[l.jsxs("div",{className:Lt.shell,children:[l.jsx(h_,{editorMode:e,isSaving:S,isDirty:w,lastSaved:E,isFormValid:p,onToolbarEvent:N}),l.jsxs("div",{className:[Lt.workspace,o?Lt.sidebarCollapsed:"",c?Lt.dockCollapsed:""].filter(Boolean).join(" "),children:[l.jsx("aside",{className:[Lt.outline,o?Lt.outlineHidden:""].join(" "),"aria-label":"Course outline","aria-hidden":o,children:l.jsx($1,{editorMode:e,collapsed:o,onToggleCollapse:()=>a(A=>!A)})}),o&&l.jsx("button",{className:Lt.reopenTab,onClick:()=>a(!1),title:"Show outline",type:"button",children:"›"}),l.jsx("main",{className:Lt.editor,role:"main","aria-label":"Content editor",children:l.jsx(HO,{editorMode:e,onToolbarEvent:N})}),l.jsx("aside",{className:[Lt.dock,c?Lt.dockHidden:""].filter(Boolean).join(" "),"aria-label":"Content library","aria-hidden":c,children:l.jsx(rI,{editorMode:e,collapsed:c,onToggleCollapse:()=>d(A=>!A)})}),c&&l.jsx("button",{className:Lt.dockReopenTab,onClick:()=>d(!1),title:"Show library",type:"button",children:"‹"})]})]}),l.jsx(fv,{dropAnimation:null,children:s?l.jsx("div",{className:Lt.dragChip,children:l.jsx("span",{className:Lt.dragChipLabel,children:s.name})}):null}),u&&l.jsx(p_,{onSave:M,onDiscard:j,onCancel:()=>f(!1),isSaving:S})]})},aI="v1";function lI(e){const t=e.validations,r=t==null?void 0:t.find(s=>s.type==="maxlength"||s.type==="maxLength");if(!r)return e.maxLength;const n=Number(r.value);return Number.isFinite(n)?n:void 0}function Gh(e,t){var r;return{code:e.code??"",label:e.label??e.name??e.code??"",name:e.name,inputType:e.inputType,dataType:e.dataType,required:e.required===!0||Array.isArray(e.validations)&&e.validations.some(n=>n.type==="required")||String(((r=e.renderingHints)==null?void 0:r.class)??"").includes("required"),editable:e.editable!==!1,visible:e.visible!==!1,placeholder:e.placeholder,maxLength:lI(e),depends:e.depends,sourceCategory:e.sourceCategory,range:e.range,enum:e.enum,default:e.default,defaultValue:e.defaultValue,index:e.index,section:t,output:e.output}}function Nr(e){const t=e==null?void 0:e.properties;if(!Array.isArray(t))return[];const r=[];for(const n of t)if(Array.isArray(n.fields)){const s=n.name??void 0,i=n.fields.filter(o=>!!o.code).sort((o,a)=>(o.index??0)-(a.index??0));for(const o of i)r.push(Gh(o,s))}else n.code&&r.push(Gh(n));return r}function cI(e){const t=e==null?void 0:e.properties;if(!t)return{};const r={};for(const[n,s]of Object.entries(t))s&&"default"in s&&(r[n]=s.default);return r}async function uI(e,t,r="Collection",n=aI){var d,u;const i=(u=(d=(await Ae.post(`/action/object/category/definition/${n}/read?fields=objectMetadata,forms,name,label`,{request:{objectCategoryDefinition:{objectType:r,name:e,...t?{channel:t}:{}}}})).data)==null?void 0:d.result)==null?void 0:u.objectCategoryDefinition,o=(i==null?void 0:i.forms)??{},a=(i==null?void 0:i.objectMetadata)??{},c=a.config??{};return{rootForm:Nr(o.create),unitForm:Nr(o.unitMetadata),childForm:Nr(o.childMetadata),searchForm:Nr(o.search??o.searchConfig),relationalForm:Nr(o.relationalMetadata),publishChecklist:Nr(o.publishchecklist),reviewChecklist:Nr(o.review),rfcChecklist:Nr(o.requestforchangeschecklist),schemaDefaults:cI(a.schema),frameworkMetadata:c.frameworkMetadata??{},sourcingSettings:c.sourcingSettings??{}}}function dI({config:e,onError:t}){const[r,n]=h.useState(!0),[s,i]=h.useState(null),[o,a]=h.useState(!1),{setEditorConfig:c,setEditorMode:d,setCategoryDefinition:u,setContentFramework:f}=ae(),{setTreeData:g,selectNode:y}=xe();return h.useEffect(()=>{let _=!1;async function p(){var v,m;try{n(!0),i(null),e.apiBaseUrl&&Yu(e.apiBaseUrl),c(e),d(e.config.mode);const b=e.context.contentId??e.context.identifier??"";if(b){const S=e.config.objectType==="QuestionSet",{rootNode:w}=S?await Zb(b):await Zu(b);if(!_&&(g(w?[w]:[]),w)){y(w.id);const F=w.metadata??{},N=F.framework??e.context.framework??null,M=F.targetFWIds??e.context.targetFWIds??null;f(N,M)}const E=e.config.primaryCategory??"Course",T=e.context.channel??"",x=e.config.categoryDefinitionApiVersion??"v1";try{const P=await uI(E,T,e.config.objectType??"Collection",x);if(!_){u(P);const F=((v=P.sourcingSettings)==null?void 0:v.collection)??{},N={};F.maxDepth&&!e.config.maxDepth&&(N.maxDepth=F.maxDepth),F.children&&!e.config.children&&(N.children=F.children),F.hierarchy&&!((m=e.config.hierarchy)!=null&&m.level1)&&(N.hierarchy={...e.config.hierarchy??{},...F.hierarchy}),Object.keys(N).length>0&&c({...e,config:{...e.config,...N}})}}catch{}}_||a(!0)}catch(b){if(!_){const S=b instanceof Error?b:new Error(String(b));i(S),t==null||t(S)}}finally{_||n(!1)}}return p(),()=>{_=!0}},[e.context.contentId,e.context.identifier]),{isLoading:r,error:s,isReady:o}}const Ls={root:"_root_qcpw6_1",loadingState:"_loadingState_qcpw6_10",loadingSpinner:"_loadingSpinner_qcpw6_20",errorState:"_errorState_qcpw6_34"},fI=new jp({defaultOptions:{queries:{retry:1,refetchOnWindowFocus:!1}}});class hI extends h.Component{constructor(t){super(t),this.state={error:null}}static getDerivedStateFromError(t){return{error:t}}componentDidCatch(t){var r,n;(n=(r=this.props).onError)==null||n.call(r,t)}render(){return this.state.error?l.jsxs("div",{className:Ls.errorState,children:[l.jsx("h3",{children:"Something went wrong"}),l.jsx("p",{children:this.state.error.message}),l.jsx("button",{onClick:()=>this.setState({error:null}),children:"Retry"})]}):this.props.children}}function pI(e){const{isLoading:t,error:r}=dI({config:e,onError:e.onError}),n=ae(s=>s.editorMode);return t?l.jsxs("div",{className:Ls.loadingState,children:[l.jsx("div",{className:Ls.loadingSpinner}),l.jsx("p",{children:"Loading editor..."})]}):r?l.jsxs("div",{className:Ls.errorState,children:[l.jsx("h3",{children:"Failed to load editor"}),l.jsx("p",{children:r.message})]}):l.jsx("div",{className:`sb-split-builder ${Ls.root}`,children:l.jsx(oI,{editorMode:n,onToolbarEvent:e.onToolbarEvent,onContentAdded:e.onContentAdded,onHierarchySaved:e.onHierarchySaved})})}const Yh=e=>l.jsx(hI,{onError:e.onError,children:l.jsxs(Up,{client:fI,children:[l.jsx(pI,{...e}),l.jsx(Bg,{position:"top-right",toastOptions:{duration:3e3}})]})}),lo=Symbol.for("r2wc.reactRender"),Rh=Symbol.for("r2wc.shouldRender"),co=Symbol.for("r2wc.root");function gI(e=""){return e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}function yI(e=""){return e.replace(/-([a-z0-9])/g,function(t){return t[1].toUpperCase()})}var Xh={expando:function(e,t,r){Object.defineProperty(e,t,{enumerable:!0,get:function(){return r},set:function(n){r=n,this[lo]()}}),e[lo]()}};function vI(e,t,r,n={}){var s={isConnected:"isConnected"in HTMLElement.prototype},i=!1,o=function(){var d=Reflect.construct(HTMLElement,arguments,this.constructor);return typeof n.shadow=="string"?d.attachShadow({mode:n.shadow}):n.shadow&&(console.warn('Specifying the "shadow" option as a boolean is deprecated and will be removed in a future version.'),d.attachShadow({mode:"open"})),d},a=Object.create(HTMLElement.prototype);a.constructor=o;var c=new Proxy(a,{has:function(d,u){return u in e.propTypes||u in a},set:function(d,u,f,g){return i&&(s[u]=!0),typeof u=="symbol"||s[u]||u in d?(e.propTypes&&u in e.propTypes&&Xh.expando(g,u,f),Reflect.set(d,u,f,g)):(Xh.expando(g,u,f),!0)},getOwnPropertyDescriptor:function(d,u){var f=Reflect.getOwnPropertyDescriptor(d,u);if(f)return f;if(u in e.propTypes)return{configurable:!0,enumerable:!0,writable:!0,value:void 0}}});return o.prototype=c,a.connectedCallback=function(){this[Rh]=!0,this[lo]()},a.disconnectedCallback=function(){typeof r.createRoot=="function"?this[co].unmount():r.unmountComponentAtNode(this)},a[lo]=function(){if(this[Rh]===!0){var d={};Object.keys(this).forEach(function(g){s[g]!==!1&&(d[g]=this[g])},this),i=!0;const u=n.shadow?this.shadowRoot:this,f=t.createElement(e,d);typeof r.createRoot=="function"?(this[co]||(this[co]=r.createRoot(u)),this[co].render(f)):r.render(f,u),i=!1}},e.propTypes&&(o.observedAttributes=n.dashStyleAttributes?Object.keys(e.propTypes).map(function(d){return gI(d)}):Object.keys(e.propTypes),a.attributeChangedCallback=function(d,u,f){var g=n.dashStyleAttributes?yI(d):d;this[g]=f}),o}var Fs={},$s=Me;if(process.env.NODE_ENV==="production")Fs.createRoot=$s.createRoot,Fs.hydrateRoot=$s.hydrateRoot;else{var uo=$s.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;Fs.createRoot=function(e,t){uo.usingClientEntryPoint=!0;try{return $s.createRoot(e,t)}finally{uo.usingClientEntryPoint=!1}},Fs.hydrateRoot=function(e,t,r){uo.usingClientEntryPoint=!0;try{return $s.hydrateRoot(e,t,r)}finally{uo.usingClientEntryPoint=!1}}}function mI(){if(document.getElementById("sb-ce-react-styles"))return;const e=document.createElement("style");e.id="sb-ce-react-styles",e.textContent="@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');",document.head.insertBefore(e,document.head.firstChild)}function bI(e="sb-collection-editor"){if(mI(),typeof customElements>"u"||customElements.get(e))return;const t=vI(Yh,h,Fs,{});customElements.define(e,t)}ye.CollectionEditor=Yh,ye.registerCollectionEditor=bI,ye.setApiBaseUrl=Yu,ye.useEditorStore=ae,ye.useLibraryStore=Wh,ye.useTreeStore=xe,Object.defineProperty(ye,Symbol.toStringTag,{value:"Module"})});
466
+ Use the data prop if you want to provide your own handlers.`);if(e.initialData){const[t,r]=S1(e.initialData,{idAccessor:e.idAccessor,childrenAccessor:e.childrenAccessor});return Object.assign(Object.assign(Object.assign({},e),r),{data:t})}else return e}function E1(e,t){const r=C1(e);return l.jsxs(h1,{treeProps:r,imperativeHandle:t,children:[l.jsx(g1,{children:l.jsx(y1,{})}),l.jsx(v1,{})]})}const O1=h.forwardRef(E1);function Za(){return xe(e=>{var n;const t=e.treeData[0];return(((n=t==null?void 0:t.metadata)==null?void 0:n.status)??(t==null?void 0:t.status)??"Draft").toLowerCase()==="draft"})}function I1(){return xe(e=>{var s;if(!e.selectedNodeId)return!1;const t=(s=e.treeData[0])==null?void 0:s.id,r=i=>{var o;for(const a of i){if(a.id===e.selectedNodeId)return a;if((o=a.children)!=null&&o.length){const c=r(a.children);if(c)return c}}},n=r(e.treeData);return!!(n!=null&&n.isFolder)&&n.id!==t})}const Vf={video:"#EA580C",pdf:"#DC2626",h5p:"#0D9488",scorm:"#7C3AED",audio:"#DB2777",quiz:"#16A34A",default:"#6B7280"},qf={video:"Video",pdf:"FileText",h5p:"Layers",scorm:"Package",audio:"Music",quiz:"HelpCircle",default:"File"},Hf=["Course Assessment","eTextbook","Exam Question","Explanation Content","Learning Resource","Practice Question Set","SCORM Content","Teacher Resource"],D1=[{label:"All",value:"all"},{label:"Course Assessment",value:"Course Assessment"},{label:"eTextbook",value:"eTextbook"},{label:"Exam Question",value:"Exam Question"},{label:"Explanation Content",value:"Explanation Content"},{label:"Learning Resource",value:"Learning Resource"},{label:"Practice Question Set",value:"Practice Question Set"},{label:"SCORM Content",value:"SCORM Content"},{label:"Teacher Resource",value:"Teacher Resource"}];function T1(e){const t=[e.mimeType??"",e.primaryCategory??"",e.contentType??""].join(" ").toLowerCase();return t.includes("video")?"video":t.includes("pdf")||t.includes("epub")?"pdf":t.includes("h5p")?"h5p":t.includes("scorm")?"scorm":t.includes("audio")||t.includes("mp3")?"audio":t.includes("quiz")||t.includes("question")||t.includes("ecml")?"quiz":"default"}function Yi(e){const t=T1(e);return{key:t,color:Vf[t]??Vf.default,bgClass:`sbx-ct-sq--${t}`,badgeClass:`sbx-ct-badge--${t}`,tintClass:`sbx-ct-tint--${t}`,iconName:qf[t]??qf.default,label:t.charAt(0).toUpperCase()+t.slice(1)}}const Tt={row:"_row_i3qt2_1",grip:"_grip_i3qt2_16",menuBtn:"_menuBtn_i3qt2_19",selected:"_selected_i3qt2_23",title:"_title_i3qt2_28",dropTarget:"_dropTarget_i3qt2_33",toggle:"_toggle_i3qt2_50",ctIcon:"_ctIcon_i3qt2_65",folderIcon:"_folderIcon_i3qt2_77",renameInput:"_renameInput_i3qt2_92",dropHere:"_dropHere_i3qt2_101",menuWrap:"_menuWrap_i3qt2_111",menu:"_menu_i3qt2_19",dangerItem:"_dangerItem_i3qt2_163"},N1={video:Ro,pdf:Ho,h5p:Wo,scorm:Ko,audio:Qo,quiz:Vo,default:mn},k1=({node:e,style:t,dragHandle:r,editorMode:n})=>{const[s,i]=h.useState(!1),[o,a]=h.useState(!1),[c,d]=h.useState(e.data.name),u=h.useRef(null),f=n==="edit",g=Za(),y=Yi(e.data),_=N1[y.key]??mn,p=e.isSelected,v=e.level===0,m=e.data.isFolder??(e.children&&e.children.length>0),b=v?mv:m?Cv:_;h.useEffect(()=>{if(!s)return;const E=T=>{var x;(x=u.current)!=null&&x.contains(T.target)||i(!1)};return document.addEventListener("mousedown",E),()=>document.removeEventListener("mousedown",E)},[s]);const S=h.useCallback(()=>{c.trim()&&e.submit(c.trim()),a(!1)},[c,e]),w=h.useCallback(E=>{E.key==="Enter"&&S(),E.key==="Escape"&&(d(e.data.name),a(!1))},[S,e.data.name]);return l.jsxs("div",{className:[Tt.row,p?Tt.selected:"",e.state.isOver&&m?Tt.dropTarget:""].filter(Boolean).join(" "),style:t,onClick:()=>e.select(),"data-node-id":e.data.id,"data-droppable":m?"true":void 0,role:"treeitem","aria-selected":p,"aria-expanded":m?!e.isClosed:void 0,children:[f&&l.jsx("span",{ref:r,className:Tt.grip,"aria-hidden":"true",children:l.jsx(Wc,{size:14})}),l.jsx("button",{className:Tt.toggle,onClick:E=>{E.stopPropagation(),e.toggle()},"aria-label":e.isClosed?"Expand":"Collapse",style:{visibility:m?"visible":"hidden"},children:e.isClosed?l.jsx(zc,{size:14}):l.jsx(hs,{size:14})}),l.jsx("span",{className:`${Tt.ctIcon} ${v||m?Tt.folderIcon:y.bgClass}`,"aria-hidden":"true",children:l.jsx(b,{size:12})}),o?l.jsx("input",{className:Tt.renameInput,value:c,autoFocus:!0,onChange:E=>d(E.target.value),onBlur:S,onKeyDown:w,onClick:E=>E.stopPropagation()}):l.jsx("span",{className:Tt.title,title:e.data.name,onDoubleClick:()=>f&&a(!0),children:e.data.name.length>25?`${e.data.name.slice(0,25)}...`:e.data.name}),e.state.isOver&&m&&l.jsx("span",{className:Tt.dropHere,"aria-hidden":"true",children:"Drop here"}),f&&l.jsxs("div",{className:Tt.menuWrap,ref:u,children:[l.jsx("button",{className:Tt.menuBtn,onClick:E=>{E.stopPropagation(),i(T=>!T)},"aria-label":"Node options",children:l.jsx(qc,{size:14})}),s&&l.jsxs("div",{className:Tt.menu,role:"menu",children:[l.jsxs("button",{role:"menuitem",onClick:()=>{a(!0),i(!1)},children:[l.jsx(Nv,{size:13})," Rename"]}),m&&g&&l.jsxs("button",{role:"menuitem",onClick:()=>{e.tree.create({parentId:e.id}),i(!1)},children:[l.jsx(Hc,{size:13})," Add sub-unit"]}),e.data.parent&&g&&l.jsxs("button",{role:"menuitem",onClick:()=>{e.tree.create({parentId:e.data.parent}),i(!1)},children:[l.jsx(ps,{size:13})," Add Sibling"]}),l.jsxs("button",{role:"menuitem",className:Tt.dangerItem,onClick:()=>{e.tree.delete(e.id),i(!1)},children:[l.jsx(Yo,{size:13})," Delete"]})]})]})]})};async function x1(e,t){var i,o;const n=((i=(await Ae.post(`/action/content/v3/upload/url/${e}?type=hierarchy`,{request:{content:{fileName:t}}})).data)==null?void 0:i.result)??{},s=((o=n.content)==null?void 0:o.preSignedURL)??n.pre_signed_url??n.preSignedUrl;if(!s)throw new Error("Could not obtain an upload URL");return s}async function A1(e,t){const r=await fetch(e,{method:"PUT",headers:{"x-ms-blob-type":"BlockBlob","Content-Type":"text/csv"},body:t});if(!r.ok)throw new Error(`Blob upload failed (${r.status})`);return e.split("?")[0]}async function P1(e,t){var a;const r=await x1(e,t.name),n=await A1(r,t),s=new FormData;return s.append("fileUrl",n),s.append("mimeType",t.type||"text/csv"),{processId:(((a=(await Ae.post(`/action/collection/v1/import/${e}`,s)).data)==null?void 0:a.result)??{}).processId??""}}async function M1(e){var r;return((r=(await Ae.get(`/action/collection/v1/import/status/${e}`)).data)==null?void 0:r.result)??{status:"PENDING"}}async function Wf(e){var n,s,i;const r=(i=(s=(n=(await Ae.get(`/action/collection/v1/export/${e}`)).data)==null?void 0:n.result)==null?void 0:s.collection)==null?void 0:i.tocUrl;if(!r)throw new Error("No export URL returned");return r}async function L1(e){return Wf(e)}const Pe={container:"_container_jr3ij_1",header:"_header_jr3ij_13",title:"_title_jr3ij_22",closeBtn:"_closeBtn_jr3ij_29",body:"_body_jr3ij_45",dropZone:"_dropZone_jr3ij_54",dragOver:"_dragOver_jr3ij_67",hasFile:"_hasFile_jr3ij_72",hiddenInput:"_hiddenInput_jr3ij_78",fileInfo:"_fileInfo_jr3ij_82",fileIcon:"_fileIcon_jr3ij_89",fileName:"_fileName_jr3ij_93",fileSize:"_fileSize_jr3ij_100",dropHint:"_dropHint_jr3ij_105",dropIcon:"_dropIcon_jr3ij_112",dropText:"_dropText_jr3ij_117",dropSubtext:"_dropSubtext_jr3ij_124",sampleLink:"_sampleLink_jr3ij_130",statusBar:"_statusBar_jr3ij_145",status_uploading:"_status_uploading_jr3ij_154",status_processing:"_status_processing_jr3ij_154",status_done:"_status_done_jr3ij_159",status_error:"_status_error_jr3ij_164",successDetail:"_successDetail_jr3ij_170",spinner:"_spinner_jr3ij_175",spin:"_spin_jr3ij_175",errorMsg:"_errorMsg_jr3ij_191",failedSection:"_failedSection_jr3ij_197",failedTitle:"_failedTitle_jr3ij_203",tableWrap:"_tableWrap_jr3ij_213",failedTable:"_failedTable_jr3ij_219",reasonCell:"_reasonCell_jr3ij_244",footer:"_footer_jr3ij_248"},F1=({contentId:e,onComplete:t,onClose:r,mode:n="create"})=>{const[s,i]=h.useState(null),[o,a]=h.useState(!1),[c,d]=h.useState("idle"),[u,f]=h.useState(""),[g,y]=h.useState([]),[_,p]=h.useState(null),v=h.useRef(null),m=h.useRef(null),b=h.useCallback(()=>{m.current!==null&&(clearInterval(m.current),m.current=null)},[]);h.useEffect(()=>()=>b(),[b]);const S=N=>N.name.toLowerCase().endsWith(".csv")?N.size>50*1024*1024?(f("File size must not exceed 50 MB."),!1):!0:(f("Only .csv files are accepted."),!1),w=h.useCallback(N=>{f(""),y([]),p(null),d("idle"),S(N)&&i(N)},[]),E=h.useCallback(N=>{N.preventDefault(),a(!1);const M=N.dataTransfer.files[0];M&&w(M)},[w]),T=h.useCallback(N=>{var j;const M=(j=N.target.files)==null?void 0:j[0];M&&w(M),N.target.value=""},[w]),x=h.useCallback(async()=>{try{const N=await L1(e),M=document.createElement("a");M.href=N,M.download="sample_hierarchy.csv",M.target="_blank",M.click()}catch{f("Failed to download sample CSV.")}},[e]),P=h.useCallback(async()=>{if(s){d("uploading"),f(""),y([]);try{const{processId:N}=await P1(e,s);if(!N){d("done"),p(null),setTimeout(t,1500);return}d("processing"),m.current=setInterval(async()=>{try{const M=await M1(N);M.status==="COMPLETED"?(b(),d("done"),p(M.successCount??null),M.failedRecords&&M.failedRecords.length>0?y(M.failedRecords):setTimeout(t,1500)):M.status==="FAILED"&&(b(),d("error"),f("Upload processing failed. Please check the error rows below."),M.failedRecords&&y(M.failedRecords))}catch{b(),d("error"),f("Lost connection while checking status. Please try again.")}},2e3)}catch{d("error"),f("Upload failed. Please check your file and try again.")}}},[e,s,t,b]),F={idle:"",uploading:"Uploading...",processing:"Processing...",done:"Done!",error:"Error"};return l.jsxs("div",{className:Pe.container,children:[l.jsxs("div",{className:Pe.header,children:[l.jsx("h2",{className:Pe.title,children:n==="update"?"Update Folder Metadata via CSV":"Create Folders via CSV"}),l.jsx("button",{className:Pe.closeBtn,onClick:r,"aria-label":"Close",children:"✕"})]}),l.jsxs("div",{className:Pe.body,children:[l.jsxs("div",{className:`${Pe.dropZone} ${o?Pe.dragOver:""} ${s?Pe.hasFile:""}`,onDragEnter:N=>{N.preventDefault(),a(!0)},onDragOver:N=>{N.preventDefault(),a(!0)},onDragLeave:N=>{N.preventDefault(),a(!1)},onDrop:E,onClick:()=>{var N;return(N=v.current)==null?void 0:N.click()},role:"button",tabIndex:0,"aria-label":"Drop CSV file here or click to browse",onKeyDown:N=>{var M;return N.key==="Enter"&&((M=v.current)==null?void 0:M.click())},children:[l.jsx("input",{ref:v,type:"file",accept:".csv",className:Pe.hiddenInput,onChange:T,"aria-hidden":"true"}),s?l.jsxs("div",{className:Pe.fileInfo,children:[l.jsx("span",{className:Pe.fileIcon,children:"📄"}),l.jsx("span",{className:Pe.fileName,children:s.name}),l.jsxs("span",{className:Pe.fileSize,children:["(",(s.size/1024).toFixed(1)," KB)"]})]}):l.jsxs("div",{className:Pe.dropHint,children:[l.jsx("span",{className:Pe.dropIcon,children:"⬆️"}),l.jsx("p",{className:Pe.dropText,children:"Drag & drop your CSV here"}),l.jsx("p",{className:Pe.dropSubtext,children:"or click to browse"})]})]}),l.jsx("button",{className:Pe.sampleLink,onClick:x,type:"button",children:"Download Sample CSV"}),c!=="idle"&&l.jsxs("div",{className:`${Pe.statusBar} ${Pe[`status_${c}`]}`,role:"status","aria-live":"polite",children:[c==="processing"&&l.jsx("span",{className:Pe.spinner,"aria-hidden":"true"}),F[c],c==="done"&&_!==null&&l.jsxs("span",{className:Pe.successDetail,children:[" — ",_," item(s) imported"]})]}),u&&l.jsx("p",{className:Pe.errorMsg,role:"alert",children:u}),g.length>0&&l.jsxs("div",{className:Pe.failedSection,children:[l.jsxs("h4",{className:Pe.failedTitle,children:["Failed Rows (",g.length,")"]}),l.jsx("div",{className:Pe.tableWrap,children:l.jsxs("table",{className:Pe.failedTable,children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{children:"Row"}),l.jsx("th",{children:"Name"}),l.jsx("th",{children:"Reason"})]})}),l.jsx("tbody",{children:g.map((N,M)=>l.jsxs("tr",{children:[l.jsx("td",{children:N.rowNumber??M+1}),l.jsx("td",{children:N.name??"—"}),l.jsx("td",{className:Pe.reasonCell,children:N.reason??"Unknown error"})]},M))})]})})]})]}),l.jsxs("div",{className:Pe.footer,children:[l.jsx(Le,{variant:"ghost",onClick:r,disabled:c==="uploading"||c==="processing",children:"Cancel"}),l.jsx(Le,{variant:"primary",isLoading:c==="uploading"||c==="processing",disabled:!s||c==="done",onClick:P,children:c==="done"?"Uploaded":"Upload"})]})]})},rr={container:"_container_1y30m_1",header:"_header_1y30m_8",headerActions:"_headerActions_1y30m_19",iconBtn:"_iconBtn_1y30m_25",menuWrap:"_menuWrap_1y30m_43",dropdownMenu:"_dropdownMenu_1y30m_47",treeWrapper:"_treeWrapper_1y30m_79",csvModal:"_csvModal_1y30m_95",footer:"_footer_1y30m_105"},$1=({editorMode:e,collapsed:t=!1,onToggleCollapse:r})=>{var ce;const n=h.useRef(null),s=h.useRef(null),i=h.useRef(null),[o,a]=h.useState(400),[c,d]=h.useState(!1),[u,f]=h.useState(!1),[g,y]=h.useState("create"),{treeData:_,selectedNodeId:p,selectNode:v,addNode:m,deleteNode:b,reorderChildren:S,moveNode:w,setTreeData:E}=xe(),T=e==="edit",x=Za(),P=T&&x,F=(((ce=_[0])==null?void 0:ce.children)??[]).some(Q=>Q.isFolder),N=ae(Q=>{var J,ie,B,R;return((ie=(J=Q.editorConfig)==null?void 0:J.context)==null?void 0:ie.contentId)??((R=(B=Q.editorConfig)==null?void 0:B.context)==null?void 0:R.identifier)??""}),M=ae(Q=>{var ie,B;const J=(B=(ie=Q.categoryMeta)==null?void 0:ie.sourcingSettings)==null?void 0:B.collection;return(J==null?void 0:J.enableBulkUpload)!==!1});h.useEffect(()=>{const Q=s.current;if(!Q)return;const J=new ResizeObserver(()=>{a(Q.clientHeight||400)});return J.observe(Q),a(Q.clientHeight||400),()=>J.disconnect()},[]),h.useEffect(()=>{if(!c)return;const Q=J=>{var ie;(ie=i.current)!=null&&ie.contains(J.target)||d(!1)};return document.addEventListener("mousedown",Q),()=>document.removeEventListener("mousedown",Q)},[c]);const j=h.useCallback(Q=>{Q.length>0&&v(Q[0].data.id)},[v]),A=h.useCallback(({parentId:Q,index:J,dragIds:ie})=>{if(!Q)return;const B=ie[0],R=Ja(_,B);if(!R)return;const K=R.parent;if(K===Q){const de=Ja(_,Q);if(!(de!=null&&de.children))return;const Oe=de.children.findIndex(Be=>Be.id===B);if(Oe<0)return;S(Q,Oe,J>Oe?J-1:J)}else w(B,K??"",Q)},[_,S,w]),$=h.useCallback(({ids:Q})=>{Q.forEach(J=>b(J))},[b]),U=h.useCallback(({parentId:Q})=>{var B;const J=Q??((B=_[0])==null?void 0:B.id)??"";if(!J)return{id:crypto.randomUUID()};const ie=m(J,"unit");return ie?{id:ie}:(Ie.error("Maximum depth reached"),{id:crypto.randomUUID()})},[m,_]),Z=h.useCallback(()=>{var J;const Q=(J=_[0])==null?void 0:J.id;Q&&(m(Q,"unit")||Ie.error("Maximum depth reached"))},[_,m]),se=h.useCallback(()=>{p&&(m(p,"subunit")||Ie.error("Maximum depth reached"))},[p,m]),be=h.useCallback(async()=>{if(d(!1),!!N)try{const Q=await Wf(N),J=await fetch(Q).then(R=>R.blob()),ie=URL.createObjectURL(J),B=document.createElement("a");B.href=ie,B.download=`${N}-folders.csv`,B.style.display="none",document.body.appendChild(B),B.click(),document.body.removeChild(B),URL.revokeObjectURL(ie)}catch{Ie.error("Failed to download CSV")}},[N]),Ee=h.useCallback(async()=>{if(f(!1),!!N)try{const{rootNode:Q}=await Zu(N);E([Q]),Ie.success("Course outline refreshed.")}catch{Ie.error("Outline could not be refreshed automatically. Please reload the page.")}},[N,E]);return l.jsxs("div",{className:rr.container,children:[l.jsx("div",{className:rr.header,children:l.jsxs("div",{className:rr.headerActions,children:[T&&l.jsxs("div",{className:rr.menuWrap,ref:i,children:[l.jsx("button",{type:"button",className:rr.iconBtn,onClick:()=>d(Q=>!Q),"aria-label":"More options",title:"More options","aria-haspopup":"true","aria-expanded":c,children:l.jsx(qc,{size:15})}),c&&l.jsx("div",{className:rr.dropdownMenu,role:"menu",children:M&&l.jsxs(l.Fragment,{children:[l.jsx("button",{role:"menuitem",type:"button",disabled:F,title:F?'Folders already exist — use "Update" instead':void 0,onClick:()=>{d(!1),y("create"),f(!0)},children:"Create folders using csv file"}),l.jsx("button",{role:"menuitem",type:"button",disabled:!F,title:F?void 0:'No folders yet — use "Create" first',onClick:be,children:"Download folders as csv file"}),l.jsx("button",{role:"menuitem",type:"button",disabled:!F,title:F?void 0:'No folders yet — use "Create" first',onClick:()=>{d(!1),y("update"),f(!0)},children:"Update folder metadata using csv file"})]})})]}),r&&l.jsx("button",{type:"button",className:rr.iconBtn,onClick:r,"aria-label":t?"Expand outline":"Collapse outline",title:t?"Expand outline":"Collapse outline",children:t?l.jsx(Dv,{size:15}):l.jsx(Iv,{size:15})})]})}),l.jsx("div",{className:rr.treeWrapper,ref:s,children:l.jsx(O1,{ref:n,data:_,idAccessor:"id",childrenAccessor:"children",onSelect:j,onMove:T?A:void 0,onDelete:T?$:void 0,onCreate:T?U:void 0,disableEdit:!T,disableDrop:!T,selection:p??void 0,rowHeight:40,indent:20,paddingBottom:16,height:o,width:"100%",children:Q=>l.jsx(k1,{...Q,editorMode:e})})}),T&&l.jsxs("div",{className:rr.footer,children:[l.jsxs(Le,{variant:"ghost",size:"sm",onClick:Z,disabled:!P,children:[l.jsx(ps,{size:14})," Add Unit"]}),l.jsxs(Le,{variant:"ghost",size:"sm",onClick:se,disabled:!P||!p,children:[l.jsx(Hc,{size:14})," Add Sub-unit"]})]}),u&&l.jsx("div",{className:rr.csvModal,children:l.jsx(F1,{contentId:N,mode:g,onComplete:Ee,onClose:()=>f(!1)})})]})};function Ja(e,t){for(const r of e){if(r.id===t)return r;if(r.children){const n=Ja(r.children,t);if(n)return n}}}const Ds={breadcrumb:"_breadcrumb_zd1aj_1",crumb:"_crumb_zd1aj_10",sep:"_sep_zd1aj_26",current:"_current_zd1aj_31"},j1=({crumbs:e})=>{const t=xe(r=>r.selectNode);return e.length?l.jsxs("nav",{className:Ds.breadcrumb,"aria-label":"Node path",children:[l.jsx("button",{className:Ds.crumb,onClick:()=>t(e[0].id),"aria-label":"Home",children:l.jsx(Ev,{size:13})}),e.map((r,n)=>l.jsxs(h.Fragment,{children:[l.jsx(zc,{size:13,className:Ds.sep}),n<e.length-1?l.jsx("button",{className:Ds.crumb,onClick:()=>t(r.id),children:r.name}):l.jsx("span",{className:Ds.current,children:r.name})]},r.id))]}):null},Ts={tabBar:"_tabBar_qhks1_1",tab:"_tab_qhks1_1",active:"_active_qhks1_29",error:"_error_qhks1_35",errorDot:"_errorDot_qhks1_39"},Qf=[{id:"details",label:"Details"},{id:"audience",label:"Audience & Curriculum"},{id:"licensing",label:"Licensing"}],B1=({activeTab:e,onChange:t,errorTabs:r=[],visibleTabs:n})=>{const s=n?Qf.filter(i=>n.includes(i.id)):Qf;return l.jsx("div",{className:Ts.tabBar,role:"tablist","aria-label":"Metadata sections",children:s.map(i=>l.jsxs("button",{role:"tab","aria-selected":e===i.id,"aria-controls":`panel-${i.id}`,className:[Ts.tab,e===i.id?Ts.active:"",r.includes(i.id)?Ts.error:""].join(" "),onClick:()=>t(i.id),children:[i.label,r.includes(i.id)&&l.jsx("span",{className:Ts.errorDot,"aria-label":"Has errors"})]},i.id))})};var Ns=e=>e.type==="checkbox",Rr=e=>e instanceof Date,ut=e=>e==null;const Kf=e=>typeof e=="object";var He=e=>!ut(e)&&!Array.isArray(e)&&Kf(e)&&!Rr(e),el=e=>He(e)&&e.target?Ns(e.target)?e.target.checked:e.target.value:e,Gf=(e,t)=>t.split(".").some((r,n,s)=>!isNaN(Number(r))&&e.has(s.slice(0,n).join("."))),Yf=e=>{const t=e.constructor&&e.constructor.prototype;return He(t)&&t.hasOwnProperty("isPrototypeOf")},Ri=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function Ge(e){if(e instanceof Date)return new Date(e);const t=typeof FileList<"u"&&e instanceof FileList;if(Ri&&(e instanceof Blob||t))return e;const r=Array.isArray(e);if(!r&&!(He(e)&&Yf(e)))return e;const n=r?[]:Object.create(Object.getPrototypeOf(e));for(const s in e)Object.prototype.hasOwnProperty.call(e,s)&&(n[s]=Ge(e[s]));return n}const Tr={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change",SUBMIT:"submit",TRIGGER:"trigger",VALID:"valid"},Gt={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},Yt={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"},tl="form",Rf="root",Xf=["__proto__","constructor","prototype"];var ks=e=>/^\w*$/.test(e),Ue=e=>e===void 0,Xi=e=>e.split(/[.[\]'"]/g).filter(Boolean),W=(e,t,r)=>{if(!t||!He(e))return r;const n=ks(t)?[t]:Xi(t);if(n.some(i=>Xf.includes(i)))return r;const s=n.reduce((i,o)=>ut(i)?void 0:i[o],e);return Ue(s)||s===e?Ue(e[t])?r:e[t]:s},Pt=e=>typeof e=="boolean",mt=e=>typeof e=="function",je=(e,t,r)=>{let n=-1;const s=ks(t)?[t]:Xi(t),i=s.length,o=i-1;for(;++n<i;){const a=s[n];let c=r;if(n!==o){const d=e[a];c=He(d)||Array.isArray(d)?d:isNaN(+s[n+1])?{}:[]}if(Xf.includes(a))return;e[a]=c,e=e[a]}};const rl=h.createContext(null);rl.displayName="HookFormControlContext";const nl=()=>h.useContext(rl);var Zf=(e,t,r,n=!0)=>{const s={};for(const i in e)Object.defineProperty(s,i,{get:()=>{const o=i;return t._proxyFormState[o]!==Gt.all&&(t._proxyFormState[o]=!n||Gt.all),r&&(r[o]=!0),e[o]}});return s};const sl=Ri?h.useLayoutEffect:h.useEffect;function U1(e){const t=nl(),{control:r=t,disabled:n,name:s,exact:i}=e||{},[o,a]=h.useState(()=>({...r._formState,defaultValues:r._defaultValues})),c=h.useRef({isDirty:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,validatingFields:!1,isValidating:!1,isValid:!1,errors:!1});return sl(()=>r._subscribe({name:s,formState:c.current,exact:i,callback:d=>{!n&&a({...r._formState,...d,defaultValues:r._defaultValues})}}),[s,n,i]),h.useEffect(()=>{c.current.isValid&&r._setValid(!0)},[r]),h.useMemo(()=>Zf(o,r,c.current,!1),[o,r])}var bt=e=>typeof e=="string",il=(e,t,r,n,s)=>bt(e)?(n&&t.watch.add(e),W(r,e,s)):Array.isArray(e)?e.map(i=>(n&&t.watch.add(i),W(r,i))):(n&&(t.watchAll=!0),r),ol=e=>ut(e)||!Kf(e);const Jf=(e,t)=>t.length===0&&!Array.isArray(e)&&!Yf(e);function Mt(e,t,r=new WeakMap){if(e===t)return!0;if(ol(e)||ol(t))return Object.is(e,t);if(Rr(e)&&Rr(t))return Object.is(e.getTime(),t.getTime());const n=Object.keys(e),s=Object.keys(t);if(n.length!==s.length)return!1;if(Jf(e,n)||Jf(t,s))return Object.is(e,t);const i=r.get(e);if(i&&i.has(t))return!0;i?i.add(t):r.set(e,new WeakSet([t]));for(const o of n){const a=e[o];if(!(o in t))return!1;if(o!=="ref"){const c=t[o];if(Rr(a)&&Rr(c)||(He(a)||Array.isArray(a))&&(He(c)||Array.isArray(c))?!Mt(a,c,r):!Object.is(a,c))return!1}}return!0}function z1(e){const t=nl(),{control:r=t,name:n,defaultValue:s,disabled:i,exact:o,compute:a}=e||{},c=h.useRef(s),d=h.useRef(a),u=h.useRef(void 0),f=h.useRef(r),g=h.useRef(n);d.current=a;const[y,_]=h.useState(()=>{const w=r._getWatch(n,c.current);return d.current?d.current(w):w}),p=h.useCallback(w=>{const E=il(n,r._names,w||r._formValues,!1,c.current);return d.current?d.current(E):E},[r._formValues,r._names,n]),v=h.useCallback(w=>{if(!i){const E=il(n,r._names,w||r._formValues,!1,c.current);if(d.current){const T=d.current(E);Mt(T,u.current)||(_(T),u.current=T)}else _(E)}},[r._formValues,r._names,i,n]);sl(()=>((f.current!==r||!Mt(g.current,n))&&(f.current=r,g.current=n,v()),r._subscribe({name:n,formState:{values:!0},exact:o,callback:w=>{v(w.values)}})),[r,o,n,v]),h.useEffect(()=>r._removeUnmounted());const m=f.current!==r,b=g.current,S=h.useMemo(()=>{if(i)return null;const w=!m&&!Mt(b,n);return m||w?p():null},[i,m,n,b,p]);return S!==null?S:y}function Zi(e){const t=nl(),{name:r,disabled:n,control:s=t,shouldUnregister:i,defaultValue:o,exact:a=!0}=e,c=Gf(s._names.array,r),d=h.useMemo(()=>W(s._formValues,r,W(s._defaultValues,r,o)),[s,r,o]),u=z1({control:s,name:r,defaultValue:d,exact:a}),f=U1({control:s,name:r,exact:a}),g=h.useRef(e),y=h.useRef(null),_=h.useRef(s.register(r,{...e.rules,value:u,...Pt(e.disabled)?{disabled:e.disabled}:{}}));g.current=e;const p=h.useMemo(()=>Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!W(f.errors,r)},isDirty:{enumerable:!0,get:()=>!!W(f.dirtyFields,r)},isTouched:{enumerable:!0,get:()=>!!W(f.touchedFields,r)},isValidating:{enumerable:!0,get:()=>!!W(f.validatingFields,r)},error:{enumerable:!0,get:()=>W(f.errors,r)}}),[f,r]),v=h.useCallback(w=>{const E=el(w);return W(s._fields,r)||(_.current=s.register(r,{...g.current.rules,value:E})),_.current.onChange({target:{value:el(w),name:r},type:Tr.CHANGE})},[r,s]),m=h.useCallback(()=>_.current.onBlur({target:{value:W(s._formValues,r),name:r},type:Tr.BLUR}),[r,s._formValues]),b=h.useCallback(w=>{w&&(y.current={focus:()=>mt(w.focus)&&w.focus(),select:()=>mt(w.select)&&w.select(),setCustomValidity:T=>mt(w.setCustomValidity)&&w.setCustomValidity(T),reportValidity:()=>mt(w.reportValidity)&&w.reportValidity()});const E=W(s._fields,r);E&&E._f&&w&&(E._f.ref=y.current)},[s._fields,r]),S=h.useMemo(()=>({name:r,value:u,...Pt(n)||f.disabled?{disabled:f.disabled||n}:{},onChange:v,onBlur:m,ref:b}),[r,n,f.disabled,v,m,b,u]);return h.useEffect(()=>{const w=s._options.shouldUnregister||i;s.register(r,{...g.current.rules,...Pt(g.current.disabled)?{disabled:g.current.disabled}:{}});const E=(T,x)=>{const P=W(s._fields,T);P&&P._f&&(P._f.mount=x)};if(E(r,!0),w){const T=Ge(W(i?s._defaultValues:s._options.values||s._defaultValues,r,W(s._options.defaultValues,r,g.current.defaultValue)));je(s._defaultValues,r,T),Ue(W(s._formValues,r))&&je(s._formValues,r,T)}if(!c&&s.register(r),y.current){const T=W(s._fields,r);T&&T._f&&(T._f.ref=y.current)}return()=>{(c?w&&!s._state.action:w)?s.unregister(r):E(r,!1)}},[r,s,c,i]),h.useEffect(()=>{s._setDisabledField({disabled:n,name:r})},[n,r,s]),h.useMemo(()=>({field:S,formState:f,fieldState:p}),[S,f,p])}const al=h.createContext(null);al.displayName="HookFormContext";const Rt=()=>h.useContext(al),V1=({children:e,watch:t,getValues:r,getFieldState:n,setError:s,clearErrors:i,setValue:o,setValues:a,trigger:c,formState:d,resetField:u,reset:f,handleSubmit:g,unregister:y,control:_,register:p,setFocus:v,subscribe:m})=>{const b=h.useMemo(()=>({watch:t,getValues:r,getFieldState:n,setError:s,clearErrors:i,setValue:o,setValues:a,trigger:c,formState:d,resetField:u,reset:f,handleSubmit:g,unregister:y,control:_,register:p,setFocus:v,subscribe:m}),[i,_,d,n,r,g,p,f,u,s,v,o,a,m,c,y,t]);return h.createElement(al.Provider,{value:b},h.createElement(rl.Provider,{value:b.control},e))};var q1=(e,t,r,n,s)=>t?{...r[e],types:{...r[e]&&r[e].types?r[e].types:{},[n]:s||!0}}:{},eh=e=>Array.isArray(e)?e.filter(Boolean):[],Ji=e=>Array.isArray(e)?e:[e],th=()=>{let e=[];return{get observers(){return e},next:s=>{for(const i of e)i.next&&i.next(s)},subscribe:s=>(e.push(s),{unsubscribe:()=>{e=e.filter(i=>i!==s)}}),unsubscribe:()=>{e=[]}}};function rh(e,t){const r={};for(const n in e)if(e.hasOwnProperty(n)){const s=e[n],i=t[n];if(s&&He(s)&&i){const o=rh(s,i);He(o)&&(r[n]=o)}else e[n]&&(r[n]=i)}return r}var nt=e=>He(e)&&!Object.keys(e).length,ll=e=>e.type==="file",eo=e=>{if(!Ri)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},nh=e=>e.type==="select-multiple",cl=e=>e.type==="radio",H1=e=>cl(e)||Ns(e),ul=e=>eo(e)&&e.isConnected;function W1(e,t){const r=t.slice(0,-1).length;let n=0;for(;n<r;){if(ut(e)){e=void 0;break}e=e[t[n]],n++}return e}function Q1(e){for(const t in e)if(e.hasOwnProperty(t)&&!Ue(e[t]))return!1;return!0}function Ze(e,t){if(bt(t)&&Object.prototype.hasOwnProperty.call(e,t))return delete e[t],e;const r=Array.isArray(t)?t:ks(t)?[t]:Xi(t),n=r.length===1?e:W1(e,r),s=r.length-1,i=r[s];return n&&delete n[i],s!==0&&(He(n)&&nt(n)||Array.isArray(n)&&Q1(n))&&Ze(e,r.slice(0,-1)),e}var K1=e=>{for(const t in e)if(mt(e[t]))return!0;return!1};function sh(e){return Array.isArray(e)||He(e)&&!K1(e)}function dl(e,t={}){for(const r in e){const n=e[r];sh(n)?(t[r]=Array.isArray(n)?[]:{},dl(n,t[r])):Ue(n)||(t[r]=!0)}return t}function fl(e){if(e!==!1){if(e===!0)return!0;if(Array.isArray(e)){const t=e.map(r=>fl(r));return t.some(r=>r!==void 0)?t:void 0}if(He(e)){const t={};for(const r in e){const n=fl(e[r]);Ue(n)||(t[r]=n)}return Object.keys(t).length?t:void 0}}}function Xr(e,t,r){r||(r=dl(t));for(const n in e){const s=e[n];if(sh(s))Ue(t)||ol(r[n])?r[n]=dl(s,Array.isArray(s)?[]:{}):Xr(s,ut(t)?{}:t[n],r[n]);else{const i=t[n];r[n]=!Mt(s,i)}}return fl(r)||{}}const ih={value:!1,isValid:!1},oh={value:!0,isValid:!0};var ah=e=>{if(Array.isArray(e)){if(e.length>1){const t=e.filter(r=>r&&r.checked&&!r.disabled).map(r=>r.value);return{value:t,isValid:!!t.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!Ue(e[0].attributes.value)?Ue(e[0].value)||e[0].value===""?oh:{value:e[0].value,isValid:!0}:oh:ih}return ih},lh=(e,{valueAsNumber:t,valueAsDate:r,setValueAs:n})=>Ue(e)?e:t?e===""?NaN:e&&+e:r&&bt(e)?new Date(e):n?n(e):e;const ch={isValid:!1,value:null};var uh=e=>Array.isArray(e)?e.reduce((t,r)=>r&&r.checked&&!r.disabled?{isValid:!0,value:r.value}:t,ch):ch;function dh(e){const t=e.ref;return ll(t)?t.files:cl(t)?uh(e.refs).value:nh(t)?[...t.selectedOptions].map(({value:r})=>r):Ns(t)?ah(e.refs).value:lh(Ue(t.value)?e.ref.value:t.value,e)}var G1=(e,t,r,n)=>{const s={};for(const i of e){const o=W(t,i);o&&je(s,i,o._f)}return{criteriaMode:r,names:[...e],fields:s,shouldUseNativeValidation:n}},to=e=>e instanceof RegExp,xs=e=>Ue(e)?e:to(e)?e.source:He(e)?to(e.value)?e.value.source:e.value:e,fh=e=>({isOnSubmit:!e||e===Gt.onSubmit,isOnBlur:e===Gt.onBlur,isOnChange:e===Gt.onChange,isOnAll:e===Gt.all,isOnTouch:e===Gt.onTouched});const hh="AsyncFunction";var Y1=e=>!!e&&!!e.validate&&!!(mt(e.validate)&&e.validate.constructor.name===hh||He(e.validate)&&Object.values(e.validate).find(t=>t.constructor.name===hh)),R1=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate),hl=(e,t,r)=>!r&&(t.watchAll||t.watch.has(e)||[...t.watch].some(n=>e.startsWith(`${n}.`)));const As=(e,t,r,n)=>{for(const s of r||Object.keys(e)){const i=W(e,s);if(i){const{_f:o,...a}=i;if(o){if(o.refs&&o.refs[0]&&t(o.refs[0],s)&&!n)return!0;if(o.ref&&t(o.ref,o.name)&&!n)return!0;if(As(a,t))break}else if(He(a)&&As(a,t))break}}};function ph(e,t,r){const n=W(e,r);if(n||ks(r))return{error:n,name:r};const s=r.split(".");for(;s.length;){const i=s.join("."),o=W(t,i),a=W(e,i);if(o&&!Array.isArray(o)&&r!==i)return{name:r};if(a&&a.type)return{name:i,error:a};if(a&&a.root&&a.root.type)return{name:`${i}.root`,error:a.root};s.pop()}return{name:r}}var X1=(e,t,r,n)=>{r(e);const{name:s,...i}=e;return nt(i)||n&&Object.keys(i).length>=Object.keys(t).length||Object.keys(i).find(o=>t[o]===(!n||Gt.all))},Z1=(e,t,r)=>!e||!t||e===t||Ji(e).some(n=>n&&(r?n===t:n.startsWith(t)||t.startsWith(n))),J1=(e,t,r,n,s)=>s.isOnAll?!1:!r&&s.isOnTouch?!(t||e):(r?n.isOnBlur:s.isOnBlur)?!e:(r?n.isOnChange:s.isOnChange)?e:!0,eE=(e,t)=>!eh(W(e,t)).length&&Ze(e,t),gh=(e,t,r)=>{const n=W(e,r),s=Array.isArray(n)?n:[];return je(s,Rf,t[r]),je(e,r,s),e};function yh(e,t,r="validate"){if(bt(e)||Array.isArray(e)&&e.every(bt)||Pt(e)&&!e)return{type:r,message:bt(e)?e:"",ref:t}}var Mn=e=>He(e)&&!to(e)?e:{value:e,message:""},vh=async(e,t,r,n,s,i)=>{const{ref:o,refs:a,required:c,maxLength:d,minLength:u,min:f,max:g,pattern:y,validate:_,name:p,valueAsNumber:v,mount:m}=e._f,b=W(r,p);if(!m||t.has(p))return{};const S=a?a[0]:o,w=j=>{if(s&&S.reportValidity){const A=Pt(j)?"":j||"";a?a.forEach($=>$.setCustomValidity(A)):S.setCustomValidity(A),S.reportValidity()}},E={},T=cl(o),x=Ns(o),P=T||x,F=(v||ll(o))&&Ue(o.value)&&Ue(b)||eo(o)&&o.value===""||b===""||Array.isArray(b)&&!b.length,N=q1.bind(null,p,n,E),M=(j,A,$,U=Yt.maxLength,Z=Yt.minLength)=>{const se=j?A:$;E[p]={type:j?U:Z,message:se,ref:o,...N(j?U:Z,se)}};if(i?!Array.isArray(b)||!b.length:c&&(!P&&(F||ut(b))||Pt(b)&&!b||x&&!ah(a).isValid||T&&!uh(a).isValid)){const{value:j,message:A}=bt(c)?{value:!!c,message:c}:Mn(c);if(j&&(E[p]={type:Yt.required,message:A,ref:S,...N(Yt.required,A)},!n))return w(A),E}if(!F&&(!ut(f)||!ut(g))){let j,A;const $=Mn(g),U=Mn(f);if(!ut(b)&&!isNaN(b)){const Z=o.valueAsNumber||b&&+b;ut($.value)||(j=Z>$.value),ut(U.value)||(A=Z<U.value)}else{const Z=o.valueAsDate||new Date(b),se=ce=>new Date(new Date().toDateString()+" "+ce),be=o.type=="time",Ee=o.type=="week";bt($.value)&&b&&(j=be?se(b)>se($.value):Ee?b>$.value:Z>new Date($.value)),bt(U.value)&&b&&(A=be?se(b)<se(U.value):Ee?b<U.value:Z<new Date(U.value))}if((j||A)&&(M(!!j,$.message,U.message,Yt.max,Yt.min),!n))return w(E[p].message),E}if((d||u)&&!F&&(bt(b)||i&&Array.isArray(b))){const j=Mn(d),A=Mn(u),$=!ut(j.value)&&b.length>+j.value,U=!ut(A.value)&&b.length<+A.value;if(($||U)&&(M($,j.message,A.message),!n))return w(E[p].message),E}if(y&&!F&&bt(b)){const{value:j,message:A}=Mn(y);if(to(j)&&!b.match(j)&&(E[p]={type:Yt.pattern,message:A,ref:o,...N(Yt.pattern,A)},!n))return w(A),E}if(_){if(mt(_)){const j=await _(b,r),A=yh(j,S);if(A&&(E[p]={...A,...N(Yt.validate,A.message)},!n))return w(A.message),E}else if(He(_)){let j={};for(const A in _){if(!nt(j)&&!n)break;const $=yh(await _[A](b,r),S,A);$&&(j={...$,...N(A,$.message)},w($.message),n&&(E[p]=j))}if(!nt(j)&&(E[p]={ref:S,...j},!n))return E}}return w(!0),E};const tE={mode:Gt.onSubmit,reValidateMode:Gt.onChange,shouldFocusError:!0},mh={submitCount:0,isDirty:!1,isReady:!1,isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{}};function rE(e={}){let t={...tE,...e},r={...Ge(mh),isLoading:mt(t.defaultValues),errors:t.errors||{},disabled:t.disabled||!1},n={},s=He(t.defaultValues)||He(t.values)?Ge(t.defaultValues||t.values)||{}:{},i=t.shouldUnregister?{}:Ge(s),o={action:!1,mount:!1,watch:!1,keepIsValid:!1},a={mount:new Set,disabled:new Set,unMount:new Set,array:new Set,watch:new Set,registerName:new Set},c,d=0;const u={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},f={...u};let g={...f};const y={array:th(),state:th()},_=t.criteriaMode===Gt.all,p=C=>D=>{clearTimeout(d),d=setTimeout(C,D)},v=async C=>{if(!o.keepIsValid&&!t.disabled&&(f.isValid||g.isValid||C)){let D;t.resolver?(D=nt((await N()).errors),m()):D=await A({fields:n,onlyCheckValid:!0,eventType:Tr.VALID}),D!==r.isValid&&y.state.next({isValid:D})}},m=(C,D)=>{!t.disabled&&(f.isValidating||f.validatingFields||g.isValidating||g.validatingFields)&&((C||Array.from(a.mount)).forEach(k=>{k&&(D?je(r.validatingFields,k,D):Ze(r.validatingFields,k))}),y.state.next({validatingFields:r.validatingFields,isValidating:!nt(r.validatingFields)}))},b=()=>{r.dirtyFields=Xr(s,i)},S=(C,D=[],k,z,V=!0,G=!0)=>{if(z&&k&&!t.disabled){if(o.action=!0,G&&Array.isArray(W(n,C))){const q=k(W(n,C),z.argA,z.argB);V&&je(n,C,q)}if(G&&Array.isArray(W(r.errors,C))){const q=k(W(r.errors,C),z.argA,z.argB);V&&je(r.errors,C,q),eE(r.errors,C)}if((f.touchedFields||g.touchedFields)&&G&&Array.isArray(W(r.touchedFields,C))){const q=k(W(r.touchedFields,C),z.argA,z.argB);V&&je(r.touchedFields,C,q)}(f.dirtyFields||g.dirtyFields)&&b(),y.state.next({name:C,isDirty:U(C,D),dirtyFields:r.dirtyFields,errors:r.errors,isValid:r.isValid})}else je(i,C,D)},w=(C,D)=>{je(r.errors,C,D),r.errors={...r.errors},y.state.next({errors:r.errors})},E=C=>{r.errors=C,y.state.next({errors:r.errors,isValid:!1})},T=C=>{const D=ks(C)?[C]:Xi(C);let k=i,z=s;for(let V=0;V<D.length-1;V++){const G=D[V];if(k=ut(k)?k:k[G],z=ut(z)?z:z[G],k===null&&z!==null)return!0}return!1},x=(C,D,k,z)=>{const V=W(n,C);if(V){if(T(C))return;const G=Ue(W(i,C)),q=W(i,C,Ue(k)?W(s,C):k);Ue(q)||z&&z.defaultChecked||D?je(i,C,D?q:dh(V._f)):be(C,q),o.mount&&!o.action&&(v(),G&&r.isDirty&&(f.isDirty||g.isDirty)&&(U()||(r.isDirty=!1,y.state.next({...r}))),e.shouldUnregister&&G&&!Ue(W(i,C))&&hl(C,a)&&(o.watch=!0))}},P=(C,D,k,z,V)=>{let G=!1,q=!1;const te={name:C};if(!t.disabled){if(!k||z){(f.isDirty||g.isDirty)&&(q=r.isDirty,r.isDirty=te.isDirty=U(),G=q!==te.isDirty);const me=Mt(W(s,C),D);q=!!W(r.dirtyFields,C),me!==r.isDirty?r.dirtyFields=Xr(s,i):me?Ze(r.dirtyFields,C):je(r.dirtyFields,C,!0),te.dirtyFields=r.dirtyFields,G=G||(f.dirtyFields||g.dirtyFields)&&q!==!me}if(k){const me=W(r.touchedFields,C);me||(je(r.touchedFields,C,k),te.touchedFields=r.touchedFields,G=G||(f.touchedFields||g.touchedFields)&&me!==k)}G&&V&&y.state.next(te)}return G?te:{}},F=(C,D,k,z)=>{const V=W(r.errors,C),G=(f.isValid||g.isValid)&&Pt(D)&&r.isValid!==D;if(t.delayError&&k?(c=p(()=>w(C,k)),c(t.delayError)):(clearTimeout(d),c=null,k?je(r.errors,C,k):Ze(r.errors,C),r.errors={...r.errors}),(k?!Mt(V,k):V)||!nt(z)||G){const q={...z,...G&&Pt(D)?{isValid:D}:{},errors:r.errors,name:C};r={...r,...q},y.state.next(q)}},N=async C=>(m(C,!0),await t.resolver(i,t.context,G1(C||a.mount,n,t.criteriaMode,t.shouldUseNativeValidation))),M=async C=>{const{errors:D}=await N(C);if(m(C),C){for(const k of C){const z=W(D,k);z?a.array.has(k)&&He(z)&&!Object.keys(z).some(V=>!Number.isNaN(Number(V)))?gh(r.errors,{[k]:z},k):je(r.errors,k,z):Ze(r.errors,k)}r.errors={...r.errors}}else r.errors=D;return D},j=async({name:C,eventType:D})=>{if(e.validate){const k=await e.validate({formValues:i,formState:r,name:C,eventType:D});if(He(k))for(const z in k){const V=k[z];V&&Be(`${tl}.${z}`,{message:bt(V.message)?V.message:"",type:V.type||Yt.validate})}else bt(k)||!k?Be(tl,{message:k||"",type:Yt.validate}):Oe(tl);return k}return!0},A=async({fields:C,onlyCheckValid:D,name:k,eventType:z,context:V={valid:!0,runRootValidation:!1}})=>{if(e.validate&&(V.runRootValidation=!0,!await j({name:k,eventType:z})&&(V.valid=!1,D)))return V.valid;for(const G in C){const q=C[G];if(q){const{_f:te,...me}=q;if(te){const Ke=a.array.has(te.name),kt=q._f&&Y1(q._f),xt=f.validatingFields||f.isValidating||g.validatingFields||g.isValidating;kt&&xt&&m([te.name],!0);const vr=await vh(q,a.disabled,i,_,t.shouldUseNativeValidation&&!D,Ke);if(kt&&xt&&m([te.name]),vr[te.name]&&(V.valid=!1,D)||(!D&&(W(vr,te.name)?Ke?gh(r.errors,vr,te.name):je(r.errors,te.name,vr[te.name]):Ze(r.errors,te.name)),e.shouldUseNativeValidation&&vr[te.name]))break}!nt(me)&&await A({context:V,onlyCheckValid:D,fields:me,name:G,eventType:z})}}return V.valid},$=()=>{for(const C of a.unMount){const D=W(n,C);D&&(D._f.refs?D._f.refs.every(k=>!ul(k)):!ul(D._f.ref))&&$e(C)}a.unMount=new Set},U=(C,D)=>!t.disabled&&(C&&D&&je(i,C,D),!Mt(K(),s)),Z=(C,D,k)=>il(C,a,{...o.mount?i:Ue(D)?s:bt(C)?{[C]:D}:D},k,D),se=C=>eh(W(o.mount?i:s,C,t.shouldUnregister?W(s,C,[]):[])),be=(C,D,k={},z=!1)=>{const V=W(n,C);let G=D;if(V){const q=V._f;q&&(!q.disabled&&je(i,C,lh(D,q)),G=eo(q.ref)&&ut(D)?"":D,nh(q.ref)?[...q.ref.options].forEach(te=>te.selected=G.includes(te.value)):q.refs?Ns(q.ref)?q.refs.forEach(te=>{(!te.defaultChecked||!te.disabled)&&(Array.isArray(G)?te.checked=!!G.find(me=>me===te.value):te.checked=G===te.value||!!G)}):q.refs.forEach(te=>te.checked=te.value===G):ll(q.ref)?q.ref.value="":(q.ref.value=G,q.ref.type||y.state.next({name:C,values:z?i:Ge(i)})))}(k.shouldDirty||k.shouldTouch)&&P(C,G,k.shouldTouch,k.shouldDirty,!0),k.shouldValidate&&R(C)},Ee=(C,D,k,z=!1)=>{for(const V in D){if(!D.hasOwnProperty(V))return;const G=D[V],q=C+"."+V,te=W(n,q);(a.array.has(C)||He(G)||te&&!te._f)&&!Rr(G)?Ee(q,G,k,z):be(q,G,k,z)}},ce=(C,D,k,z)=>{const V=W(n,C),G=a.array.has(C),q=z?D:Ge(D),te=W(i,C),me=Mt(te,q);if(me||je(i,C,q),G)y.array.next({name:C,values:z?i:Ge(i)}),(f.isDirty||f.dirtyFields||g.isDirty||g.dirtyFields)&&k.shouldDirty&&(b(),y.state.next({name:C,dirtyFields:r.dirtyFields,isDirty:U(C,q)}));else{const Ke=Array.isArray(q)&&!q.length||nt(q);!V||V._f||ut(q)||Ke?be(C,q,k,z):Ee(C,q,k,z)}if(!me){const Ke=hl(C,a),kt=z?i:Ge(i);y.state.next({...Ke&&r,name:o.mount||Ke?C:void 0,values:kt})}},Q=(C,D,k={})=>ce(C,D,k,!1),J=(C,D={})=>{const k=mt(C)?C(i):C;if(!Mt(i,k)){i={...i,...k};for(const z of a.mount)ce(z,W(k,z),D,!0);y.state.next({...r,name:void 0,type:void 0,values:i}),D.shouldValidate&&v()}},ie=async C=>{o.mount=!0;const D=C.target;let k=D.name,z=!0;const V=W(n,k),G=me=>{z=Number.isNaN(me)||Rr(me)&&isNaN(me.getTime())||Mt(me,W(i,k,me))},q=fh(t.mode),te=fh(t.reValidateMode);if(V){let me,Ke;const kt=D.type?dh(V._f):el(C),xt=C.type===Tr.BLUR||C.type===Tr.FOCUS_OUT,vr=!R1(V._f)&&!e.validate&&!t.resolver&&!W(r.errors,k)&&!V._f.deps||J1(xt,W(r.touchedFields,k),r.isSubmitted,te,q),qs=hl(k,a,xt);je(i,k,kt),xt?(!D||!D.readOnly)&&(V._f.onBlur&&V._f.onBlur(C),c&&c(0)):V._f.onChange&&V._f.onChange(C);const fn=P(k,kt,xt),at=!nt(fn)||qs;if(!xt&&y.state.next({name:k,type:C.type,values:Ge(i)}),vr)return(f.isValid||g.isValid)&&(t.mode==="onBlur"?xt&&v():xt||v()),at&&y.state.next({name:k,...qs?{}:fn});if(!t.resolver&&e.validate&&await j({name:k,eventType:C.type}),!xt&&qs&&y.state.next({...r}),t.resolver){const{errors:wt}=await N([k]);if(m([k]),G(kt),!z){!nt(fn)&&y.state.next(fn);return}const Et=ph(r.errors,n,k),Jt=ph(wt,n,Et.name||k);me=Jt.error,k=Jt.name,Ke=nt(wt)}else m([k],!0),me=(await vh(V,a.disabled,i,_,t.shouldUseNativeValidation))[k],m([k]),G(kt),z&&(me?Ke=!1:(f.isValid||g.isValid)&&(Ke=await A({fields:n,onlyCheckValid:!0,name:k,eventType:C.type})));z&&(V._f.deps&&(!Array.isArray(V._f.deps)||V._f.deps.length>0)&&R(V._f.deps),F(k,Ke,me,fn))}},B=(C,D)=>{if(W(r.errors,D)&&C.focus)return C.focus(),1},R=async(C,D={})=>{let k,z;const V=Ji(C);if(t.resolver){const G=await M(Ue(C)?C:V);k=nt(G),z=C?!V.some(q=>W(G,q)):k}else C?(z=(await Promise.all(V.map(async G=>{const q=W(n,G);return await A({fields:q&&q._f?{[G]:q}:q,eventType:Tr.TRIGGER})}))).every(Boolean),!(!z&&!r.isValid)&&v()):z=k=await A({fields:n,name:C,eventType:Tr.TRIGGER});return y.state.next({...!bt(C)||(f.isValid||g.isValid)&&k!==r.isValid?{}:{name:C},...t.resolver||!C?{isValid:k}:{},errors:r.errors}),D.shouldFocus&&!z&&As(n,B,C?V:a.mount),z},K=(C,D)=>{let k={...o.mount?i:s};return D&&(k=rh(D.dirtyFields?r.dirtyFields:r.touchedFields,k)),Ue(C)?k:bt(C)?W(k,C):C.map(z=>W(k,z))},de=(C,D)=>({invalid:!!W((D||r).errors,C),isDirty:!!W((D||r).dirtyFields,C),error:W((D||r).errors,C),isValidating:!!W(r.validatingFields,C),isTouched:!!W((D||r).touchedFields,C)}),Oe=C=>{const D=C?Ji(C):void 0;D==null||D.forEach(k=>Ze(r.errors,k)),D?D.forEach(k=>{y.state.next({name:k,errors:r.errors})}):y.state.next({errors:{}})},Be=(C,D,k)=>{const z=(W(n,C,{_f:{}})._f||{}).ref,V=W(r.errors,C)||{},{ref:G,message:q,type:te,...me}=V;je(r.errors,C,{...me,...D,ref:z}),y.state.next({name:C,errors:r.errors,isValid:!1}),k&&k.shouldFocus&&z&&z.focus&&z.focus()},ve=(C,D)=>mt(C)?y.state.subscribe({next:k=>"values"in k&&C(k.values||Z(void 0,D),k)}):Z(C,D,!0),ue=C=>y.state.subscribe({next:D=>{if(Z1(C.name,D.name,C.exact)&&X1(D,C.formState||f,gr,C.reRenderRoot)){const k={...i};C.callback({values:k,...r,...D,defaultValues:s})}}}).unsubscribe,ge=C=>(o.mount=!0,g={...g,...C.formState},ue({...C,formState:{...u,...C.formState}})),$e=(C,D={})=>{for(const k of C?Ji(C):a.mount)a.mount.delete(k),a.array.delete(k),D.keepValue||(Ze(n,k),Ze(i,k)),!D.keepError&&Ze(r.errors,k),!D.keepDirty&&Ze(r.dirtyFields,k),!D.keepTouched&&Ze(r.touchedFields,k),!D.keepIsValidating&&Ze(r.validatingFields,k),!t.shouldUnregister&&!D.keepDefaultValue&&Ze(s,k);y.state.next({values:Ge(i)}),y.state.next({...r,...D.keepDirty?{isDirty:U()}:{}}),!D.keepIsValid&&v()},qe=({disabled:C,name:D})=>{if(Pt(C)&&o.mount||C||a.disabled.has(D)){const V=a.disabled.has(D)!==!!C;C?a.disabled.add(D):a.disabled.delete(D),V&&o.mount&&!o.action&&v()}},ke=(C,D={})=>{let k=W(n,C);const z=Pt(D.disabled)||Pt(t.disabled),V=!a.registerName.has(C)&&k&&k._f&&!k._f.mount;return je(n,C,{...k||{},_f:{...k&&k._f?k._f:{ref:{name:C}},name:C,mount:!0,...D}}),a.mount.add(C),k&&!V?qe({disabled:Pt(D.disabled)?D.disabled:t.disabled,name:C}):x(C,!0,D.value),{...z?{disabled:D.disabled||t.disabled}:{},...t.progressive?{required:!!D.required,min:xs(D.min),max:xs(D.max),minLength:xs(D.minLength),maxLength:xs(D.maxLength),pattern:xs(D.pattern)}:{},name:C,onChange:ie,onBlur:ie,ref:G=>{if(G){a.registerName.add(C),ke(C,D),a.registerName.delete(C),k=W(n,C);const q=Ue(G.value)&&G.querySelectorAll&&G.querySelectorAll("input,select,textarea")[0]||G,te=H1(q),me=k._f.refs||[];if(te?me.find(Ke=>Ke===q):q===k._f.ref)return;je(n,C,{_f:{...k._f,...te?{refs:[...me.filter(ul),q,...Array.isArray(W(s,C))?[{}]:[]],ref:{type:q.type,name:C}}:{ref:q}}}),x(C,!1,void 0,q)}else k=W(n,C,{}),k._f&&(k._f.mount=!1),(t.shouldUnregister||D.shouldUnregister)&&!(Gf(a.array,C)&&o.action)&&a.unMount.add(C)}}},ee=()=>t.shouldFocusError&&!t.shouldUseNativeValidation&&As(n,B,a.mount),Qe=C=>{Pt(C)&&(y.state.next({disabled:C}),As(n,(D,k)=>{const z=W(n,k);z&&(D.disabled=z._f.disabled||C,Array.isArray(z._f.refs)&&z._f.refs.forEach(V=>{V.disabled=z._f.disabled||C}))},0,!1))},tt=(C,D)=>async k=>{let z;k&&(k.preventDefault&&k.preventDefault(),k.persist&&k.persist());let V=Ge(i);if(y.state.next({isSubmitting:!0}),t.resolver){const{errors:G,values:q}=await N();m(),r.errors=G,V=Ge(q)}else await A({fields:n,eventType:Tr.SUBMIT});if(a.disabled.size)for(const G of a.disabled)Ze(V,G);if(Ze(r.errors,Rf),nt(r.errors)){y.state.next({errors:{}});try{await C(V,k)}catch(G){z=G}}else D&&await D({...r.errors},k),ee(),setTimeout(ee);if(y.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:nt(r.errors)&&!z,submitCount:r.submitCount+1,errors:r.errors}),z)throw z},H=(C,D={})=>{W(n,C)&&(Ue(D.defaultValue)?Q(C,Ge(W(s,C))):(Q(C,D.defaultValue),je(s,C,Ge(D.defaultValue))),D.keepTouched||Ze(r.touchedFields,C),D.keepDirty||(Ze(r.dirtyFields,C),r.isDirty=D.defaultValue?U(C,Ge(W(s,C))):U()),D.keepError||(Ze(r.errors,C),f.isValid&&v()),y.state.next({...r}))},re=(C,D={})=>{const k=C?Ge(C):s,z=Ge(k),V=nt(C),G=z;if(D.keepDefaultValues||(s=k),!D.keepValues){if(D.keepDirtyValues){const q=new Set([...a.mount,...Object.keys(Xr(s,i))]);for(const te of Array.from(q)){const me=W(r.dirtyFields,te),Ke=W(i,te),kt=W(G,te);me&&!Ue(Ke)?je(G,te,Ke):!me&&!Ue(kt)&&Q(te,kt)}}else{if(Ri&&Ue(C))for(const q of a.mount){const te=W(n,q);if(te&&te._f){const me=Array.isArray(te._f.refs)?te._f.refs[0]:te._f.ref;if(eo(me)){const Ke=me.closest("form");if(Ke){Ke.reset();break}}}}if(D.keepFieldsRef)for(const q of a.mount)Q(q,W(G,q));else n={}}if(t.shouldUnregister){if(i=D.keepDefaultValues?Ge(s):{},D.keepFieldsRef)for(const q of a.mount)je(i,q,W(G,q))}else i=Ge(G);y.array.next({values:{...G}}),y.state.next({values:{...G}})}a={mount:D.keepDirtyValues?a.mount:new Set,unMount:new Set,array:new Set,registerName:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:""},o.mount=!f.isValid||!!D.keepIsValid||!!D.keepDirtyValues||!t.shouldUnregister&&!nt(G),o.watch=!!t.shouldUnregister,o.keepIsValid=!!D.keepIsValid,o.action=!1,D.keepErrors||(r.errors={}),y.state.next({submitCount:D.keepSubmitCount?r.submitCount:0,isDirty:V?!1:D.keepDirty?r.isDirty:D.keepValues?U():!!(D.keepDefaultValues&&!Mt(C,s)),isSubmitted:D.keepIsSubmitted?r.isSubmitted:!1,dirtyFields:V?{}:D.keepDirtyValues?D.keepDefaultValues&&i?Xr(s,i):r.dirtyFields:D.keepDefaultValues&&C?Xr(s,C):D.keepDirty?r.dirtyFields:{},touchedFields:D.keepTouched?r.touchedFields:{},errors:D.keepErrors?r.errors:{},isSubmitSuccessful:D.keepIsSubmitSuccessful?r.isSubmitSuccessful:!1,isSubmitting:!1,defaultValues:s})},oe=(C,D)=>re(mt(C)?C(i):C,{...t.resetOptions,...D}),Re=(C,D={})=>{const k=W(n,C),z=k&&k._f;if(z){const V=z.refs?z.refs[0]:z.ref;V.focus&&setTimeout(()=>{V.focus(),D.shouldSelect&&mt(V.select)&&V.select()})}},gr=C=>{r={...r,...C}},Yn={control:{register:ke,unregister:$e,getFieldState:de,handleSubmit:tt,setError:Be,_subscribe:ue,_runSchema:N,_updateIsValidating:m,_focusError:ee,_getWatch:Z,_getDirty:U,_setValid:v,_setFieldArray:S,_setDisabledField:qe,_setErrors:E,_getFieldArray:se,_reset:re,_resetDefaultValues:()=>mt(t.defaultValues)&&t.defaultValues().then(C=>{oe(C,t.resetOptions),y.state.next({isLoading:!1})}),_removeUnmounted:$,_disableForm:Qe,_subjects:y,_proxyFormState:f,get _fields(){return n},get _formValues(){return i},get _state(){return o},set _state(C){o=C},get _defaultValues(){return s},get _names(){return a},set _names(C){a=C},get _formState(){return r},get _options(){return t},set _options(C){t={...t,...C}}},subscribe:ge,trigger:R,register:ke,handleSubmit:tt,watch:ve,setValue:Q,setValues:J,getValues:K,reset:oe,resetField:H,resetDefaultValues:(C,D={})=>{if(s=Ge(C),!D.keepDirty){const k=Xr(s,i);r.dirtyFields=k,r.isDirty=!nt(k)}D.keepIsValid||v(),y.state.next({...r,defaultValues:s})},clearErrors:Oe,unregister:$e,setError:Be,setFocus:Re,getFieldState:de};return{...Yn,formControl:Yn}}function nE(e={}){const t=h.useRef(void 0),r=h.useRef(void 0),n=h.useRef(e.formControl),[s,i]=h.useState(()=>({...Ge(mh),isLoading:mt(e.defaultValues),errors:e.errors||{},disabled:e.disabled||!1,defaultValues:mt(e.defaultValues)?void 0:e.defaultValues}));if(!t.current||e.formControl&&n.current!==e.formControl)if(n.current=e.formControl,e.formControl)t.current={...e.formControl,formState:s},e.defaultValues&&!mt(e.defaultValues)&&e.formControl.reset(e.defaultValues,e.resetOptions);else{const{formControl:a,...c}=rE(e);t.current={...c,formState:s}}const o=t.current.control;return o._options=e,sl(()=>{const a=o._subscribe({formState:o._proxyFormState,callback:()=>i({...o._formState,defaultValues:o._defaultValues}),reRenderRoot:!0});return i(c=>({...c,isReady:!0})),o._formState.isReady=!0,a},[o]),h.useEffect(()=>o._disableForm(e.disabled),[o,e.disabled]),h.useEffect(()=>{e.mode&&(o._options.mode=e.mode),e.reValidateMode&&(o._options.reValidateMode=e.reValidateMode)},[o,e.mode,e.reValidateMode]),h.useEffect(()=>{e.errors&&(o._setErrors(e.errors),o._focusError())},[o,e.errors]),h.useEffect(()=>{e.shouldUnregister&&o._subjects.state.next({values:o._getWatch()})},[o,e.shouldUnregister]),h.useEffect(()=>{if(o._proxyFormState.isDirty){const a=o._getDirty();a!==s.isDirty&&o._subjects.state.next({isDirty:a})}},[o,s.isDirty]),h.useEffect(()=>{var a;e.values&&!Mt(e.values,r.current)?(o._reset(e.values,{keepFieldsRef:!0,...o._options.resetOptions}),!((a=o._options.resetOptions)===null||a===void 0)&&a.keepIsValid||o._setValid(),r.current=e.values,i(c=>({...c}))):o._resetDefaultValues()},[o,e.values]),h.useEffect(()=>{o._state.mount||(o._setValid(),o._state.mount=!0),o._state.watch&&(o._state.watch=!1,o._subjects.state.next({...o._formState})),o._removeUnmounted()}),t.current.formState=h.useMemo(()=>Zf(s,o),[o,s]),t.current}async function bh(e){var r,n;return(n=(r=(await Ae.get(`/api/framework/v1/read/${e}`)).data)==null?void 0:r.result)==null?void 0:n.framework}async function sE(e){var r,n;return((n=(r=(await Ae.post("/action/composite/v3/search",{request:{filters:{objectType:"Framework",status:["Live"],...e.type?{type:e.type}:{},...e.identifier?{identifier:e.identifier}:{},...e.channel?{channel:e.channel}:{},...e.systemDefault?{systemDefault:e.systemDefault}:{}}}})).data)==null?void 0:r.result)==null?void 0:n.Framework)??[]}function _h(e,t){const r=ts({queryKey:["framework",e],queryFn:()=>bh(e),enabled:!!e,staleTime:3e5}),n=t==null?void 0:t[0],s=ts({queryKey:["framework",n],queryFn:()=>bh(n),enabled:!!n,staleTime:5*60*1e3}),i=s.data?[s.data]:[];return{organisationFramework:r.data,targetFrameworks:i,isLoading:r.isLoading||s.isLoading}}function iE(e,t,r){const n=e??[],s=new Set(n.map(u=>u.type).filter(Boolean)),i=(t??[]).filter(u=>!s.has(u)),{data:o}=ts({queryKey:["framework-search",i.sort().join(","),r],queryFn:()=>sE({type:i,systemDefault:"Yes"}),enabled:i.length>0,staleTime:10*60*1e3}),a=t&&t.length?n.filter(u=>u.type&&t.includes(u.type)):n,c=[...(o??[]).map(u=>({label:u.name,value:u.identifier})),...a.map(u=>({label:u.name,value:u.identifier}))],d=new Set;return c.filter(u=>d.has(u.value)?!1:(d.add(u.value),!0))}async function oE(e){var r,n;return(n=(r=(await Ae.get(`/api/channel/v1/read/${e}`)).data)==null?void 0:r.result)==null?void 0:n.channel}function aE(e){var r,n,s,i,o,a;const t=ts({queryKey:["channel",e],queryFn:()=>oE(e),enabled:!!e,staleTime:6e5});return{identifier:((r=t.data)==null?void 0:r.identifier)??e??"",name:(n=t.data)==null?void 0:n.name,frameworks:(s=t.data)==null?void 0:s.frameworks,collectionAdditionalCategories:(i=t.data)==null?void 0:i.collectionAdditionalCategories,contentAdditionalCategories:(o=t.data)==null?void 0:o.contentAdditionalCategories,defaultLicense:(a=t.data)==null?void 0:a.defaultLicense,isLoading:t.isLoading}}const lE={"First Section":{title:"Basic Information",description:"Core details that define the content identity."},"Second Section":{title:"Categorisation",description:"Category and type classification for the content."},"Third Section":{title:"Categorisation",description:"Category and type classification for the content."},"Organisation Framework Terms":{title:"Curriculum",description:"Framework-aligned categorisation."},"Target Framework Terms":{title:"Target Audience",description:"Curriculum alignment for the intended learners."},"Fourth Section":{title:"Licensing & Attribution",description:"Copyright and usage rights information."},"Sixth Section":{title:"Licensing & Attribution",description:"Copyright and usage rights information."}},cE=new Set(["review","read","sourcingreview","orgreview"]),ro={"First Section":"details","Second Section":"details","Third Section":"details","Organisation Framework Terms":"details","Target Framework Terms":"audience","Fourth Section":"licensing","Sixth Section":"licensing"},uE={Categorisation:"Second Section","Basic Information":"First Section","Licensing & Attribution":"Fourth Section",Curriculum:"Organisation Framework Terms","Target Audience":"Target Framework Terms"},dE={name:"details",description:"details",keywords:"details",appIcon:"details",primaryCategory:"details",additionalCategories:"details",board:"details",boardIds:"details",subject:"details",subjectIds:"details",medium:"details",framework:"details",topicsIds:"details",topic:"details",dialcodeRequired:"details",dialcodes:"details",audience:"audience",targetBoardIds:"audience",targetMediumIds:"audience",targetGradeLevelIds:"audience",targetSubjectIds:"audience",gradeLevel:"audience",creator:"licensing",author:"licensing",attributions:"licensing",license:"licensing",copyright:"licensing",copyrightYear:"licensing"},pl={board:"board",boardIds:"board",medium:"medium",gradeLevel:"gradeLevel",subject:"subject",subjectIds:"subject",topicsIds:"topic",topic:"topic",targetBoardIds:"board",targetMediumIds:"medium",targetGradeLevelIds:"gradeLevel",targetSubjectIds:"subject"},wh=new Set(["targetBoardIds","targetMediumIds","targetGradeLevelIds","targetSubjectIds"]);function fE(e,t,r,n,s={}){if(!(e!=null&&e.length))return IE(t,n,r);const i=new Map;for(const a of e){const c=a.code;c&&!i.has(c)&&i.set(c,a)}const o=new Set;return e.filter(a=>{if(n&&(a.code==="dialCode"||a.code==="dialcode")||a.visible===!1)return!1;const c=a.code;return o.has(c)?!1:(o.add(c),!0)}).map(a=>{const c=a.code??"",d=bE(a),u=_E(a,r,t,i,s),f=t[c],g=pE(c,Sh(f,d),d,t,s),y={code:c,label:a.label??c,inputType:d,required:!!(a.required===!0||Array.isArray(a.validations)&&a.validations.some(_=>_.type==="required")),editable:hE(c,a.editable!==!1,s),placeholder:a.placeholder,maxLength:a.maxLength,options:vE(u,g,d,r),depends:a.depends,tab:mE(a),section:a.section,defaultValue:a.defaultValue??a.default,currentValue:g};if(c==="dialcodes"){const _=t.dialcodeRequired==="Yes";return{...y,required:_,visible:_}}return y})}function hE(e,t,r){var i;const n=r.editorMode??"edit";if(!cE.has(n))return t!==!1;const s=(i=r.editableFields)==null?void 0:i[n];return!!(s&&s.includes(e))}function pE(e,t,r,n,s){const i=t==null||t===""||Array.isArray(t)&&t.length===0;switch(e){case"license":return i?s.defaultLicense??"":t;case"copyright":return i&&s.setDefaultCopyRight&&s.channelName?s.channelName:t;case"author":case"creator":return i&&s.userFullName?s.userFullName:t;case"instructions":{const o=n.instructions;return o&&typeof o=="object"&&!Array.isArray(o)?o.default??"":typeof t=="object"&&t!==null?"":t}case"maxTime":case"warningTime":{if(!i)return t;const o=n.timeLimits,a=o==null?void 0:o[e];return a!=null&&a!==""?gE(Number(a)):t}default:return t}}function gE(e){if(!Number.isFinite(e)||e<0)return"";const t=Math.floor(e%60),r=Math.floor(e/60%60),n=Math.floor(e/3600),s=i=>String(i).padStart(2,"0");return n>0?`${s(n)}:${s(r)}:${s(t)}`:`${s(r)}:${s(t)}`}function yE(e){var n,s,i;const t=new Map,r=o=>o==null?void 0:o.forEach(a=>{a.identifier&&t.set(a.identifier,a.name),a.name&&t.set(a.name,a.name)});return(s=(n=e.organisationFramework)==null?void 0:n.categories)==null||s.forEach(o=>r(o.terms)),(i=e.targetFrameworks)==null||i.forEach(o=>{var a;return(a=o.categories)==null?void 0:a.forEach(c=>r(c.terms))}),t}function vE(e,t,r,n){if(r!=="select"&&r!=="multiselect"&&r!=="radio")return e;const s=Array.isArray(t)?t:t!=null&&t!==""?[t]:[];if(!s.length)return e;const i=e?[...e]:[],o=new Set(i.map(c=>c.value)),a=yE(n);for(const c of s){const d=String(c);o.has(d)||(i.push({label:a.get(d)??d,value:d}),o.add(d))}return i}function mE(e){const t=e.section;if(t){if(ro[t])return ro[t];const n=uE[t];if(n&&ro[n])return ro[n]}const r=e.code??"";return dE[r]??"details"}function Sh(e,t){const r=new Set(["multiselect","chips","keywords","tagsinput"]),n=new Set(["select","text","textarea","radio","datepicker","datetime","license"]);return r.has(t)?Array.isArray(e)?e:e!=null&&e!==""?[e]:[]:n.has(t)?Array.isArray(e)?e[0]??"":e??"":e}function bE(e){const t=(e.inputType??e.dataType??"").toLowerCase(),n=(e.dataType??"").toLowerCase()==="list";return t==="select"?"select":t==="framework"||t==="frameworkcategoryselect"?n?"multiselect":"select":t==="topicselector"?"chips":t==="multiselect"||t==="multi-select"?"multiselect":t==="keywords"||e.code==="keywords"||e.code==="topic"||e.code==="topicsIds"?"chips":t==="radio"?"radio":e.code==="appIcon"||t==="appicon"?"appIcon":t==="textarea"||e.code==="description"?"textarea":t==="datepicker"||t==="date"?"datepicker":t==="datetime"||t==="datetime-local"?"datetime":t==="tagsinput"?"tagsinput":t==="nestedselect"||t==="nested-select"?n?"multiselect":"select":t==="license"?"license":t==="dialcode"||t==="dial-code"?"dialcode":"text"}function _E(e,t,r,n,s){const i=e.code??"";if(i==="maxQuestions"){const d=s.childCount??0;if(d>0)return Array.from({length:d},(u,f)=>({label:String(f+1),value:String(f+1)}))}const o=e.range;if(Array.isArray(o)&&o.length)return typeof o[0]=="string"?o.map(d=>({label:d,value:d})):o.map(d=>({label:d.name,value:d.identifier}));const a=e.enum;if(a!=null&&a.length)return a.map(d=>({label:d,value:d}));if(i==="framework")return t.orgFrameworks;if(i==="additionalCategories"){const u=(s.objectType??"")==="QuestionSet"?s.contentAdditionalCategories??s.collectionAdditionalCategories:s.collectionAdditionalCategories??s.contentAdditionalCategories,f=(u&&u.length?u:s.contextAdditionalCategories)??t.channelAdditionalCategories;return f!=null&&f.length?EE(f).map(g=>({label:g,value:g})):void 0}const c=e.sourceCategory??pl[i];if(c)return Ch(i,c,e,t,r,n)}function wE(e,t){return wh.has(e)||t.output==="identifier"||typeof t.section=="string"&&t.section.includes("Target")}function SE(e,t){return wh.has(e)||typeof t.section=="string"&&t.section.includes("Target")}function gl(e,t,r){var i,o,a,c,d;const n=(o=(i=e.organisationFramework)==null?void 0:i.categories)==null?void 0:o.find(u=>u.code===t),s=(d=(c=(a=e.targetFrameworks)==null?void 0:a[0])==null?void 0:c.categories)==null?void 0:d.find(u=>u.code===t);return r?(s==null?void 0:s.terms)??(n==null?void 0:n.terms)??[]:(n==null?void 0:n.terms)??(s==null?void 0:s.terms)??[]}function CE(e){const t=new Set,r=[];for(const n of e){const s=n.identifier??n.name;s&&!t.has(s)&&(t.add(s),r.push(n))}return r}function EE(e){return Array.from(new Set(e))}function OE(e){return Array.isArray(e)?e:e!=null&&e!==""?[e]:[]}function Ch(e,t,r,n,s,i){const o=wE(e,r),a=SE(e,r),c=p=>({label:p.name,value:o?p.identifier:p.name}),d=r.depends;if(!(d!=null&&d.length))return gl(n,t,a).map(c);const u=d.flatMap(p=>OE(s[p])).map(String);if(!u.length)return[];const f=[];for(const p of d){const v=i.get(p),m=(v==null?void 0:v.sourceCategory)??pl[p]??p;f.push(...gl(n,m,a))}const y=f.filter(p=>u.includes(String(p.name))||u.includes(String(p.identifier))||u.includes(String(p.code))).flatMap(p=>p.associations??[]).filter(p=>String(p.category??"").toLowerCase()===t.toLowerCase()),_=CE(y);return _.length?_.map(c):gl(n,t,a).map(c)}function Ps(e,t){const r=pl[e];if(r)return Ch(e,r,{},t,{},new Map)}function dt(e,t,r){return Sh(e[t],r)}function IE(e,t,r){var s;const n=[{code:"name",label:"Title",inputType:"text",required:!0,editable:!0,tab:"details",section:"First Section",maxLength:200,currentValue:dt(e,"name","text")},{code:"description",label:"Description",inputType:"textarea",editable:!0,tab:"details",section:"First Section",maxLength:2e3,currentValue:dt(e,"description","textarea")},{code:"keywords",label:"Keywords",inputType:"chips",editable:!0,tab:"details",section:"First Section",currentValue:dt(e,"keywords","chips")}];return t&&(n.push({code:"primaryCategory",label:"Category",inputType:"select",editable:!1,tab:"details",section:"Second Section",currentValue:dt(e,"primaryCategory","select")},{code:"additionalCategories",label:"Additional Category",inputType:"multiselect",editable:!0,tab:"details",section:"Second Section",currentValue:dt(e,"additionalCategories","multiselect"),options:(s=r.channelAdditionalCategories)==null?void 0:s.map(i=>({label:i,value:i}))},{code:"framework",label:"Course Type",inputType:"select",required:!0,editable:!0,tab:"details",section:"Organisation Framework Terms",options:r.orgFrameworks,currentValue:dt(e,"framework","select")},{code:"subjectIds",label:"Subjects covered",inputType:"multiselect",required:!0,editable:!0,tab:"details",section:"Organisation Framework Terms",options:Ps("subjectIds",r),currentValue:dt(e,"subjectIds","multiselect")}),n.push({code:"audience",label:"Audience Type",inputType:"multiselect",editable:!0,tab:"audience",section:"Target Framework Terms",currentValue:dt(e,"audience","multiselect")},{code:"targetBoardIds",label:"Board/Syllabus of the audience",inputType:"select",required:!0,editable:!0,tab:"audience",section:"Target Framework Terms",options:Ps("targetBoardIds",r),currentValue:dt(e,"targetBoardIds","select")},{code:"targetMediumIds",label:"Medium(s) of the audience",inputType:"multiselect",required:!0,editable:!0,tab:"audience",section:"Target Framework Terms",depends:["targetBoardIds"],options:Ps("targetMediumIds",r),currentValue:dt(e,"targetMediumIds","multiselect")},{code:"targetGradeLevelIds",label:"Class(es) of the audience",inputType:"multiselect",required:!0,editable:!0,tab:"audience",section:"Target Framework Terms",depends:["targetMediumIds"],options:Ps("targetGradeLevelIds",r),currentValue:dt(e,"targetGradeLevelIds","multiselect")},{code:"targetSubjectIds",label:"Subject(s) of the audience",inputType:"multiselect",required:!0,editable:!0,tab:"audience",section:"Target Framework Terms",depends:["targetGradeLevelIds"],options:Ps("targetSubjectIds",r),currentValue:dt(e,"targetSubjectIds","multiselect")}),n.push({code:"creator",label:"Author",inputType:"text",editable:!0,tab:"licensing",section:"Fourth Section",currentValue:dt(e,"creator","text")},{code:"attributions",label:"Attributions",inputType:"text",editable:!0,tab:"licensing",section:"Fourth Section",currentValue:dt(e,"attributions","text")},{code:"copyright",label:"Copyright",inputType:"text",required:!0,editable:!0,tab:"licensing",section:"Fourth Section",currentValue:dt(e,"copyright","text")},{code:"copyrightYear",label:"Copyright Year",inputType:"text",required:!0,editable:!0,tab:"licensing",section:"Fourth Section",currentValue:dt(e,"copyrightYear","text")},{code:"license",label:"License",inputType:"select",required:!0,editable:!0,tab:"licensing",section:"Fourth Section",currentValue:dt(e,"license","select")})),n}const DE=["allowECM","levels","setPeriod","instances"];function Eh(e){const t={};return e.forEach((r,n)=>{t[`L${n+1}`]={label:r}}),t}function TE(e,t={}){const r={...e};for(const i of DE)delete r[i];const n=e.levels;Array.isArray(n)&&n.length&&(r.outcomeDeclaration={levels:Eh(n)});const s=e.instances;return s!=null&&s!==""&&(r.instances={label:s}),t.isReview&&(r.name===void 0||r.name===null||r.name==="")&&t.nodeTitle&&(r.name=t.nodeTitle),r}function NE(e,t){return e==="allowECM"||e==="setPeriod"?null:e==="levels"?{outcomeDeclaration:{levels:Array.isArray(t)?Eh(t):{}}}:e==="instances"?{instances:t!=null&&t!==""?{label:t}:""}:{[e]:t}}function kE(e,t){const{watch:r,setValue:n}=e,s=h.useRef(!1);h.useEffect(()=>{const i=r((o,{name:a})=>{var c;if(!(!a||s.current)){s.current=!0;try{const d=new Set([a]);let u=!0;for(;u;){u=!1;for(const f of t)d.has(f.code)||(c=f.depends)!=null&&c.some(g=>d.has(g))&&(n(f.code,f.inputType==="multiselect"||f.inputType==="chips"?[]:"",{shouldDirty:!0}),d.add(f.code),u=!0)}}finally{s.current=!1}}});return()=>i.unsubscribe()},[r,n,t])}const Ln={section:"_section_ylgu8_1",header:"_header_ylgu8_11",title:"_title_ylgu8_17",description:"_description_ylgu8_24",divider:"_divider_ylgu8_30",fields:"_fields_ylgu8_36"},xE=({title:e,description:t,children:r})=>l.jsxs("div",{className:Ln.section,children:[l.jsxs("div",{className:Ln.header,children:[l.jsx("h3",{className:Ln.title,children:e}),t&&l.jsx("p",{className:Ln.description,children:t})]}),l.jsx("hr",{className:Ln.divider}),l.jsx("div",{className:Ln.fields,children:r})]}),L={field:"_field_1s288_1",fullWidth:"_fullWidth_1s288_7",label:"_label_1s288_11",required:"_required_1s288_19",input:"_input_1s288_24",textarea:"_textarea_1s288_45",inputError:"_inputError_1s288_50",error:"_error_1s288_54",selectBtn:"_selectBtn_1s288_59",selectOpen:"_selectOpen_1s288_83",placeholder:"_placeholder_1s288_87",selectedVal:"_selectedVal_1s288_91",chevronUp:"_chevronUp_1s288_95",dropdown:"_dropdown_1s288_100",option:"_option_1s288_116",optionSelected:"_optionSelected_1s288_134",noOpts:"_noOpts_1s288_139",chipGroup:"_chipGroup_1s288_146",chipInput:"_chipInput_1s288_158",addChipBtn:"_addChipBtn_1s288_167",radioGroup:"_radioGroup_1s288_184",radioLabel:"_radioLabel_1s288_191",iconWrap:"_iconWrap_1s288_199",iconPreview:"_iconPreview_1s288_214",iconPlaceholder:"_iconPlaceholder_1s288_220",removeIconBtn:"_removeIconBtn_1s288_233",tagChip:"_tagChip_1s288_252",tagChipRemove:"_tagChipRemove_1s288_264",nestedSelectRow:"_nestedSelectRow_1s288_278",dialcodeRow:"_dialcodeRow_1s288_287",validateBtn:"_validateBtn_1s288_293",dialcodeValid:"_dialcodeValid_1s288_315",dialcodeSpinner:"_dialcodeSpinner_1s288_325"},Oh=({name:e,label:t,required:r,disabled:n,multiline:s,maxLength:i,placeholder:o})=>{const{register:a,formState:{errors:c}}=Rt(),d=c[e],u={required:r?`${t} is required`:!1,maxLength:i?{value:i,message:`Max ${i} characters`}:void 0};return l.jsxs("div",{className:[L.field,s?L.fullWidth:""].join(" "),children:[l.jsxs("label",{className:L.label,htmlFor:e,children:[t,r&&l.jsx("span",{className:L.required,children:"*"})]}),s?l.jsx("textarea",{id:e,className:[L.input,L.textarea,d?L.inputError:""].join(" "),disabled:n,placeholder:o,rows:3,...a(e,u)}):l.jsx("input",{id:e,type:"text",className:[L.input,d?L.inputError:""].join(" "),disabled:n,placeholder:o,...a(e,u)}),d&&l.jsx("span",{className:L.error,children:String(d.message)})]})},AE=({name:e,label:t,options:r,required:n,disabled:s})=>{var p;const[i,o]=h.useState(!1),a=h.useRef(null),{register:c,watch:d,setValue:u,formState:{errors:f}}=Rt(),g=d(e),y=((p=r.find(v=>v.value===g))==null?void 0:p.label)??"Select…",_=f[e];return h.useEffect(()=>{if(!i)return;const v=m=>{var b;(b=a.current)!=null&&b.contains(m.target)||o(!1)};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[i]),l.jsxs("div",{className:L.field,ref:a,style:{position:"relative"},children:[l.jsxs("label",{className:L.label,children:[t,n&&l.jsx("span",{className:L.required,children:"*"})]}),l.jsx("input",{type:"hidden",...c(e,{required:n?`${t} is required`:!1})}),l.jsxs("button",{type:"button",disabled:s,className:[L.selectBtn,_?L.inputError:"",i?L.selectOpen:""].join(" "),onClick:()=>o(v=>!v),children:[l.jsx("span",{className:g?L.selectedVal:L.placeholder,children:y}),l.jsx(hs,{size:14,className:i?L.chevronUp:""})]}),i&&l.jsxs("div",{className:L.dropdown,children:[r.map(v=>l.jsxs("button",{type:"button",className:[L.option,g===v.value?L.optionSelected:""].join(" "),onClick:()=>{u(e,v.value,{shouldDirty:!0,shouldValidate:!0}),o(!1)},children:[l.jsx("span",{children:v.label}),g===v.value&&l.jsx(vn,{size:13})]},v.value)),!r.length&&l.jsx("span",{className:L.noOpts,children:"No options"})]}),_&&l.jsx("span",{className:L.error,children:String(_.message)})]})},PE=({name:e,label:t,options:r,required:n,disabled:s})=>{const[i,o]=h.useState(!1),a=h.useRef(null),{register:c,watch:d,setValue:u,formState:{errors:f}}=Rt(),g=d(e)??[],y=f[e],_=g.length?`${g.length} selected`:"Select…";h.useEffect(()=>{if(!i)return;const v=m=>{var b;(b=a.current)!=null&&b.contains(m.target)||o(!1)};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[i]);const p=v=>{const m=g.includes(v)?g.filter(b=>b!==v):[...g,v];u(e,m,{shouldDirty:!0,shouldValidate:!0})};return l.jsxs("div",{className:L.field,ref:a,style:{position:"relative"},children:[l.jsxs("label",{className:L.label,children:[t,n&&l.jsx("span",{className:L.required,children:"*"})]}),l.jsx("input",{type:"hidden",...c(e,{required:n?`${t} is required`:!1})}),l.jsxs("button",{type:"button",disabled:s,className:[L.selectBtn,y?L.inputError:"",i?L.selectOpen:""].join(" "),onClick:()=>o(v=>!v),children:[l.jsx("span",{className:g.length?L.selectedVal:L.placeholder,children:_}),l.jsx(hs,{size:14,className:i?L.chevronUp:""})]}),i&&l.jsxs("div",{className:L.dropdown,children:[r.map(v=>l.jsxs("button",{type:"button",className:[L.option,g.includes(v.value)?L.optionSelected:""].join(" "),onClick:()=>p(v.value),children:[l.jsx(vn,{size:13,style:{opacity:g.includes(v.value)?1:0}}),l.jsx("span",{children:v.label})]},v.value)),!r.length&&l.jsx("span",{className:L.noOpts,children:"No options"})]}),y&&l.jsx("span",{className:L.error,children:String(y.message)})]})},ME=({name:e,label:t,required:r,disabled:n,placeholder:s="Add…"})=>{const[i,o]=h.useState(""),[a,c]=h.useState(!1),d=h.useRef(null),{watch:u,setValue:f,formState:{errors:g}}=Rt(),y=u(e)??[],_=g[e],p=()=>{const m=i.trim();m&&!y.includes(m)&&f(e,[...y,m],{shouldDirty:!0}),o(""),c(!1)},v=m=>f(e,y.filter(b=>b!==m),{shouldDirty:!0});return l.jsxs("div",{className:[L.field,L.fullWidth].join(" "),children:[l.jsxs("label",{className:L.label,children:[t,r&&l.jsx("span",{className:L.required,children:"*"})]}),l.jsxs("div",{className:L.chipGroup,children:[y.map(m=>l.jsxs("span",{className:"sbx-chip filled",children:[m,!n&&l.jsx("button",{type:"button",className:"sbx-chip-remove",onClick:()=>v(m),"aria-label":`Remove ${m}`,children:"×"})]},m)),!n&&(a?l.jsx("input",{ref:d,autoFocus:!0,className:L.chipInput,value:i,onChange:m=>o(m.target.value),onKeyDown:m=>{m.key==="Enter"&&(m.preventDefault(),p()),m.key==="Escape"&&(o(""),c(!1))},onBlur:p,placeholder:s}):l.jsxs("button",{type:"button",className:L.addChipBtn,onClick:()=>{c(!0),setTimeout(()=>{var m;return(m=d.current)==null?void 0:m.focus()},50)},children:[l.jsx(ps,{size:12})," Add"]}))]}),_&&l.jsx("span",{className:L.error,children:String(_.message)})]})},LE=({name:e,label:t,options:r,required:n,disabled:s})=>{const{register:i,formState:{errors:o}}=Rt(),a=o[e];return l.jsxs("div",{className:L.field,children:[l.jsxs("label",{className:L.label,children:[t,n&&l.jsx("span",{className:L.required,children:"*"})]}),l.jsx("div",{className:L.radioGroup,children:r.map(c=>l.jsxs("label",{className:L.radioLabel,children:[l.jsx("input",{type:"radio",value:c.value,disabled:s,...i(e,{required:n?`${t} is required`:!1})}),c.label]},c.value))}),a&&l.jsx("span",{className:L.error,children:String(a.message)})]})};async function FE(e,t,r,n){var o,a;const i=(a=(o=(await Ae.post("/action/asset/v1/create",{request:{asset:{primaryCategory:"asset",language:["English"],code:crypto.randomUUID(),name:e,mediaType:"image",mimeType:t,createdBy:r,creator:null,channel:n,keywords:""}}})).data)==null?void 0:o.result)==null?void 0:a.node_id;if(!i)throw new Error("Asset creation failed: no node_id returned");return i}async function $E(e,t){var s,i;const n=(i=(s=(await Ae.post(`/action/content/v3/upload/url/${e}`,{request:{content:{fileName:t}}})).data)==null?void 0:s.result)==null?void 0:i.pre_signed_url;if(!n)throw new Error("Pre-signed URL fetch failed");return n}async function jE(e,t,r={}){const n=await fetch(e,{method:"PUT",body:t,headers:{"x-ms-blob-type":"BlockBlob","Content-Type":"application/octet-stream",...r}});if(!n.ok)throw new Error(`Blob upload failed: ${n.status} ${n.statusText}`)}async function BE(e,t,r){var o,a;const n=new FormData;n.append("fileUrl",t),n.append("mimeType",r);const i=(a=(o=(await Ae.post(`/action/asset/v1/upload/${e}`,n,{params:{enctype:"multipart/form-data",processData:!1,contentType:!1,cache:!1}})).data)==null?void 0:o.result)==null?void 0:a.content_url;if(!i)throw new Error("Asset finalize failed: no content_url returned");return i}const pe={overlay:"_overlay_ga6eh_1",modal:"_modal_ga6eh_12",header:"_header_ga6eh_24",title:"_title_ga6eh_33",closeBtn:"_closeBtn_ga6eh_39",tabs:"_tabs_ga6eh_57",tab:"_tab_ga6eh_57",activeTab:"_activeTab_ga6eh_83",body:"_body_ga6eh_88",searchWrap:"_searchWrap_ga6eh_99",searchIcon:"_searchIcon_ga6eh_104",searchInput:"_searchInput_ga6eh_113",grid:"_grid_ga6eh_132",imgCell:"_imgCell_ga6eh_148",imgCellSelected:"_imgCellSelected_ga6eh_166",thumb:"_thumb_ga6eh_171",noThumb:"_noThumb_ga6eh_177",checkBadge:"_checkBadge_ga6eh_183",loadMoreBtn:"_loadMoreBtn_ga6eh_198",loadingRow:"_loadingRow_ga6eh_220",empty:"_empty_ga6eh_230",spinner:"_spinner_ga6eh_237",uploadArea:"_uploadArea_ga6eh_247",dropZone:"_dropZone_ga6eh_256",uploadIcon:"_uploadIcon_ga6eh_277",dropText:"_dropText_ga6eh_281",dropSubtext:"_dropSubtext_ga6eh_288",uploadPreview:"_uploadPreview_ga6eh_294",hiddenInput:"_hiddenInput_ga6eh_301",fileName:"_fileName_ga6eh_305",errorText:"_errorText_ga6eh_311",footer:"_footer_ga6eh_318",cancelBtn:"_cancelBtn_ga6eh_328",confirmBtn:"_confirmBtn_ga6eh_345"},Ih=18,Dh=({nodeId:e,currentValue:t,onSelect:r,onClose:n})=>{const[s,i]=h.useState("my"),[o,a]=h.useState(""),[c,d]=h.useState([]),[u,f]=h.useState(0),[g,y]=h.useState(!1),[_,p]=h.useState(null),[v,m]=h.useState(0),[b,S]=h.useState(null),[w,E]=h.useState(""),[T,x]=h.useState(!1),[P,F]=h.useState(""),N=h.useRef(null),M=ae(B=>{var R,K;return((K=(R=B.editorConfig)==null?void 0:R.context)==null?void 0:K.channel)??""}),j=ae(B=>{var R,K;return((K=(R=B.editorConfig)==null?void 0:R.context)==null?void 0:K.uid)??""}),A=ae(B=>{var R,K,de;return((de=(K=(R=B.editorConfig)==null?void 0:R.context)==null?void 0:K.cloudStorage)==null?void 0:de.presigned_headers)??{}}),$=ae(B=>{var R,K,de;return((de=(K=(R=B.editorConfig)==null?void 0:R.config)==null?void 0:K.assetConfig)==null?void 0:de.size)??1*1024*1024}),U=ae(B=>{var R,K,de;return((de=(K=(R=B.editorConfig)==null?void 0:R.config)==null?void 0:K.assetConfig)==null?void 0:de.accepted)??"image/png,image/jpeg"}),Z=h.useCallback(async(B,R,K=!1)=>{var de;y(!0);try{const Oe={status:["Live"],mediaType:["image"],mimeType:["image/png","image/jpeg","image/jpg","image/gif","image/svg+xml"]};s==="my"&&j&&(Oe.createdBy=j),M&&(Oe.channel=M);const ve=((de=(await Ae.post("/action/composite/v3/search",{request:{filters:Oe,query:B,limit:Ih,offset:R,sort_by:{createdOn:"desc"},fields:["identifier","name","appIcon","artifactUrl","downloadUrl"]}},{headers:{"X-Source":"web"}})).data)==null?void 0:de.result)??{},ue=ve.content??[];f(ve.count??0),d(ge=>K?[...ge,...ue]:ue)}catch{}finally{y(!1)}},[s,j,M]);h.useEffect(()=>{s!=="upload"&&(d([]),m(0),Z(o,0))},[s]);const se=h.useRef(),be=B=>{a(B),clearTimeout(se.current),se.current=setTimeout(()=>{d([]),m(0),Z(B,0)},400)},Ee=()=>{const B=v+Ih;m(B),Z(o,B,!0)},ce=()=>{const B=(_==null?void 0:_.artifactUrl)??(_==null?void 0:_.appIcon)??(_==null?void 0:_.downloadUrl)??"";B&&r(B)};h.useEffect(()=>()=>{w&&URL.revokeObjectURL(w)},[w]);const Q=B=>{var de;const R=(de=B.target.files)==null?void 0:de[0];if(B.target.value="",!R)return;const K=U.split(",").map(Oe=>Oe.trim());if(!K.includes(R.type)){const Oe=K.map(Be=>Be.replace("image/","").toUpperCase()).join(", ");F(`Only ${Oe} files are accepted.`);return}if(R.size>$){const Oe=($/1048576).toFixed(0);F(`Image must be under ${Oe} MB.`);return}w&&URL.revokeObjectURL(w),S(R),E(URL.createObjectURL(R)),F("")},J=async()=>{if(b){x(!0),F("");try{const B=await FE(b.name.split(".").slice(0,-1).join(".")||b.name,b.type,j,M),R=await $E(B,b.name);await jE(R,b,A);const K=R.split("?")[0],de=await BE(B,K,b.type);r(de)}catch(B){F(B instanceof Error?B.message:"Upload failed.")}finally{x(!1)}}},ie=c.length<u;return l.jsx("div",{className:pe.overlay,role:"dialog","aria-modal":"true","aria-label":"Select App Icon",children:l.jsxs("div",{className:pe.modal,children:[l.jsxs("div",{className:pe.header,children:[l.jsx("span",{className:pe.title,children:"Select App Icon"}),l.jsx("button",{className:pe.closeBtn,onClick:n,"aria-label":"Close",children:l.jsx(zr,{size:18})})]}),l.jsxs("div",{className:pe.tabs,role:"tablist",children:[l.jsx("button",{role:"tab","aria-selected":s==="my",className:`${pe.tab} ${s==="my"?pe.activeTab:""}`,onClick:()=>i("my"),children:"My Images"}),l.jsx("button",{role:"tab","aria-selected":s==="all",className:`${pe.tab} ${s==="all"?pe.activeTab:""}`,onClick:()=>i("all"),children:"All Images"}),l.jsxs("button",{role:"tab","aria-selected":s==="upload",className:`${pe.tab} ${s==="upload"?pe.activeTab:""}`,onClick:()=>i("upload"),children:[l.jsx(Gc,{size:13,style:{marginRight:4}}),"Upload"]})]}),l.jsx("div",{className:pe.body,children:s!=="upload"?l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:pe.searchWrap,children:[l.jsx(Go,{size:14,className:pe.searchIcon}),l.jsx("input",{type:"search",className:pe.searchInput,placeholder:"Search images…",value:o,onChange:B=>be(B.target.value)})]}),g&&c.length===0?l.jsxs("div",{className:pe.loadingRow,children:[l.jsx(yi,{size:20,className:pe.spinner}),l.jsx("span",{children:"Loading…"})]}):c.length===0?l.jsx("div",{className:pe.empty,children:"No images found"}):l.jsx("div",{className:pe.grid,children:c.map(B=>{const R=B.appIcon??B.artifactUrl??B.downloadUrl??"",K=(_==null?void 0:_.identifier)===B.identifier;return l.jsxs("button",{type:"button",className:`${pe.imgCell} ${K?pe.imgCellSelected:""}`,onClick:()=>p(B),title:B.name,children:[R?l.jsx("img",{src:R,alt:B.name,className:pe.thumb}):l.jsx("div",{className:pe.noThumb,children:"IMG"}),K&&l.jsx("div",{className:pe.checkBadge,children:l.jsx(vn,{size:12})})]},B.identifier)})}),ie&&!g&&l.jsx("button",{className:pe.loadMoreBtn,onClick:Ee,children:"Load More"}),g&&c.length>0&&l.jsx("div",{className:pe.loadingRow,children:l.jsx(yi,{size:16,className:pe.spinner})})]}):l.jsxs("div",{className:pe.uploadArea,children:[l.jsx("div",{className:pe.dropZone,onClick:()=>{var B;return(B=N.current)==null?void 0:B.click()},onDragOver:B=>B.preventDefault(),onDrop:B=>{B.preventDefault();const R=B.dataTransfer.files[0];R&&Q({target:{files:[R],value:""}})},children:w?l.jsx("img",{src:w,alt:"Preview",className:pe.uploadPreview}):l.jsxs(l.Fragment,{children:[l.jsx(Gc,{size:32,className:pe.uploadIcon}),l.jsx("p",{className:pe.dropText,children:"Drag & drop or click to browse"}),l.jsxs("p",{className:pe.dropSubtext,children:[U.split(",").map(B=>B.replace("image/","").toUpperCase()).join(", ")," · max ",($/(1024*1024)).toFixed(0)," MB"]})]})}),l.jsx("input",{ref:N,type:"file",accept:U,className:pe.hiddenInput,onChange:Q}),b&&l.jsx("p",{className:pe.fileName,children:b.name}),P&&l.jsx("p",{className:pe.errorText,children:P})]})}),l.jsxs("div",{className:pe.footer,children:[l.jsx("button",{className:pe.cancelBtn,onClick:n,children:"Cancel"}),s==="upload"?l.jsx("button",{className:pe.confirmBtn,disabled:!b||T,onClick:J,children:T?l.jsxs(l.Fragment,{children:[l.jsx(yi,{size:14,className:pe.spinner})," Uploading…"]}):"Upload & Use"}):l.jsx("button",{className:pe.confirmBtn,disabled:!_,onClick:ce,children:"Use Selected"})]})]})})},UE=({name:e,label:t,nodeId:r,required:n,disabled:s})=>{const[i,o]=h.useState(!1),{watch:a,setValue:c,register:d,formState:{errors:u}}=Rt(),f=a(e),g=u[e],y=p=>{c(e,p,{shouldDirty:!0,shouldValidate:!0}),o(!1)},_=()=>{c(e,"",{shouldDirty:!0,shouldValidate:!0})};return l.jsxs("div",{className:L.field,children:[l.jsxs("label",{className:L.label,children:[t,n&&l.jsx("span",{className:L.required,children:"*"})]}),l.jsx("input",{type:"hidden",...d(e,{required:n?`${t} is required`:!1})}),l.jsx("div",{className:L.iconWrap,role:"button",tabIndex:s?-1:0,"aria-label":"Select app icon",onClick:()=>!s&&o(!0),onKeyDown:p=>{(p.key==="Enter"||p.key===" ")&&!s&&o(!0)},children:f?l.jsx("img",{src:f,alt:"App icon",className:L.iconPreview}):l.jsxs("div",{className:L.iconPlaceholder,children:[l.jsx(Qc,{size:20}),l.jsx("span",{children:"Select icon"})]})}),f&&!s&&l.jsxs("button",{type:"button",className:L.removeIconBtn,onClick:_,"aria-label":"Remove app icon",children:[l.jsx(Yo,{size:13}),l.jsx("span",{children:"Remove"})]}),g&&l.jsx("span",{className:L.error,children:String(g.message)}),i&&l.jsx(Dh,{nodeId:r,currentValue:f,onSelect:y,onClose:()=>o(!1)})]})},zE=({name:e,label:t,required:r,disabled:n})=>{const{control:s}=Rt(),{field:i,fieldState:{error:o}}=Zi({name:e,control:s,rules:{required:r?`${t} is required`:!1}});return l.jsxs("div",{className:L.field,children:[l.jsxs("label",{className:L.label,htmlFor:e,children:[t,r&&l.jsx("span",{className:L.required,children:"*"})]}),l.jsx("input",{id:e,type:"datetime-local",className:[L.input,o?L.inputError:""].join(" "),disabled:n,value:i.value??"",onChange:i.onChange,onBlur:i.onBlur,ref:i.ref}),o&&l.jsx("span",{className:L.error,children:String(o.message)})]})},VE=({name:e,label:t,required:r,disabled:n})=>{const{control:s}=Rt(),{field:i,fieldState:{error:o}}=Zi({name:e,control:s,rules:{required:r?`${t} is required`:!1},defaultValue:[]}),[a,c]=h.useState(""),d=h.useRef(null),u=i.value??[],f=p=>{const v=p.trim();!v||u.includes(v)||i.onChange([...u,v])},g=p=>{i.onChange(u.filter(v=>v!==p))},y=p=>{p.key==="Enter"||p.key===","?(p.preventDefault(),f(a),c("")):p.key==="Backspace"&&a===""&&u.length>0&&g(u[u.length-1])},_=()=>{a.trim()&&(f(a),c("")),i.onBlur()};return l.jsxs("div",{className:[L.field,L.fullWidth].join(" "),children:[l.jsxs("label",{className:L.label,children:[t,r&&l.jsx("span",{className:L.required,children:"*"})]}),l.jsxs("div",{className:[L.chipGroup,o?L.inputError:""].join(" "),onClick:()=>{var p;return!n&&((p=d.current)==null?void 0:p.focus())},style:{cursor:n?"not-allowed":"text"},children:[u.map(p=>l.jsxs("span",{className:L.tagChip,children:[p,!n&&l.jsx("button",{type:"button",className:L.tagChipRemove,onClick:v=>{v.stopPropagation(),g(p)},"aria-label":`Remove ${p}`,children:l.jsx(zr,{size:11})})]},p)),!n&&l.jsx("input",{ref:d,className:L.chipInput,value:a,onChange:p=>c(p.target.value),onKeyDown:y,onBlur:_,placeholder:u.length===0?"Type and press Enter or comma…":"",style:{flexGrow:1,minWidth:120}})]}),o&&l.jsx("span",{className:L.error,children:String(o.message)})]})},qE=({name:e,label:t,levels:r,required:n,disabled:s})=>{const{control:i}=Rt(),{field:o,fieldState:{error:a}}=Zi({name:e,control:i,rules:{required:n?`${t} is required`:!1},defaultValue:{}}),c=o.value??{},d=(u,f,g)=>{const y={};for(let _=0;_<f;_++)y[r[_].code]=c[r[_].code]??"";y[u]=g;for(let _=f+1;_<r.length;_++)y[r[_].code]="";o.onChange(y)};return l.jsxs("div",{className:[L.field,L.fullWidth].join(" "),children:[l.jsxs("label",{className:L.label,children:[t,n&&l.jsx("span",{className:L.required,children:"*"})]}),l.jsx("div",{className:L.nestedSelectRow,children:r.map((u,f)=>{const g=f>0&&!c[r[f-1].code];return l.jsxs("div",{className:L.field,style:{flex:1},children:[l.jsx("label",{className:L.label,htmlFor:`${e}_${u.code}`,children:u.label}),l.jsxs("select",{id:`${e}_${u.code}`,className:[L.input,a?L.inputError:""].join(" "),disabled:s||g,value:c[u.code]??"",onChange:y=>d(u.code,f,y.target.value),onBlur:o.onBlur,children:[l.jsx("option",{value:"",children:"Select…"}),u.options.map(y=>l.jsx("option",{value:y.value,children:y.label},y.value))]})]},u.code)})}),a&&l.jsx("span",{className:L.error,children:String(a.message)})]})},Th=[{label:"CC BY 4.0",value:"CC BY 4.0"},{label:"CC BY-SA 4.0",value:"CC BY-SA 4.0"},{label:"CC BY-NC 4.0",value:"CC BY-NC 4.0"},{label:"CC BY-NC-SA 4.0",value:"CC BY-NC-SA 4.0"},{label:"CC BY-ND 4.0",value:"CC BY-ND 4.0"},{label:"CC0 1.0 (Public Domain)",value:"CC0 1.0"}],HE=({name:e,label:t,required:r,disabled:n})=>{const[s,i]=h.useState(!1),o=h.useRef(null),{register:a,watch:c,setValue:d,formState:{errors:u}}=Rt(),f=c(e),g=Th.find(p=>p.value===f),y=(g==null?void 0:g.label)??"Select license…",_=u[e];return h.useEffect(()=>{if(!s)return;const p=v=>{var m;(m=o.current)!=null&&m.contains(v.target)||i(!1)};return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[s]),l.jsxs("div",{className:L.field,ref:o,style:{position:"relative"},children:[l.jsxs("label",{className:L.label,children:[t,r&&l.jsx("span",{className:L.required,children:"*"})]}),l.jsx("input",{type:"hidden",...a(e,{required:r?`${t} is required`:!1})}),l.jsxs("button",{type:"button",disabled:n,className:[L.selectBtn,_?L.inputError:"",s?L.selectOpen:""].join(" "),onClick:()=>i(p=>!p),"aria-haspopup":"listbox","aria-expanded":s,children:[l.jsx("span",{className:f?L.selectedVal:L.placeholder,children:y}),l.jsx(hs,{size:14,className:s?L.chevronUp:""})]}),s&&l.jsx("div",{className:L.dropdown,role:"listbox",children:Th.map(p=>l.jsxs("button",{type:"button",role:"option","aria-selected":f===p.value,className:[L.option,f===p.value?L.optionSelected:""].join(" "),onClick:()=>{d(e,p.value,{shouldDirty:!0,shouldValidate:!0}),i(!1)},children:[l.jsx("span",{children:p.label}),f===p.value&&l.jsx(vn,{size:13})]},p.value))}),_&&l.jsx("span",{className:L.error,children:String(_.message)})]})},WE=({name:e,label:t,required:r,disabled:n})=>{const{control:s}=Rt(),{field:i,fieldState:{error:o}}=Zi({name:e,control:s,rules:{required:r?`${t} is required`:!1},defaultValue:""}),[a,c]=h.useState("idle"),[d,u]=h.useState(""),f=async()=>{const y=(i.value??"").trim();if(!y){c("invalid"),u("Enter a dial code to validate.");return}c("loading"),u("");try{const _=await o_(y),p=_==null?void 0:_.result,v=p==null?void 0:p.dialcodes;Array.isArray(v)&&v.length>0?(c("valid"),u("Dial code is valid.")):(c("invalid"),u("Dial code not found."))}catch{c("invalid"),u("Validation failed. Please try again.")}},g=()=>a==="loading"?l.jsx(yi,{size:16,className:L.dialcodeSpinner}):a==="valid"?l.jsx(Vc,{size:16,color:"var(--sbx-success, #2e7d32)"}):a==="invalid"?l.jsx(qo,{size:16,color:"var(--sbx-error)"}):null;return l.jsxs("div",{className:L.field,children:[l.jsxs("label",{className:L.label,htmlFor:e,children:[t,r&&l.jsx("span",{className:L.required,children:"*"})]}),l.jsxs("div",{className:L.dialcodeRow,children:[l.jsx("input",{id:e,type:"text",className:[L.input,o?L.inputError:""].join(" "),disabled:n,value:i.value??"",onChange:y=>{i.onChange(y),c("idle"),u("")},onBlur:i.onBlur,ref:i.ref,placeholder:"e.g. A1B2C3",style:{flex:1}}),l.jsx("button",{type:"button",className:L.validateBtn,onClick:f,disabled:n||a==="loading","aria-label":"Validate dial code",children:a==="loading"?"Validating…":"Validate"}),g()]}),o&&l.jsx("span",{className:L.error,children:String(o.message)}),!o&&d&&l.jsx("span",{className:a==="valid"?L.dialcodeValid:L.error,children:d})]})},yl={form:"_form_szqex_1",ungrouped:"_ungrouped_szqex_7",noFields:"_noFields_szqex_18"},QE=({nodeMetadata:e,activeTab:t,isRoot:r,isFolder:n,editorMode:s,onFormValueChange:i,onFormStatusChange:o})=>{var ge,$e,qe,ke,ee,Qe,tt;const a=ae(H=>H.editorConfig),c=ae(H=>H.rootFormConfig),d=ae(H=>H.unitFormConfig),u=ae(H=>H.categoryMeta),f=ae(H=>H.contentFramework),g=ae(H=>H.contentTargetFWIds),{organisationFramework:y,targetFrameworks:_,isLoading:p}=_h(f??((ge=a==null?void 0:a.context)==null?void 0:ge.framework),g??(($e=a==null?void 0:a.context)==null?void 0:$e.targetFWIds)),{frameworks:v,collectionAdditionalCategories:m,contentAdditionalCategories:b,defaultLicense:S,name:w}=aE((qe=a==null?void 0:a.context)==null?void 0:qe.channel),E=iE(v,(ke=u==null?void 0:u.frameworkMetadata)==null?void 0:ke.orgFWType,(ee=a==null?void 0:a.context)==null?void 0:ee.channel),T={organisationFramework:y,targetFrameworks:_,orgFrameworks:E,channelAdditionalCategories:m},x=xe(H=>H.selectedNodeId),P=xe(H=>H.treeData),F=xe(H=>H.treeCache),N=x?F[x]??{}:{},M={...e,...N},j=h.useMemo(()=>{var re;if(!x)return 0;const H=[...P];for(;H.length;){const oe=H.shift();if(oe.id===x)return((re=oe.children)==null?void 0:re.length)??0;oe.children&&H.push(...oe.children)}return 0},[P,x]),A=(a==null?void 0:a.config)??{},$=(a==null?void 0:a.context)??{},U={editorMode:s,editableFields:A.editableFields,objectType:A.objectType,setDefaultCopyRight:A.setDefaultCopyRight===!0,defaultLicense:$.defaultLicense??S,contextAdditionalCategories:$.additionalCategories,userFullName:(Qe=$.user)==null?void 0:Qe.fullName,channelName:w,collectionAdditionalCategories:m,contentAdditionalCategories:b,childCount:j},Z=r?c:d,se=Z||(((tt=a==null?void 0:a.config.hierarchy)==null?void 0:tt.formConfig)??[]),be=fE(se,M,T,r,U),Ee=be.filter(H=>H.tab===t&&H.inputType!=="appIcon"&&H.visible!==!1),ce=nE({mode:"onChange",defaultValues:Object.fromEntries(be.map(H=>{const re=["multiselect","chips","keywords","tagsinput"],oe=["nestedselect"];return re.includes(H.inputType)?[H.code,H.currentValue??H.defaultValue??[]]:oe.includes(H.inputType)?[H.code,H.currentValue??H.defaultValue??{}]:[H.code,H.currentValue??H.defaultValue??""]}))});kE(ce,be);const{updateNode:Q}=xe(),J=h.useRef(be);J.current=be;const ie=h.useRef(x);ie.current=x;const B=h.useRef(i);B.current=i;const R=h.useRef(o);R.current=o;const K=h.useRef(typeof M.shuffle=="boolean"?M.shuffle:void 0),de=h.useRef(M.name??"");de.current=M.name??"";const Oe=h.useRef(s);Oe.current=s;const Be=["review","read","sourcingreview","orgreview"];h.useEffect(()=>{const H=ie.current;if(H){const re=Object.fromEntries(J.current.filter(oe=>oe.currentValue!==void 0&&oe.currentValue!==null).map(oe=>[oe.code,oe.currentValue]));Object.keys(re).length>0&&Q(H,re)}ce.trigger().then(()=>{const re=ce.formState.errors,oe=J.current,Re=Array.from(new Set(Object.keys(re).map(gr=>{var yr;return(yr=oe.find(dn=>dn.code===gr))==null?void 0:yr.tab}).filter(Boolean)));R.current(Object.keys(re).length===0,Re)})},[]),h.useEffect(()=>{const H=ce.watch((re,{name:oe})=>{const Re=ie.current;if(!Re)return;const gr=J.current,yr=new Set(gr.map(C=>C.code));if(oe&&yr.has(oe)){let C=ce.getValues(oe);oe==="dialcodes"&&(C=Array.isArray(C)?C:C?[C]:[]),oe==="shuffle"&&(C===!0&&K.current===!1&&Ie("Shuffling is enabled for this question set.",{icon:"ℹ️"}),K.current=C);const D=NE(oe,C);D&&(Q(Re,D),B.current(D))}else if(!oe){const C=ce.getValues(),D=Object.fromEntries(Object.entries(C).filter(([z])=>yr.has(z))),k=TE(D,{isReview:Be.includes(Oe.current),nodeTitle:de.current});Object.keys(k).length>0&&(Q(Re,k),B.current(k))}const dn=ce.formState.errors,Yn=Array.from(new Set(Object.keys(dn).map(C=>{var D;return(D=gr.find(k=>k.code===C))==null?void 0:D.tab}).filter(Boolean)));R.current(Object.keys(dn).length===0,Yn)});return()=>H.unsubscribe()},[ce]);const ve=Ee.reduce((H,re)=>{const oe=H[H.length-1];return oe&&oe.section===re.section?oe.fields.push(re):H.push({section:re.section,fields:[re]}),H},[]),ue=H=>{const re={key:H.code,name:H.code,label:H.label,required:H.required,disabled:H.editable===!1};switch(H.inputType){case"textarea":return l.jsx(Oh,{...re,multiline:!0,maxLength:H.maxLength});case"select":return l.jsx(AE,{...re,options:H.options??[]});case"multiselect":return l.jsx(PE,{...re,options:H.options??[]});case"chips":return l.jsx(ME,{...re});case"radio":return l.jsx(LE,{...re,options:H.options??[]});case"appIcon":return l.jsx(UE,{...re,nodeId:x??""});case"datepicker":case"datetime":return l.jsx(zE,{...re});case"keywords":case"tagsinput":return l.jsx(VE,{...re});case"nestedselect":return l.jsx(qE,{...re,levels:H.levels??[]});case"license":return l.jsx(HE,{...re});case"dialcode":return l.jsx(WE,{...re});default:return l.jsx(Oh,{...re,maxLength:H.maxLength})}};return l.jsx(V1,{...ce,children:l.jsxs("div",{className:yl.form,children:[ve.map((H,re)=>{const oe=H.section?lE[H.section]:void 0;return oe?l.jsx(xE,{title:oe.title,description:oe.description,children:H.fields.map(ue)},H.section??re):l.jsx("div",{className:yl.ungrouped,children:H.fields.map(ue)},re)}),Ee.length===0&&!p&&l.jsx("p",{className:yl.noFields,children:"No fields configured for this tab."})]})})};function Nh(e,t,r){const n=e.slice();return n.splice(r<0?n.length+r:r,0,n.splice(t,1)[0]),n}function KE(e,t){return e.reduce((r,n,s)=>{const i=t.get(n);return i&&(r[s]=i),r},Array(e.length))}function no(e){return e!==null&&e>=0}function GE(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(e[r]!==t[r])return!1;return!0}function YE(e){return typeof e=="boolean"?{draggable:e,droppable:e}:e}const kh=e=>{let{rects:t,activeIndex:r,overIndex:n,index:s}=e;const i=Nh(t,n,r),o=t[s],a=i[s];return!a||!o?null:{x:a.left-o.left,y:a.top-o.top,scaleX:a.width/o.width,scaleY:a.height/o.height}},so={scaleX:1,scaleY:1},RE=e=>{var t;let{activeIndex:r,activeNodeRect:n,index:s,rects:i,overIndex:o}=e;const a=(t=i[r])!=null?t:n;if(!a)return null;if(s===r){const d=i[o];return d?{x:0,y:r<o?d.top+d.height-(a.top+a.height):d.top-a.top,...so}:null}const c=XE(i,s,r);return s>r&&s<=o?{x:0,y:-a.height-c,...so}:s<r&&s>=o?{x:0,y:a.height+c,...so}:{x:0,y:0,...so}};function XE(e,t,r){const n=e[t],s=e[t-1],i=e[t+1];return n?r<t?s?n.top-(s.top+s.height):i?i.top-(n.top+n.height):0:i?i.top-(n.top+n.height):s?n.top-(s.top+s.height):0:0}const xh="Sortable",Ah=h.createContext({activeIndex:-1,containerId:xh,disableTransforms:!1,items:[],overIndex:-1,useDragOverlay:!1,sortedRects:[],strategy:kh,disabled:{draggable:!1,droppable:!1}});function ZE(e){let{children:t,id:r,items:n,strategy:s=kh,disabled:i=!1}=e;const{active:o,dragOverlay:a,droppableRects:c,over:d,measureDroppableContainers:u}=jc(),f=os(xh,r),g=a.rect!==null,y=h.useMemo(()=>n.map(T=>typeof T=="object"&&"id"in T?T.id:T),[n]),_=o!=null,p=o?y.indexOf(o.id):-1,v=d?y.indexOf(d.id):-1,m=h.useRef(y),b=!GE(y,m.current),S=v!==-1&&p===-1||b,w=YE(i);Wt(()=>{b&&_&&u(y)},[b,y,_,u]),h.useEffect(()=>{m.current=y},[y]);const E=h.useMemo(()=>({activeIndex:p,containerId:f,disabled:w,disableTransforms:S,items:y,overIndex:v,useDragOverlay:g,sortedRects:KE(y,c),strategy:s}),[p,f,w.draggable,w.droppable,S,y,v,c,g,s]);return h.createElement(Ah.Provider,{value:E},t)}const JE=e=>{let{id:t,items:r,activeIndex:n,overIndex:s}=e;return Nh(r,n,s).indexOf(t)},eO=e=>{let{containerId:t,isSorting:r,wasDragging:n,index:s,items:i,newIndex:o,previousItems:a,previousContainerId:c,transition:d}=e;return!d||!n||a!==i&&s===o?!1:r?!0:o!==s&&t===c},tO={duration:200,easing:"ease"},Ph="transform",rO=Er.Transition.toString({property:Ph,duration:0,easing:"linear"}),nO={roleDescription:"sortable"};function sO(e){let{disabled:t,index:r,node:n,rect:s}=e;const[i,o]=h.useState(null),a=h.useRef(r);return Wt(()=>{if(!t&&r!==a.current&&n.current){const c=s.current;if(c){const d=yn(n.current,{ignoreTransform:!0}),u={x:c.left-d.left,y:c.top-d.top,scaleX:c.width/d.width,scaleY:c.height/d.height};(u.x||u.y)&&o(u)}}r!==a.current&&(a.current=r)},[t,r,n,s]),h.useEffect(()=>{i&&o(null)},[i]),i}function iO(e){let{animateLayoutChanges:t=eO,attributes:r,disabled:n,data:s,getNewIndex:i=JE,id:o,strategy:a,resizeObserverConfig:c,transition:d=tO}=e;const{items:u,containerId:f,activeIndex:g,disabled:y,disableTransforms:_,sortedRects:p,overIndex:v,useDragOverlay:m,strategy:b}=h.useContext(Ah),S=oO(n,y),w=u.indexOf(o),E=h.useMemo(()=>({sortable:{containerId:f,index:w,items:u},...s}),[f,s,w,u]),T=h.useMemo(()=>u.slice(u.indexOf(o)),[u,o]),{rect:x,node:P,isOver:F,setNodeRef:N}=tv({id:o,data:E,disabled:S.droppable,resizeObserverConfig:{updateMeasurementsFor:T,...c}}),{active:M,activatorEvent:j,activeNodeRect:A,attributes:$,setNodeRef:U,listeners:Z,isDragging:se,over:be,setActivatorNodeRef:Ee,transform:ce}=$c({id:o,data:E,attributes:{...nO,...r},disabled:S.draggable}),Q=Ug(N,U),J=!!M,ie=J&&!_&&no(g)&&no(v),B=!m&&se,R=B&&ie?ce:null,de=ie?R??(a??b)({rects:p,activeNodeRect:A,activeIndex:g,overIndex:v,index:w}):null,Oe=no(g)&&no(v)?i({id:o,items:u,activeIndex:g,overIndex:v}):w,Be=M==null?void 0:M.id,ve=h.useRef({activeId:Be,items:u,newIndex:Oe,containerId:f}),ue=u!==ve.current.items,ge=t({active:M,containerId:f,isDragging:se,isSorting:J,id:o,index:w,items:u,newIndex:ve.current.newIndex,previousItems:ve.current.items,previousContainerId:ve.current.containerId,transition:d,wasDragging:ve.current.activeId!=null}),$e=sO({disabled:!ge,index:w,node:P,rect:x});return h.useEffect(()=>{J&&ve.current.newIndex!==Oe&&(ve.current.newIndex=Oe),f!==ve.current.containerId&&(ve.current.containerId=f),u!==ve.current.items&&(ve.current.items=u)},[J,Oe,f,u]),h.useEffect(()=>{if(Be===ve.current.activeId)return;if(Be&&!ve.current.activeId){ve.current.activeId=Be;return}const ke=setTimeout(()=>{ve.current.activeId=Be},50);return()=>clearTimeout(ke)},[Be]),{active:M,activeIndex:g,attributes:$,data:E,rect:x,index:w,newIndex:Oe,items:u,isOver:F,isSorting:J,isDragging:se,listeners:Z,node:P,overIndex:v,over:be,setNodeRef:Q,setActivatorNodeRef:Ee,setDroppableNodeRef:N,setDraggableNodeRef:U,transform:$e??de,transition:qe()};function qe(){if($e||ue&&ve.current.newIndex===w)return rO;if(!(B&&!ai(j)||!d)&&(J||ge))return Er.Transition.toString({...d,property:Ph})}}function oO(e,t){var r,n;return typeof e=="boolean"?{draggable:e,droppable:!1}:{draggable:(r=e==null?void 0:e.draggable)!=null?r:t.draggable,droppable:(n=e==null?void 0:e.droppable)!=null?n:t.droppable}}function io(e){if(!e)return!1;const t=e.data.current;return!!(t&&"sortable"in t&&typeof t.sortable=="object"&&"containerId"in t.sortable&&"items"in t.sortable&&"index"in t.sortable)}const aO=[Se.Down,Se.Right,Se.Up,Se.Left],lO=(e,t)=>{let{context:{active:r,collisionRect:n,droppableRects:s,droppableContainers:i,over:o,scrollableAncestors:a}}=t;if(aO.includes(e.code)){if(e.preventDefault(),!r||!n)return;const c=[];i.getEnabled().forEach(f=>{if(!f||f!=null&&f.disabled)return;const g=s.get(f.id);if(g)switch(e.code){case Se.Down:n.top<g.top&&c.push(f);break;case Se.Up:n.top>g.top&&c.push(f);break;case Se.Left:n.left>g.left&&c.push(f);break;case Se.Right:n.left<g.left&&c.push(f);break}});const d=ny({collisionRect:n,droppableRects:s,droppableContainers:c});let u=cc(d,"id");if(u===(o==null?void 0:o.id)&&d.length>1&&(u=d[1].id),u!=null){const f=i.get(r.id),g=i.get(u),y=g?s.get(g.id):null,_=g==null?void 0:g.node.current;if(_&&y&&f&&g){const v=ui(_).some((T,x)=>a[x]!==T),m=Mh(f,g),b=cO(f,g),S=v||!m?{x:0,y:0}:{x:b?n.width-y.width:0,y:b?n.height-y.height:0},w={x:y.left,y:y.top};return S.x&&S.y?w:as(w,S)}}}};function Mh(e,t){return!io(e)||!io(t)?!1:e.data.current.sortable.containerId===t.data.current.sortable.containerId}function cO(e,t){return!io(e)||!io(t)||!Mh(e,t)?!1:e.data.current.sortable.index<t.data.current.sortable.index}const Zr={row:"_row_11nth_1",removeBtn:"_removeBtn_11nth_14",grip:"_grip_11nth_17",ctIcon:"_ctIcon_11nth_34",info:"_info_11nth_38",name:"_name_11nth_46",meta:"_meta_11nth_55"},uO={video:Ro,pdf:Ho,h5p:Wo,scorm:Ko,audio:Qo,quiz:Vo,default:mn},dO=({item:e,onRemove:t,isEditable:r})=>{const n=Yi(e),s=uO[n.key]??mn,{attributes:i,listeners:o,setNodeRef:a,transform:c,transition:d,isDragging:u}=iO({id:e.id,disabled:!r}),f={transform:Er.Transform.toString(c),transition:d,opacity:u?.5:1};return l.jsxs("div",{ref:a,style:f,className:Zr.row,role:"listitem",children:[r&&l.jsx("span",{className:Zr.grip,...i,...o,"aria-label":"Drag to reorder",children:l.jsx(Wc,{size:15})}),l.jsx("span",{className:[`sbx-ct-sq--${n.key}`,Zr.ctIcon].join(" "),"aria-hidden":"true",children:l.jsx(s,{size:14})}),l.jsxs("div",{className:Zr.info,children:[l.jsx("span",{className:Zr.name,title:e.name,children:e.name}),l.jsx("span",{className:Zr.meta,children:n.label})]}),l.jsx("span",{className:`sbx-ct-badge--${n.key}`,children:n.label}),r&&l.jsx("button",{type:"button",className:Zr.removeBtn,onClick:()=>t(e.id),"aria-label":`Remove ${e.name}`,children:l.jsx(zr,{size:14})})]})},Jr={container:"_container_lzvke_1",header:"_header_lzvke_7",heading:"_heading_lzvke_13",count:"_count_lzvke_21",list:"_list_lzvke_30",emptyState:"_emptyState_lzvke_36",addRow:"_addRow_lzvke_52"},fO=({editorMode:e})=>{const{selectedNodeId:t,getChildrenOf:r,reorderChildren:n,deleteNode:s}=xe(),i=t?r(t):[],o=e==="edit",a=ic(xo(di,{activationConstraint:{distance:5}}),xo(Fo,{coordinateGetter:lO})),c=h.useCallback(u=>{const{active:f,over:g}=u;if(!g||f.id===g.id||!t)return;const y=xe.getState().getChildrenOf(t),_=y.findIndex(v=>v.id===f.id),p=y.findIndex(v=>v.id===g.id);_<0||p<0||n(t,_,p)},[t,n]),d=h.useCallback(u=>{window.confirm("Remove this content from the unit?")&&s(u)},[s]);return t?l.jsxs("div",{className:Jr.container,children:[l.jsxs("div",{className:Jr.header,children:[l.jsx("span",{className:Jr.heading,children:"Content in this unit"}),l.jsx("span",{className:Jr.count,children:i.length})]}),i.length>0?l.jsx(Lc,{sensors:a,collisionDetection:ry,onDragEnd:c,children:l.jsx(ZE,{items:i.map(u=>u.id),strategy:RE,children:l.jsx("div",{className:Jr.list,role:"list",children:i.map(u=>l.jsx(dO,{item:u,onRemove:d,isEditable:o},u.id))})})}):l.jsxs("div",{className:Jr.emptyState,children:[l.jsx("p",{children:"No content yet"}),l.jsx("span",{children:"Drag from the library or click Add content"})]}),o&&l.jsxs("button",{className:Jr.addRow,type:"button","aria-label":"Add content to unit",children:[l.jsx(ps,{size:14})," Add content"]})]}):null},Lh={dropZone:"_dropZone_ijo5w_1",active:"_active_ijo5w_14"},hO=({isActive:e,label:t="Drop here",nodeId:r,className:n})=>l.jsx("div",{className:`${Lh.dropZone} ${e?Lh.active:""} ${n??""}`,"data-droppable":e?"true":void 0,"data-node-id":r,"aria-label":t,role:"region",children:l.jsx("span",{children:t})});async function pO(e){var o;const t={status:["Live"],...e.filters??{}};e.channel&&(t.channel=e.channel);const n=((o=(await Ae.post("/action/composite/v3/search",{request:{filters:t,query:e.query??"",limit:e.limit??20,offset:e.offset??0,sort_by:e.sortBy??{lastUpdatedOn:"desc"},fields:e.fields??["identifier","name","mimeType","contentType","primaryCategory","appIcon","channel","organisation","pkgVersion"]}},{headers:{"X-Source":"web","X-msgid":Math.random().toString(36).slice(2)}})).data)==null?void 0:o.result)??{},s=new Set(["count","facets"]);return{content:Object.entries(n).filter(([a])=>!s.has(a)).flatMap(([,a])=>Array.isArray(a)?a:[]),count:n.count??0}}async function gO(e){var r,n;return(n=(r=(await Ae.get(`/action/content/v3/read/${e}`)).data)==null?void 0:r.result)==null?void 0:n.content}const Fh="application/vnd.sunbird.question";function $h(e){return{cardinality:"single",type:"integer",defaultValue:e.maxScore??1}}function jh(e,t,r){if(!e)return null;if(e.identifier===t)return{question:e,parent:r};for(const n of e.children??[]){const s=jh(n,t,e);if(s)return s}return null}function yO(e,t){const r=jh(e,t);if(!r)return null;const{question:n,parent:s}=r,i={...e,children:[n],childNodes:[t],shuffle:s==null?void 0:s.shuffle,showSolutions:(s==null?void 0:s.showSolutions)??"No",showFeedback:(s==null?void 0:s.showFeedback)??"No"};return(s==null?void 0:s.shuffle)===!0?i.maxScore=1:n.qType==="SA"?delete i.maxScore:n.maxScore!=null&&(i.maxScore=n.maxScore),i}function vO(e,t){const r=((t==null?void 0:t.enabled)??!0)&&!!e;return ts({queryKey:["quml","questionset",e],enabled:r,queryFn:async()=>{const n=await Xu(e),s=u=>{if(!u)return[];const f=u.mimeType===Fh&&u.identifier?[u.identifier]:[],g=(u.children??[]).flatMap(s);return[...f,...g]},i=s(n),o=new Map;i.length&&(await Xb(i)).forEach(f=>{const g=f.identifier;g&&o.set(g,f)});const a=u=>{if(!u)return u;if(u.mimeType===Fh&&u.identifier){const f=o.get(u.identifier)??u,g=f.outcomeDeclaration;return g!=null&&g.maxScore||(f.outcomeDeclaration={...g??{},maxScore:$h(f)}),f}return Array.isArray(u.children)&&(u.children=u.children.map(f=>a(f))),u},c=a(n),d=c.outcomeDeclaration;return d!=null&&d.maxScore||(c.outcomeDeclaration={...d??{},maxScore:$h(c)}),c}})}const Bh="/assets/quml-player/sunbird-quml-player.js",mO="/assets/quml-player/styles.css",Uh="sunbird-quml-player";function bO(e){const t=e.children??[];return t.length?t.every(n=>n.objectType==="Question")?[e]:t:[]}const ot=class ot{constructor(){Ks(this,"eventHandlers",new WeakMap)}loadScript(){return ot.scriptLoaded||customElements.get(Uh)?(ot.scriptLoaded=!0,Promise.resolve()):(ot.scriptLoading||(ot.scriptLoading=new Promise((t,r)=>{const n=document.createElement("script");n.src=Bh,n.setAttribute("data-quml-player-script","true"),n.onload=()=>{ot.scriptLoaded=!0,ot.scriptLoading=void 0,t()},n.onerror=()=>{ot.scriptLoading=void 0,r(new Error(`Failed to load QuML player script: ${Bh}`))},document.body.appendChild(n)})),ot.scriptLoading)}loadStyles(){if(ot.stylesLoaded||document.querySelector('[data-quml-player-styles="true"]')){ot.stylesLoaded=!0;return}const t=document.createElement("link");t.rel="stylesheet",t.href=mO,t.setAttribute("data-quml-player-styles","true"),document.head.appendChild(t),ot.stylesLoaded=!0}static unloadStyles(){var t;(t=document.querySelector('[data-quml-player-styles="true"]'))==null||t.remove(),ot.stylesLoaded=!1}async createConfig(t,r,n){var i,o,a;return await this.loadScript(),{context:{mode:(n==null?void 0:n.mode)??"play",host:"",pdata:{id:((i=r==null?void 0:r.pdata)==null?void 0:i.id)??"sunbird.portal",ver:((o=r==null?void 0:r.pdata)==null?void 0:o.ver)??"1.0",pid:((a=r==null?void 0:r.pdata)==null?void 0:a.pid)??"sunbird-portal"},contentId:t.identifier??"",sid:(r==null?void 0:r.sid)??"",uid:(r==null?void 0:r.uid)??(r==null?void 0:r.userId)??"",channel:(r==null?void 0:r.channel)??"",did:(r==null?void 0:r.did)??"",tags:(r==null?void 0:r.tags)??[],contextRollup:(n==null?void 0:n.contextRollup)??(r==null?void 0:r.rollup)??{},objectRollup:(n==null?void 0:n.objectRollup)??{},...n!=null&&n.cdata?{cdata:n.cdata}:{}},config:{language:"en"},data:{sections:bO(t),identifier:t.identifier??""},metadata:t}}createElement(t){this.loadStyles();const r=document.createElement(Uh);return r.setAttribute("player-config",JSON.stringify(t)),r.setAttribute("data-player-id",t.metadata.identifier??"quml"),r}attachEventListeners(t,r,n){this.removeEventListeners(t);const s=o=>r==null?void 0:r(o),i=o=>n==null?void 0:n(o.detail);t.addEventListener("playerEvent",s),t.addEventListener("telemetryEvent",i),this.eventHandlers.set(t,{player:s,telemetry:i})}removeEventListeners(t){const r=this.eventHandlers.get(t);r&&(t.removeEventListener("playerEvent",r.player),t.removeEventListener("telemetryEvent",r.telemetry),this.eventHandlers.delete(t))}};Ks(ot,"scriptLoaded",!1),Ks(ot,"scriptLoading"),Ks(ot,"stylesLoaded",!1);let oo=ot;const ao=new oo,ze={contentPlayerRoot:"_contentPlayerRoot_ryh6z_1",stage:"_stage_ryh6z_9",playerHeader:"_playerHeader_ryh6z_19",playerHeaderThumb:"_playerHeaderThumb_ryh6z_33",playerHeaderTitle:"_playerHeaderTitle_ryh6z_43",typeBadge:"_typeBadge_ryh6z_53",typeDot:"_typeDot_ryh6z_92",aspectRatio:"_aspectRatio_ryh6z_99",playerFrame:"_playerFrame_ryh6z_112",coverOverlay:"_coverOverlay_ryh6z_120",coverHidden:"_coverHidden_ryh6z_132",coverThumb:"_coverThumb_ryh6z_137",coverPlayRing:"_coverPlayRing_ryh6z_146",coverPlayIcon:"_coverPlayIcon_ryh6z_159",coverLabel:"_coverLabel_ryh6z_168",coverSkeleton:"_coverSkeleton_ryh6z_174",playerWrapper:"_playerWrapper_ryh6z_200",infoStrip:"_infoStrip_ryh6z_210",infoChip:"_infoChip_ryh6z_226",infoChipLabel:"_infoChipLabel_ryh6z_245",infoChipIcon:"_infoChipIcon_ryh6z_254",playerError:"_playerError_ryh6z_260",playerErrorIcon:"_playerErrorIcon_ryh6z_274",playerErrorMsg:"_playerErrorMsg_ryh6z_279",qumlRoot:"_qumlRoot_ryh6z_286"},_O="application/vnd.sunbird.questionset";function wO(e,t){const r=new Map,n=i=>{for(const o of i)r.set(o.id,o),o.children&&n(o.children)};n(e);let s=r.get(t);for(;s;){if(s.mimeType===_O)return s.identifier;s=s.parent?r.get(s.parent):void 0}return null}const SO=[{key:"video",mimes:["video/mp4","video/webm","video/ogg"],label:"Video",icon:"🎬"},{key:"audio",mimes:["audio/mp3","audio/mpeg","audio/ogg","audio/wav"],label:"Audio",icon:"🎵"},{key:"pdf",mimes:["application/pdf"],label:"PDF",icon:"📄"},{key:"epub",mimes:["application/epub"],label:"ePub",icon:"📖"},{key:"ecml",mimes:["application/vnd.ekstep.ecml-archive"],label:"ECML",icon:"✏️"},{key:"h5p",mimes:["application/vnd.ekstep.h5p-archive"],label:"H5P",icon:"🎮"},{key:"scorm",mimes:["application/vnd.ekstep.content-collection"],label:"SCORM",icon:"📦"}];function CO(e){return SO.find(t=>t.mimes.includes(e))??{key:"other",label:"Content",icon:"📱"}}const EO={"pdf-player":["application/pdf"],"video-player":["video/mp4","video/webm"],"epub-player":["application/epub"]},OO={"pdf-player":"/assets/sunbird-pdf-player.js","video-player":"/assets/sunbird-video-player.js","epub-player":"/assets/sunbird-epub-player.js"},IO={"pdf-player":"sunbird-pdf-player","video-player":"sunbird-video-player","epub-player":"sunbird-epub-player"},DO="/content/preview/preview.html?webview=true&build_number=2.8.0.e552fcd";function vl(e){for(const[t,r]of Object.entries(EO))if(r.includes(e))return t;return"default-player"}function TO(e,t,r){var i;const n=r==null?void 0:r.context,s=t.mimeType??e.mimeType??"";return{context:{mode:"play",partner:[],pdata:{id:((i=n==null?void 0:n.pdata)==null?void 0:i.id)??"sunbird.portal",ver:1,pid:"sunbird-portal"},contentId:e.identifier,sid:(n==null?void 0:n.sid)??"",uid:(n==null?void 0:n.uid)??"",channel:(n==null?void 0:n.channel)??"",did:(n==null?void 0:n.did)??"",timeDiff:0,contextRollup:{},tags:[],app:[(n==null?void 0:n.channel)??""],dims:""},config:{showEndPage:!1,showStartPage:!0,host:"",overlay:{showUser:!1},splash:{text:"",icon:"",bgImage:"",webLink:""},sideMenu:{showDownload:!0,showExit:!1,showShare:!0},apislug:"/action",repos:["/sunbird-plugins/renderer"],plugins:[{id:"org.sunbird.iframeEvent",ver:1,type:"plugin"},{id:"org.sunbird.player.endpage",ver:1.1,type:"plugin"}],enableTelemetryValidation:!1},metadata:t,data:s==="application/vnd.ekstep.ecml-archive"?t.body??{}:{}}}function NO(e){return document.querySelector(`script[src="${e}"]`)?Promise.resolve():new Promise((t,r)=>{const n=document.createElement("script");n.src=e,n.onload=()=>t(),n.onerror=()=>r(new Error(`Failed to load ${e}`)),document.head.appendChild(n)})}async function kO(e,t,r=100){await NO(OO[t]??""),!customElements.get(e)&&await new Promise((n,s)=>{let i=0;const o=setInterval(()=>{i++,customElements.get(e)?(clearInterval(o),n()):i>=r&&(clearInterval(o),s(new Error(`Custom element <${e}> did not register`)))},100)})}const xO=[{key:"author",label:"Author",icon:"👤"},{key:"license",label:"License",icon:"⚖️"},{key:"language",label:"Language",icon:"🌐"},{key:"gradeLevel",label:"Class",icon:"🏫"},{key:"subject",label:"Subject",icon:"📚"},{key:"contentType",label:"Type",icon:"🏷️"}];function AO({node:e}){const t=e.metadata??{},r=xO.flatMap(n=>{const s=t[n.key];if(!s)return[];const i=Array.isArray(s)?s.join(", "):String(s);return i?[{...n,val:i}]:[]});return r.length?l.jsx("div",{className:ze.infoStrip,children:r.map(n=>l.jsxs("div",{className:ze.infoChip,children:[n.icon&&l.jsx("span",{className:ze.infoChipIcon,children:n.icon}),l.jsx("span",{className:ze.infoChipLabel,children:n.label}),n.val]},n.key))}):null}function zh({node:e,hidden:t}){var n;const r=e.appIcon??((n=e.metadata)==null?void 0:n.appIcon);return l.jsx("div",{className:`${ze.coverOverlay} ${t?ze.coverHidden:""}`,children:r?l.jsxs(l.Fragment,{children:[l.jsx("img",{src:r,alt:e.name,className:ze.coverThumb}),l.jsx("div",{className:ze.coverPlayRing,children:l.jsx("div",{className:ze.coverPlayIcon})}),l.jsx("span",{className:ze.coverLabel,children:"Loading preview…"})]}):l.jsx("div",{className:ze.coverSkeleton})})}function Vh({message:e}){return l.jsxs("div",{className:ze.playerError,children:[l.jsx("span",{className:ze.playerErrorIcon,children:"⚠"}),l.jsx("span",{className:ze.playerErrorMsg,children:e})]})}function PO({mimeType:e}){const t=CO(e);return l.jsxs("span",{className:ze.typeBadge,"data-type":t.key,children:[l.jsx("span",{className:ze.typeDot}),t.label]})}const ml=({node:e,editorMode:t,type:r,singleQuestion:n})=>{var i;if(r==="quml")return l.jsx(LO,{node:e,editorMode:t,singleQuestion:!!n});const s=e.appIcon??((i=e.metadata)==null?void 0:i.appIcon);return l.jsxs("div",{className:ze.contentPlayerRoot,children:[l.jsxs("div",{className:ze.stage,children:[l.jsxs("div",{className:ze.playerHeader,children:[s&&l.jsx("img",{src:s,alt:"",className:ze.playerHeaderThumb}),l.jsx("span",{className:ze.playerHeaderTitle,children:e.name}),l.jsx(PO,{mimeType:e.mimeType??""})]}),l.jsx(MO,{node:e})]}),l.jsx(AO,{node:e})]})};function MO({node:e}){var v;const t=ae(m=>m.editorConfig),[r,n]=h.useState(()=>vl(e.mimeType??"")),[s,i]=h.useState(!1),[o,a]=h.useState(null),[c,d]=h.useState(e.metadata??{}),[u,f]=h.useState(!1),g=h.useRef(null),y=h.useRef(null),_=((v=t==null?void 0:t.config)==null?void 0:v.previewCdnUrl)??DO;h.useEffect(()=>{let m=!1;return f(!1),i(!1),a(null),d(e.metadata??{}),n(vl(e.mimeType??"")),gO(e.identifier).then(b=>{if(m)return;const S={...e.metadata??{},...b};d(S);const w=b.mimeType??e.mimeType??"";n(vl(w)),f(!0)}).catch(()=>{m||f(!0)}),()=>{m=!0}},[e.identifier]);const p=TO(e,c,t);return h.useEffect(()=>{if(!u||r!=="default-player")return;const m=g.current;if(!m)return;m.src=_;const b=()=>{try{const w=m.contentWindow;if(typeof(w==null?void 0:w.initializePreview)!="function"){a("Preview player unavailable. Check that /content/preview is reachable.");return}w.initializePreview(p),setTimeout(()=>i(!0),300)}catch(w){console.error("[ContentPlayer] initializePreview failed",w),a("Failed to initialize the content player.")}},S=()=>a("Preview player could not be loaded.");return m.addEventListener("load",b),m.addEventListener("error",S),()=>{m.removeEventListener("load",b),m.removeEventListener("error",S),m.src=""}},[e.identifier,r,_,u]),h.useEffect(()=>{if(!u||r==="default-player")return;const m=y.current;if(!m)return;const b=IO[r];if(!b)return;const S=p;kO(b,r).then(()=>{if(!y.current)return;if(!customElements.get(b)){n("default-player");return}const w=document.createElement(b);w.setAttribute("player-config",JSON.stringify(S)),w.addEventListener("playerEvent",()=>{}),w.addEventListener("telemetryEvent",()=>{}),m.innerHTML="",m.appendChild(w),setTimeout(()=>{try{w.playerConfig=S}catch{}i(!0)},200)}).catch(()=>{console.warn(`[ContentPlayer] ${r} script unavailable, falling back to iframe`),n("default-player")})},[e.identifier,r,u]),l.jsxs("div",{className:ze.aspectRatio,children:[o?l.jsx(Vh,{message:o}):l.jsx(zh,{node:e,hidden:s}),r==="default-player"?l.jsx("iframe",{ref:g,id:"contentPlayer",title:e.name,className:ze.playerFrame,name:"contentPlayer",allowFullScreen:!0}):l.jsx("div",{ref:y,className:ze.playerFrame})]})}function LO({node:e,editorMode:t,singleQuestion:r}){const n=ae(g=>g.editorConfig),s=xe(g=>g.treeData),i=h.useRef(null),o=r?wO(s,e.id):e.identifier,{data:a,isLoading:c,error:d}=vO(o??"",{enabled:!!o}),u=h.useMemo(()=>a?r?yO(a,e.identifier):a:null,[a,r,e.identifier]);h.useEffect(()=>{const g=i.current;if(!g||!u)return;let y=null,_=!1;return(async()=>{try{const p=await ao.createConfig(u,n==null?void 0:n.context,{mode:t==="edit"?"edit":"play"});if(_||!i.current)return;const v=ao.createElement(p);y=v,ao.attachEventListeners(v,m=>console.debug("[QumlPlayer] playerEvent",m.detail),m=>console.debug("[QumlPlayer] telemetryEvent",m)),g.innerHTML="",g.appendChild(v)}catch(p){console.error("[QumlPlayer] failed to initialize",p)}})(),()=>{_=!0,y&&(ao.removeEventListeners(y),y.remove()),oo.unloadStyles()}},[u,n,t,r]);const f=d?`Unable to load questionset: ${d.message}`:r&&!o?"Could not resolve the parent questionset for this question.":r&&a&&!u?"Question not found in the questionset.":null;return l.jsxs("div",{className:ze.qumlRoot,children:[f?l.jsx(Vh,{message:f}):c||!u?l.jsx(zh,{node:e,hidden:!1}):null,l.jsx("div",{ref:i,className:ze.playerWrapper})]})}const Vt={overlay:"_overlay_ifddx_1",modal:"_modal_ifddx_11",header:"_header_ifddx_21",body:"_body_ifddx_37",hint:"_hint_ifddx_43",list:"_list_ifddx_49",item:"_item_ifddx_55",selected:"_selected_ifddx_68",empty:"_empty_ifddx_73",footer:"_footer_ifddx_79",cancelBtn:"_cancelBtn_ifddx_87",moveBtn:"_moveBtn_ifddx_95"};function FO(e,t,r){const n=[],s=i=>{var o;for(const a of i)a.isFolder&&a.id!==r&&a.id!==t&&n.push(a),(o=a.children)!=null&&o.length&&s(a.children)};return s(e),n}const $O=({resourceId:e,resourceName:t,currentUnitId:r,onClose:n})=>{var u;const{treeData:s,moveNode:i}=xe(),o=FO(s,((u=s[0])==null?void 0:u.id)??"",r),[a,c]=h.useState(null),d=()=>{a&&(i(e,r,a),n())};return l.jsx("div",{className:Vt.overlay,role:"dialog","aria-label":"Move resource",children:l.jsxs("div",{className:Vt.modal,children:[l.jsxs("div",{className:Vt.header,children:[l.jsxs("span",{children:['Move "',t,'"']}),l.jsx("button",{onClick:n,"aria-label":"Close",children:l.jsx(zr,{size:16})})]}),l.jsxs("div",{className:Vt.body,children:[l.jsx("p",{className:Vt.hint,children:"Select a unit to move this content to:"}),l.jsxs("ul",{className:Vt.list,children:[o.map(f=>l.jsxs("li",{className:`${Vt.item} ${a===f.id?Vt.selected:""}`,onClick:()=>c(f.id),children:[l.jsx(Sv,{size:14}),l.jsx("span",{children:f.name})]},f.id)),o.length===0&&l.jsx("li",{className:Vt.empty,children:"No other units available"})]})]}),l.jsxs("div",{className:Vt.footer,children:[l.jsx("button",{className:Vt.cancelBtn,onClick:n,children:"Cancel"}),l.jsx("button",{className:Vt.moveBtn,onClick:d,disabled:!a,children:"Move here"})]})]})})},nr={overlay:"_overlay_16at9_1",modal:"_modal_16at9_11",header:"_header_16at9_21",body:"_body_16at9_37",table:"_table_16at9_43",pageInput:"_pageInput_16at9_61",empty:"_empty_16at9_68",footer:"_footer_16at9_74",cancelBtn:"_cancelBtn_16at9_82",saveBtn:"_saveBtn_16at9_90"};function jO(e){const t=[],r=n=>{var s;for(const i of n)!i.isFolder&&(!i.children||i.children.length===0)?t.push(i):(s=i.children)!=null&&s.length&&r(i.children)};return r(e),t}const BO=({onClose:e})=>{const{treeData:t,updateNode:r}=xe(),n=jO(t),[s,i]=h.useState(()=>Object.fromEntries(n.map(a=>{var c;return[a.id,String(((c=a.metadata)==null?void 0:c.pageNumber)??"")]}))),o=h.useCallback(()=>{for(const[a,c]of Object.entries(s))c!==""&&r(a,{pageNumber:parseInt(c,10)||void 0});e()},[s,r,e]);return l.jsx("div",{className:nr.overlay,role:"dialog","aria-label":"Assign Page Numbers",children:l.jsxs("div",{className:nr.modal,children:[l.jsxs("div",{className:nr.header,children:[l.jsx("span",{children:"Assign Page Numbers"}),l.jsx("button",{onClick:e,"aria-label":"Close",children:l.jsx(zr,{size:16})})]}),l.jsx("div",{className:nr.body,children:n.length===0?l.jsx("p",{className:nr.empty,children:"No content items found in this collection."}):l.jsxs("table",{className:nr.table,children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{children:"Content"}),l.jsx("th",{children:"Page Number"})]})}),l.jsx("tbody",{children:n.map(a=>l.jsxs("tr",{children:[l.jsx("td",{children:a.name}),l.jsx("td",{children:l.jsx("input",{type:"number",min:1,value:s[a.id]??"",onChange:c=>i(d=>({...d,[a.id]:c.target.value})),className:nr.pageInput})})]},a.id))})]})}),l.jsxs("div",{className:nr.footer,children:[l.jsx("button",{className:nr.cancelBtn,onClick:e,children:"Cancel"}),l.jsxs("button",{className:nr.saveBtn,onClick:o,children:[l.jsx(xv,{size:14})," Save"]})]})]})})},We={container:"_container_1a7t2_1",panelHeader:"_panelHeader_1a7t2_10",panelHeaderLeft:"_panelHeaderLeft_1a7t2_19",panelCollapseBtn:"_panelCollapseBtn_1a7t2_27",titleRow:"_titleRow_1a7t2_46",field:"_field_1a7t2_47",moveBtn:"_moveBtn_1a7t2_64",icon:"_icon_1a7t2_84",nameInput:"_nameInput_1a7t2_93",fieldHeader:"_fieldHeader_1a7t2_118",label:"_label_1a7t2_124",fieldCount:"_fieldCount_1a7t2_133",chips:"_chips_1a7t2_170",chip:"_chip_1a7t2_170",chipRemove:"_chipRemove_1a7t2_188",keywordInput:"_keywordInput_1a7t2_202",input:"_input_1a7t2_207",addBtn:"_addBtn_1a7t2_220",radioGroup:"_radioGroup_1a7t2_234",radioLabel:"_radioLabel_1a7t2_239"},UO=({node:e,editorMode:t,onMoveClick:r,reorderDialog:n})=>{var M,j;const{updateNode:s,markDirty:i}=xe(),o=t==="edit",a=Yi(e),c=ae(A=>A.relationalFormConfig),d=A=>c==null?void 0:c.find($=>$.code===A),u=A=>!c||!!d(A),f=(A,$)=>{var U;return((U=d(A))==null?void 0:U.label)||$},[g,y]=h.useState(!0),_=((M=e.metadata)==null?void 0:M.relationalMetadata)??{},[p,v]=h.useState(_.name??e.name??""),[m,b]=h.useState(""),[S,w]=h.useState(Array.isArray(_.keywords)?_.keywords:Array.isArray((j=e.metadata)==null?void 0:j.keywords)?e.metadata.keywords:[]),[E,T]=h.useState(!!_.optional);h.useEffect(()=>{var $,U;const A=(($=e.metadata)==null?void 0:$.relationalMetadata)??{};v(A.name??e.name??""),w(Array.isArray(A.keywords)?A.keywords:Array.isArray((U=e.metadata)==null?void 0:U.keywords)?e.metadata.keywords:[]),T(!!A.optional)},[e.id]);const x=()=>{p.trim()&&p!==e.name&&(s(e.id,{name:p.trim()}),i())},P=()=>{const A=m.trim();if(A&&!S.includes(A)){const $=[...S,A];w($),s(e.id,{keywords:$}),i()}b("")},F=A=>{const $=S.filter(U=>U!==A);w($),s(e.id,{keywords:$}),i()},N=A=>{T(A),s(e.id,{optional:A}),i()};return l.jsxs("div",{className:We.container,children:[l.jsxs("div",{className:We.panelHeader,children:[l.jsxs("div",{className:We.panelHeaderLeft,children:[l.jsx("span",{className:`sbx-ct-badge--${a.key}`,children:a.label}),o&&l.jsx("button",{type:"button",className:We.moveBtn,onClick:r,children:"Move to another unit"})]}),l.jsx("button",{type:"button",className:We.panelCollapseBtn,onClick:()=>y(A=>!A),"aria-expanded":g,"aria-label":g?"Collapse metadata panel":"Expand metadata panel",title:g?"Collapse":"Expand",children:g?l.jsx(hs,{size:15}):l.jsx(bv,{size:15})})]}),g&&l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:We.titleRow,children:[e.appIcon&&l.jsx("img",{src:e.appIcon,alt:"icon",className:We.icon}),l.jsx("input",{type:"text",className:We.nameInput,value:p,disabled:!o,onChange:A=>v(A.target.value),onBlur:x,placeholder:"Content name"})]}),u("keywords")&&l.jsxs("div",{className:We.field,children:[l.jsx("div",{className:We.fieldHeader,children:l.jsxs("label",{className:We.label,children:[f("keywords","Keywords"),S.length>0&&l.jsx("span",{className:We.fieldCount,children:S.length})]})}),S.length>0&&l.jsx("div",{className:We.chips,children:S.map(A=>l.jsxs("span",{className:We.chip,children:[A,o&&l.jsx("button",{type:"button",className:We.chipRemove,onClick:()=>F(A),children:"×"})]},A))}),o&&l.jsxs("div",{className:We.keywordInput,children:[l.jsx("input",{type:"text",className:We.input,value:m,placeholder:"Add keyword and press Enter",onChange:A=>b(A.target.value),onKeyDown:A=>{A.key==="Enter"&&(A.preventDefault(),P())}}),l.jsx("button",{type:"button",className:We.addBtn,onClick:P,children:"Add"})]})]}),u("optional")&&l.jsxs("div",{className:We.field,children:[l.jsx("label",{className:We.label,children:f("optional","Optional in Collection")}),l.jsxs("div",{className:We.radioGroup,children:[l.jsxs("label",{className:We.radioLabel,children:[l.jsx("input",{type:"radio",name:`optional-${e.id}`,checked:E===!0,onChange:()=>N(!0),disabled:!o}),"Yes"]}),l.jsxs("label",{className:We.radioLabel,children:[l.jsx("input",{type:"radio",name:`optional-${e.id}`,checked:E===!1,onChange:()=>N(!1),disabled:!o}),"No"]})]})]})]}),n]})},Ms={iconBtn:"_iconBtn_vl14u_1",editable:"_editable_vl14u_14",iconImg:"_iconImg_vl14u_26",placeholder:"_placeholder_vl14u_34",removeBtn:"_removeBtn_vl14u_41"},zO=({nodeId:e,value:t,editable:r})=>{const[n,s]=h.useState(!1),{updateNode:i,markDirty:o}=xe(),a=d=>{i(e,{appIcon:d}),o(),s(!1)},c=d=>{d.stopPropagation(),i(e,{appIcon:""}),o()};return l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:[Ms.iconBtn,r?Ms.editable:""].filter(Boolean).join(" "),role:r?"button":void 0,tabIndex:r?0:-1,"aria-label":r?"Select app icon":"App icon",onClick:()=>r&&s(!0),onKeyDown:d=>{r&&(d.key==="Enter"||d.key===" ")&&s(!0)},children:[t?l.jsx("img",{src:t,alt:"App icon",className:Ms.iconImg}):l.jsx("div",{className:Ms.placeholder,children:l.jsx(Qc,{size:18})}),t&&r&&l.jsx("button",{type:"button",className:Ms.removeBtn,onClick:c,"aria-label":"Remove icon",children:l.jsx(Yo,{size:11})})]}),n&&l.jsx(Dh,{nodeId:e,currentValue:t,onSelect:a,onClose:()=>s(!1)})]})},Xt={leafContentLayout:"_leafContentLayout_1osey_1",container:"_container_1osey_17",emptyState:"_emptyState_1osey_26",titleRow:"_titleRow_1osey_36",nodeTitle:"_nodeTitle_1osey_52",formArea:"_formArea_1osey_74",contentListArea:"_contentListArea_1osey_78",dropZone:"_dropZone_1osey_83",reviewComment:"_reviewComment_1osey_90",reviewCommentLabel:"_reviewCommentLabel_1osey_103",reviewCommentText:"_reviewCommentText_1osey_109"},VO="application/vnd.sunbird.questionset",qh="application/vnd.sunbird.question",qO=[VO,qh],HO=({editorMode:e,onToolbarEvent:t})=>{var j,A,$,U;const[r,n]=h.useState("details"),[s,i]=h.useState([]),[o,a]=h.useState(null),[c,d]=h.useState(!1),u=h.useRef(null),f=h.useRef(),{selectedNodeId:g,breadcrumb:y,activeNodeMeta:_,updateNode:p,treeData:v}=xe(),m=ae(Z=>{var se,be,Ee,ce;return((be=(se=Z.editorConfig)==null?void 0:se.context)==null?void 0:be.contentId)??((ce=(Ee=Z.editorConfig)==null?void 0:Ee.context)==null?void 0:ce.identifier)??""}),b=g?Hh(v,g):null,S=!!b&&!b.parent,w=!!(b!=null&&b.isFolder),E=b&&qO.includes(b.mimeType??""),T=(b==null?void 0:b.mimeType)===qh,x=b&&!b.isFolder&&!E&&!S,P=((j=b==null?void 0:b.metadata)==null?void 0:j.rejectComment)??(S?($=(A=v[0])==null?void 0:A.metadata)==null?void 0:$.rejectComment:void 0),F=h.useCallback(()=>{const Z=u.current;if(!Z||!g)return;const se=Z.innerText.trim();clearTimeout(f.current),f.current=setTimeout(()=>{p(g,{name:se})},600)},[g,p]),N=h.useCallback(Z=>{t({action:"onFormValueChange",data:Z})},[t]),M=h.useCallback((Z,se)=>{i(se),t({action:"onFormStatusChange",data:{isValid:Z,nodeId:g}})},[t,g]);return b?E?l.jsx(ml,{node:b,editorMode:e,type:"quml",singleQuestion:T}):x?l.jsxs("div",{className:Xt.leafContentLayout,children:[l.jsx(ml,{node:b,editorMode:e,type:"content"}),l.jsx(UO,{node:b,editorMode:e,onMoveClick:()=>a(b.identifier),reorderDialog:o?l.jsx($O,{resourceId:o,resourceName:b.name,currentUnitId:b.parent??"",onClose:()=>a(null)}):null})]}):l.jsxs("div",{className:Xt.container,children:[l.jsx(j1,{crumbs:y}),P&&l.jsxs("div",{className:Xt.reviewComment,role:"alert",children:[l.jsx("span",{className:Xt.reviewCommentLabel,children:"Reviewer comment:"}),l.jsx("span",{className:Xt.reviewCommentText,children:P})]}),l.jsxs("div",{className:Xt.titleRow,children:[S&&g&&l.jsx(zO,{nodeId:g,value:String(b.appIcon??((U=b.metadata)==null?void 0:U.appIcon)??""),editable:e==="edit"}),l.jsx("div",{ref:u,className:Xt.nodeTitle,contentEditable:e==="edit",suppressContentEditableWarning:!0,onInput:F,onBlur:F,"data-placeholder":"Untitled","aria-label":"Node title",children:b.name})]}),l.jsx(B1,{activeTab:r,onChange:Z=>n(Z),errorTabs:s,visibleTabs:S?void 0:["details"]}),l.jsx("div",{className:Xt.formArea,children:l.jsx(QE,{nodeMetadata:_,activeTab:r,isRoot:S,isFolder:w,editorMode:e,onFormValueChange:N,onFormStatusChange:M},`${g??"none"}:${S?"root":"node"}`)}),(w||S)&&r==="details"&&l.jsx("div",{className:Xt.contentListArea,children:l.jsx(fO,{editorMode:e})}),l.jsx(hO,{isActive:!1,label:"Drop to add content to this unit",nodeId:g??void 0,className:Xt.dropZone}),c&&l.jsx(BO,{contentId:m,onClose:()=>d(!1)})]}):l.jsx("div",{className:Xt.emptyState,children:l.jsx("p",{children:"Select a unit from the outline to edit its details"})})};function Hh(e,t){for(const r of e){if(r.id===t)return r;if(r.children){const n=Hh(r.children,t);if(n)return n}}}const Wh=mi((e,t)=>({allContent:[],filteredContent:[],searchQuery:"",activeFilter:"all",advancedFilters:{},isLoading:!1,totalCount:0,offset:0,sortAZ:!1,setContent:(r,n)=>{e({allContent:r,totalCount:n,offset:r.length}),t().applyFilter()},appendContent:(r,n)=>{const i=[...t().allContent,...r];e({allContent:i,totalCount:n,offset:i.length}),t().applyFilter()},setFilter:r=>{e({activeFilter:r}),t().applyFilter()},setSearch:r=>{e({searchQuery:r}),t().applyFilter()},setLoading:r=>e({isLoading:r}),setAdvancedFilters:r=>e({advancedFilters:r}),setOffset:r=>e({offset:r}),setSortAZ:r=>e({sortAZ:r}),applyFilter:()=>{const{allContent:r,activeFilter:n,searchQuery:s}=t();let i=r;if(n&&n!=="all"){const o=n.toLowerCase();i=i.filter(a=>[a.mimeType??"",a.primaryCategory??"",a.contentType??""].join(" ").toLowerCase().includes(o))}if(s&&s.trim()!==""){const o=s.toLowerCase().trim();i=i.filter(a=>(a.name??"").toLowerCase().includes(o))}e({filteredContent:i})}})),WO=20;function Qh(){var d;const e=ae(u=>u.editorConfig),t=xe(u=>u.selectedNodeId),r=xe(u=>u.treeData),n=h.useCallback(()=>{if(!t||!r.length)return 0;function u(f,g,y=0){var _;for(const p of f){if(p.id===g)return y;if((_=p.children)!=null&&_.length){const v=u(p.children,g,y+1);if(v>=0)return v}}return-1}return Math.max(0,u(r,t))},[t,r])(),s=(d=e==null?void 0:e.config)==null?void 0:d.hierarchy;if(!s)return[...Hf];const i=`level${n}`,o=s[i],a=o==null?void 0:o.children,c=a==null?void 0:a.Content;return c!=null&&c.length?c:[...Hf]}function QO(){const e=Wh(),t=ae(f=>{var g,y;return((y=(g=f.editorConfig)==null?void 0:g.context)==null?void 0:y.channel)??""}),r=Qh(),n=h.useRef(),s=h.useCallback(async(f="",g="all",y={},_=!0,p=!1)=>{var v,m,b,S,w;e.setLoading(!0);try{const E={status:["Live"],primaryCategory:g&&g!=="all"?[g]:r};(v=y==null?void 0:y.board)!=null&&v.length&&(E.board=y.board),(m=y==null?void 0:y.medium)!=null&&m.length&&(E.medium=y.medium),(b=y==null?void 0:y.gradeLevel)!=null&&b.length&&(E.gradeLevel=y.gradeLevel),(S=y==null?void 0:y.subject)!=null&&S.length&&(E.subject=y.subject),(w=y==null?void 0:y.primaryCategory)!=null&&w.length&&(E.primaryCategory=y.primaryCategory);const T=_?0:e.offset,{content:x,count:P}=await pO({filters:E,query:f,limit:f?50:WO,offset:T,channel:t||void 0,sortBy:p?{name:"asc"}:{lastUpdatedOn:"desc"}});_?e.setContent(x,P):e.appendContent(x,P)}catch(E){console.error("[useLibrary] load error:",E)}finally{e.setLoading(!1)}},[r,t]);h.useEffect(()=>{s()},[t]);const i=h.useCallback(f=>{e.setSearch(f),clearTimeout(n.current),n.current=setTimeout(()=>s(f,e.activeFilter,e.advancedFilters,!0,e.sortAZ),300)},[e.activeFilter,e.advancedFilters,e.sortAZ,s]),o=h.useCallback(f=>{e.setFilter(f),s(e.searchQuery,f,e.advancedFilters,!0,e.sortAZ)},[e.searchQuery,e.advancedFilters,e.sortAZ,s]),a=h.useCallback(f=>{e.setAdvancedFilters(f),s(e.searchQuery,e.activeFilter,f,!0,e.sortAZ)},[e.searchQuery,e.activeFilter,e.sortAZ,s]),c=h.useCallback(()=>{const f=!e.sortAZ;e.setSortAZ(f),s(e.searchQuery,e.activeFilter,e.advancedFilters,!0,f)},[e.sortAZ,e.searchQuery,e.activeFilter,e.advancedFilters,s]),d=h.useCallback(()=>{e.isLoading||s(e.searchQuery,e.activeFilter,e.advancedFilters,!1,e.sortAZ)},[e.isLoading,e.searchQuery,e.activeFilter,e.advancedFilters,e.sortAZ,s]),u=e.allContent.length<e.totalCount;return{content:e.filteredContent,isLoading:e.isLoading,totalCount:e.totalCount,activeFilter:e.activeFilter,advancedFilters:e.advancedFilters,searchQuery:e.searchQuery,sortAZ:e.sortAZ,hasMore:u,search:i,setFilter:o,applyAdvancedFilters:a,toggleSort:c,loadMore:d,refetch:()=>s(e.searchQuery,e.activeFilter,e.advancedFilters,!0,e.sortAZ)}}const sr={card:"_card_jzciw_1",addBtn:"_addBtn_jzciw_17",dragging:"_dragging_jzciw_24",ctIcon:"_ctIcon_jzciw_29",info:"_info_jzciw_33",name:"_name_jzciw_41",meta:"_meta_jzciw_50",addBtnMuted:"_addBtnMuted_jzciw_78",added:"_added_jzciw_87",addedBadge:"_addedBadge_jzciw_96"},KO={video:Ro,pdf:Ho,h5p:Wo,scorm:Ko,audio:Qo,quiz:Vo,default:mn},GO=({item:e,onAdd:t,onPreview:r,isDraggable:n,isAdded:s})=>{var p,v;const i=Yi(e),o=KO[i.key]??mn,a=Za(),c=I1(),d=a&&!s&&c,{attributes:u,listeners:f,setNodeRef:g,isDragging:y}=$c({id:e.identifier,disabled:!n||!a||!c,data:{type:"library-item",item:e}}),_=()=>{r&&r(e)};return l.jsxs("div",{ref:g,className:[sr.card,y?sr.dragging:"",s?sr.added:""].join(" "),"aria-label":e.name,...n?{...u,...f}:{},role:"listitem",onClick:_,children:[l.jsx("span",{className:[`sbx-ct-sq--${i.key}`,sr.ctIcon].join(" "),"aria-hidden":"true",children:l.jsx(o,{size:14})}),l.jsxs("div",{className:sr.info,children:[l.jsx("span",{className:sr.name,title:e.name,children:e.name}),l.jsxs("span",{className:sr.meta,children:[((p=e.organisation)==null?void 0:p[0])??e.channel??"",(v=e.organisation)!=null&&v[0]&&e.primaryCategory?" · ":"",e.primaryCategory??""]})]}),s&&l.jsx("span",{className:sr.addedBadge,"aria-label":"Already added",title:"Already added to this collection",children:l.jsx(vn,{size:12})}),!s&&l.jsx("button",{type:"button",className:[sr.addBtn,!d&&a?sr.addBtnMuted:""].join(" "),onClick:m=>{m.stopPropagation(),t(e)},disabled:!a,"aria-disabled":!d,"aria-label":`Add ${e.name} to unit`,title:a?c?"Add to unit":"Select a unit to add":"Only Draft content can be added",children:l.jsx(ps,{size:14})})]})},Kh={chips:"_chips_xhhaq_1",chip:"_chip_xhhaq_1"},YO=({filters:e,active:t,onChange:r})=>l.jsx("div",{className:Kh.chips,role:"group","aria-label":"Content type filters",children:e.map(n=>l.jsx("button",{type:"button",role:"radio","aria-checked":t===n.value,className:["sbx-chip",t===n.value?"filled":"outline",Kh.chip].join(" "),onClick:()=>r(n.value),children:n.label},n.value))}),st={panel:"_panel_1cl11_1",header:"_header_1cl11_10",headerTitle:"_headerTitle_1cl11_19",closeBtn:"_closeBtn_1cl11_25",body:"_body_1cl11_43",section:"_section_1cl11_59",sectionLabel:"_sectionLabel_1cl11_65",chips:"_chips_1cl11_73",chip:"_chip_1cl11_73",active:"_active_1cl11_96",footer:"_footer_1cl11_102",resetBtn:"_resetBtn_1cl11_112",applyBtn:"_applyBtn_1cl11_129"},RO=[{key:"board",label:"Board"},{key:"medium",label:"Medium"},{key:"gradeLevel",label:"Class"},{key:"subject",label:"Subject"}],XO=new Set(["board","medium","gradeLevel","subject","topic"]),ZO=({local:e,toggle:t})=>{const r=Qh();return r.length?l.jsxs("div",{className:st.section,children:[l.jsx("div",{className:st.sectionLabel,children:"Primary Category"}),l.jsx("div",{className:st.chips,children:r.map(n=>l.jsx("button",{type:"button",className:[st.chip,(e.primaryCategory??[]).includes(n)?st.active:""].join(" "),onClick:()=>t("primaryCategory",n),children:n},n))})]}):null},JO=({isOpen:e,filters:t,onApply:r,onClose:n})=>{var p,v;const s=ae(m=>m.editorConfig),i=ae(m=>m.searchFormConfig),o=ae(m=>m.contentFramework),a=ae(m=>m.contentTargetFWIds),{organisationFramework:c}=_h(o??((p=s==null?void 0:s.context)==null?void 0:p.framework),a??((v=s==null?void 0:s.context)==null?void 0:v.targetFWIds)),[d,u]=h.useState(t),f=i!=null&&i.length?i.filter(m=>XO.has(m.code)).map(m=>({key:m.code,label:m.label||m.code})):RO;h.useEffect(()=>{u(t)},[t]);const g=(m,b)=>{u(S=>{const w=S[m]??[],E=w.includes(b)?w.filter(T=>T!==b):[...w,b];return{...S,[m]:E}})},y=(c==null?void 0:c.categories)??[],_=m=>{var b;return((b=y.find(S=>S.code===m))==null?void 0:b.terms)??[]};return e?l.jsxs("div",{className:st.panel,role:"dialog","aria-label":"Filter library","aria-modal":"true",children:[l.jsxs("div",{className:st.header,children:[l.jsx("span",{className:st.headerTitle,children:"Filters"}),l.jsx("button",{type:"button",className:st.closeBtn,onClick:n,"aria-label":"Close filters",children:l.jsx(zr,{size:16})})]}),l.jsxs("div",{className:st.body,children:[f.map(({key:m,label:b})=>{const S=_(m);return S.length?l.jsxs("div",{className:st.section,children:[l.jsx("div",{className:st.sectionLabel,children:b}),l.jsx("div",{className:st.chips,children:S.slice(0,20).map(w=>l.jsx("button",{type:"button",className:[st.chip,(d[m]??[]).includes(w.name)?st.active:""].join(" "),onClick:()=>g(m,w.name),children:w.name},w.identifier))})]},m):null}),l.jsx(ZO,{local:d,toggle:g})]}),l.jsxs("div",{className:st.footer,children:[l.jsx("button",{type:"button",className:st.resetBtn,onClick:()=>u({}),children:"Reset"}),l.jsx("button",{type:"button",className:st.applyBtn,onClick:()=>{r(d),n()},children:"Apply"})]})]}):null},fr={header:"_header_6qdpu_10",title:"_title_6qdpu_20",headerActions:"_headerActions_6qdpu_31",iconBtn:"_iconBtn_6qdpu_38",playerArea:"_playerArea_6qdpu_56",footer:"_footer_6qdpu_64",addBtn:"_addBtn_6qdpu_73",modalOverlay:"_modalOverlay_6qdpu_92",modalPanel:"_modalPanel_6qdpu_103"},eI=({content:e,onAdd:t,onClose:r})=>{if(!e)return null;const n={id:e.identifier,identifier:e.identifier,name:e.name??"",mimeType:e.mimeType,primaryCategory:e.primaryCategory,contentType:e.contentType,appIcon:e.appIcon,status:e.status,isFolder:!1,children:[],metadata:e};return Me.createPortal(l.jsx("div",{className:fr.modalOverlay,role:"dialog","aria-modal":"true","aria-label":"Content preview",onClick:r,children:l.jsxs("div",{className:fr.modalPanel,onClick:s=>s.stopPropagation(),children:[l.jsxs("div",{className:fr.header,children:[l.jsx("span",{className:fr.title,title:e.name,children:e.name}),l.jsx("div",{className:fr.headerActions,children:l.jsx("button",{type:"button",className:fr.iconBtn,onClick:r,"aria-label":"Close preview",children:l.jsx(zr,{size:16})})})]}),l.jsx("div",{className:fr.playerArea,children:l.jsx(ml,{node:n,editorMode:"read",type:"content"})}),l.jsx("div",{className:fr.footer,children:l.jsx("button",{type:"button",className:fr.addBtn,onClick:()=>t(e),children:"+ Add to Unit"})})]})}),document.body)},Ve={dock:"_dock_1lpg0_1",header:"_header_1lpg0_8",headerLeft:"_headerLeft_1lpg0_17",headerTitle:"_headerTitle_1lpg0_24",count:"_count_1lpg0_30",searchRow:"_searchRow_1lpg0_39",searchWrap:"_searchWrap_1lpg0_47",searchIcon:"_searchIcon_1lpg0_53",searchInput:"_searchInput_1lpg0_62",filterToggleBtn:"_filterToggleBtn_1lpg0_80",filterToggleBtnActive:"_filterToggleBtnActive_1lpg0_99",filterBadge:"_filterBadge_1lpg0_105",filters:"_filters_1lpg0_124",mainArea:"_mainArea_1lpg0_134",sidePanelOverlay:"_sidePanelOverlay_1lpg0_143",cardList:"_cardList_1lpg0_152",skeleton:"_skeleton_1lpg0_168",skeletonIcon:"_skeletonIcon_1lpg0_178",skeletonText:"_skeletonText_1lpg0_186",skeletonLine:"_skeletonLine_1lpg0_193",skeletonLineSm:"_skeletonLineSm_1lpg0_200",loadMoreBtn:"_loadMoreBtn_1lpg0_215",emptyState:"_emptyState_1lpg0_240",collapseBtn:"_collapseBtn_1lpg0_260"};function tI(e){const t=new Set,r=[...e];for(;r.length>0;){const n=r.shift();n.isFolder||t.add(n.identifier),n.children&&r.push(...n.children)}return t}const rI=({editorMode:e,collapsed:t=!1,onToggleCollapse:r})=>{const{content:n,isLoading:s,totalCount:i,activeFilter:o,searchQuery:a,sortAZ:c,hasMore:d,search:u,setFilter:f,applyAdvancedFilters:g,toggleSort:y,loadMore:_}=QO(),{addResource:p,selectedNodeId:v,treeData:m}=xe(),b=e==="edit",[S,w]=h.useState(!1),[E,T]=h.useState({}),[x,P]=h.useState(null),F=h.useMemo(()=>tI(m),[m]),N=h.useCallback(U=>{var be;if(!v){Ie.error("Select a unit first");return}const Z=(be=m[0])==null?void 0:be.id;if(v===Z){Ie("Select a unit from the outline to add content — resources cannot be added directly to the course.",{icon:"ℹ️",duration:4e3});return}if(p(U,v)===!1){Ie.error(`"${U.name}" is already in this collection`);return}Ie.success(`Added "${U.name}"`)},[v,p,m]),M=h.useCallback(U=>{T(U),g(U)},[g]),j=h.useCallback(U=>{P(U)},[]),A=h.useCallback(U=>{N(U),P(null)},[N]),$=h.useMemo(()=>Object.values(E).reduce((U,Z)=>U+((Z==null?void 0:Z.length)??0),0),[E]);return l.jsxs("div",{className:Ve.dock,children:[l.jsx("div",{className:Ve.header,children:l.jsxs("div",{className:Ve.headerLeft,children:[l.jsx("button",{type:"button",className:Ve.collapseBtn,onClick:r,"aria-label":"Collapse library panel",title:"Collapse library",children:l.jsx(Tv,{size:15})}),l.jsx(Ov,{size:16}),l.jsx("span",{className:Ve.headerTitle,children:"Library"}),i>0&&l.jsx("span",{className:Ve.count,children:i})]})}),l.jsxs("div",{className:Ve.searchRow,children:[l.jsxs("div",{className:Ve.searchWrap,children:[l.jsx(Go,{size:14,className:Ve.searchIcon}),l.jsx("input",{type:"search",className:Ve.searchInput,placeholder:"Search content…",value:a,onChange:U=>u(U.target.value),"aria-label":"Search library"})]}),l.jsx("button",{type:"button",className:[Ve.filterToggleBtn,c?Ve.filterToggleBtnActive:""].join(" "),onClick:y,"aria-label":c?"Sort: A–Z (click for Recent)":"Sort: Recent (click for A–Z)",title:c?"A–Z":"Recent",children:c?l.jsx(vv,{size:15}):l.jsx(_v,{size:15})}),l.jsxs("button",{type:"button",className:[Ve.filterToggleBtn,S?Ve.filterToggleBtnActive:""].join(" "),onClick:()=>w(U=>!U),"aria-label":"Toggle advanced filters","aria-pressed":S,title:"Advanced filters",children:[l.jsx(Mv,{size:15}),$>0&&l.jsx("span",{className:Ve.filterBadge,children:$})]})]}),l.jsx("div",{className:Ve.filters,children:l.jsx(YO,{filters:D1,active:o,onChange:f})}),l.jsxs("div",{className:Ve.mainArea,children:[l.jsx("div",{className:Ve.cardList,role:"list","aria-label":"Library content",children:s&&n.length===0?Array.from({length:4}).map((U,Z)=>l.jsxs("div",{className:Ve.skeleton,"aria-hidden":"true",children:[l.jsx("div",{className:Ve.skeletonIcon}),l.jsxs("div",{className:Ve.skeletonText,children:[l.jsx("div",{className:Ve.skeletonLine}),l.jsx("div",{className:Ve.skeletonLineSm})]})]},Z)):n.length>0?l.jsxs(l.Fragment,{children:[n.map(U=>l.jsx(GO,{item:U,onAdd:N,onPreview:j,isDraggable:b,isAdded:F.has(U.identifier)},U.identifier)),d&&l.jsx("button",{type:"button",className:Ve.loadMoreBtn,onClick:_,disabled:s,"aria-label":"Load more content",children:s?"Loading…":"Load More"})]}):l.jsxs("div",{className:Ve.emptyState,children:[l.jsx(Go,{size:24}),l.jsx("p",{children:"No content found"}),l.jsx("span",{children:"Try a different search or filter"})]})}),S&&l.jsx("div",{className:Ve.sidePanelOverlay,children:l.jsx(JO,{isOpen:S,filters:E,onApply:M,onClose:()=>w(!1)})}),x&&l.jsx(eI,{content:x,onAdd:A,onClose:()=>P(null)})]})]})};function nI(e,t,r){const n={},s={},i=new Set(["id","isFolder","children","parent","isNew","breadcrumb","title","relationalMetadata","optional"]),o=new Set(["targetBoardIds","targetMediumIds","targetGradeLevelIds","targetSubjectIds","targetFWIds","targetTopicIds","topic","topicsIds"]),a=new Set(["audience","attributions","keywords","language","additionalCategories","medium","gradeLevel","subject","boardIds","mediumIds","gradeLevelIds","subjectIds","targetBoardIds","targetMediumIds","targetGradeLevelIds","targetSubjectIds","dialcodes"]),c=new Set(["copyrightYear","compatibilityLevel","version"]);function d(g,y=!1){const _={};for(const[p,v]of Object.entries(g))if(!i.has(p)&&!(y&&o.has(p)))if(a.has(p))Array.isArray(v)?_[p]=v:v!=null&&v!==""?_[p]=[v]:_[p]=[];else if(c.has(p)){const m=Number(v);isNaN(m)||(_[p]=m)}else _[p]=v;return _}function u(g){var _;const y={};for(const p of g.children??[]){if(p.isFolder)continue;const v=t[p.identifier];if(!v)continue;const{isNew:m,...b}=v;if(Object.keys(b).length===0)continue;const S=((_=p.metadata)==null?void 0:_.relationalMetadata)??{};y[p.identifier]={name:p.name,...S,...b}}return y}function f(g,y){var S,w;const _=g.identifier,p=t[_],v=_.startsWith("temp-")||!!(p!=null&&p.isNew),m=!g.isFolder&&!y;if(y||v||p&&!m){let E;if(v)E={mimeType:"application/vnd.ekstep.content-collection",code:_,contentType:((S=g.metadata)==null?void 0:S.contentType)??"CourseUnit",primaryCategory:((w=g.metadata)==null?void 0:w.primaryCategory)??"Course Unit",name:g.name,visibility:"Parent",channel:r,...d(g.metadata??{})};else if(y){const{isNew:T,...x}=p??{};E={...d(g.metadata??{},!0),...d(x,!1),name:g.name}}else{const{isNew:T,...x}=p??{};E={name:g.name,visibility:"Parent",...d(x,!0)}}n[_]={metadata:E,objectType:g.objectType||(g.isFolder?"Collection":"Content"),root:y,isNew:v}}const b=g.isFolder?u(g):{};s[_]={name:g.name,children:(g.children??[]).map(E=>E.identifier),...Object.keys(b).length>0?{relationalMetadata:b}:{},root:y},(g.children??[]).forEach(E=>f(E,!1))}return e.forEach((g,y)=>f(g,y===0)),{nodesModified:n,hierarchy:s}}function sI(){const[e,t]=h.useState(!1),r=xe(u=>u.treeCache),n=xe(u=>u.treeData),s=ae(u=>u.isDirty),i=ae(u=>u.lastSaved),{setIsDirty:o,setLastSaved:a}=ae(),c=ae(u=>u.editorConfig);return{save:h.useCallback(async()=>{if(!c||e)return;const u=c.context.contentId??c.context.identifier??"";if(!u)return;const f=c.context.channel??"",g=c.context.userId??c.context.uid??"";t(!0);try{const{nodesModified:y,hierarchy:_}=nI(n,r,f),{identifiers:p}=await Jb(u,y,_,g);p&&Object.keys(p).length>0&&xe.getState().replaceNodeIds(p);const v=new Date().toISOString();a(v),o(!1)}catch(y){console.error("[useSaveHierarchy] save failed:",y),Ie.error("Failed to save. Please try again.")}finally{t(!1)}},[c,e,n,r,o,a]),isSaving:e,isDirty:s,lastSaved:i}}function iI(e){const t=ae(o=>o.editorConfig),r=ae(o=>o.setButtonLoader),n=ae(o=>o.validateAllForms),s=xe(o=>o.treeData);return{runAction:h.useCallback(async(o,a)=>{var u,f,g,y;const c=((u=t==null?void 0:t.context)==null?void 0:u.contentId)??((f=t==null?void 0:t.context)==null?void 0:f.identifier)??"";if(!c)return Ie.error("No content identifier found."),!1;const d=((g=t==null?void 0:t.context)==null?void 0:g.userId)??((y=t==null?void 0:t.context)==null?void 0:y.uid)??"";try{switch(o){case"sendForReview":return n(s)?(r("saveCollection",!0),await e(),await r_(c),Ie.success("Content sent for review"),!0):(Ie.error("Some units have missing required fields. Please fill them before sending for review."),!1);case"reject":{r("rejectCollection",!0);const _=(a==null?void 0:a.comment)??"";return await n_(c,_),Ie.success("Content rejected and sent back to the author"),!0}case"publish":return n(s)?(r("publishCollection",!0),await e(),await e_(c,d),Ie.success("Content published successfully"),!0):(Ie.error("Some units have missing required fields. Please fill them before publishing."),!1);default:return!1}}catch(_){console.error(`[useToolbarActions] ${o} failed`,_);const p=o==="sendForReview"?"send for review":o==="reject"?"reject":"publish";return Ie.error(`Failed to ${p}. Please try again.`),!1}finally{r("saveCollection",!1),r("rejectCollection",!1),r("publishCollection",!1)}},[t,e,r])}}const Lt={shell:"_shell_90fon_1",workspace:"_workspace_90fon_8",sidebarCollapsed:"_sidebarCollapsed_90fon_16",dockCollapsed:"_dockCollapsed_90fon_19",dock:"_dock_90fon_19",outline:"_outline_90fon_40",reopenTab:"_reopenTab_90fon_45",outlineHidden:"_outlineHidden_90fon_79",editor:"_editor_90fon_86",dockHidden:"_dockHidden_90fon_101",dockReopenTab:"_dockReopenTab_90fon_108",dragChip:"_dragChip_90fon_133",dragChipLabel:"_dragChipLabel_90fon_148"},oI=({editorMode:e,onToolbarEvent:t,onContentAdded:r,onHierarchySaved:n})=>{const[s,i]=h.useState(null),[o,a]=h.useState(!1),[c,d]=h.useState(!1),[u,f]=h.useState(!1),{addResource:g,treeData:y}=xe(),_=ae(A=>A.setFormStatus),[p,v]=h.useState(!0),m=xe(A=>A.selectedNodeId),{save:b,isSaving:S,isDirty:w,lastSaved:E}=sI(),{runAction:T}=iI(b);h.useEffect(()=>{if(!w)return;const A=$=>{$.preventDefault(),$.returnValue=""};return window.addEventListener("beforeunload",A),()=>window.removeEventListener("beforeunload",A)},[w]);const x=ic(xo(di,{activationConstraint:{distance:8}})),P=h.useCallback(A=>{var U;const $=(U=A.active.data.current)==null?void 0:U.item;$&&i($)},[]),F=h.useCallback(A=>{var Ee,ce;i(null);const $=(Ee=A.active.data.current)==null?void 0:Ee.item;if(!$)return;const U=A.over,Z=(U==null?void 0:U.id)??m??void 0;if(!Z){Ie.error("Drop onto a unit to add content");return}const se=(ce=y[0])==null?void 0:ce.id;if(Z===se){Ie.error("Drop content onto a unit, not directly on the course.");return}if(!g($,Z)){Ie.error(`"${$.name}" is already in this collection`);return}r==null||r($,Z),Ie.success(`Added "${$.name}" to unit`)},[m,g,r]),N=h.useCallback(async A=>{if(A.action==="onFormStatusChange"){const{isValid:$,nodeId:U}=A.data??{},Z=$!==!1;v(Z),U&&_(U,Z);return}if(A.action==="back"&&w){f(!0);return}if(A.action==="saveCollection"){if(!p){Ie.error("Please fill the required metadata");return}await b(),n==null||n(y),t==null||t(A);return}if(A.action==="sendForReview"||A.action==="reject"||A.action==="publish"){await T(A.action,A.data)&&(t==null||t(A));return}t==null||t(A)},[b,T,t,n,y,w,p]),M=h.useCallback(async()=>{await b(),f(!1),n==null||n(y),t==null||t({action:"back"})},[b,n,t,y]),j=h.useCallback(()=>{f(!1),t==null||t({action:"back"})},[t]);return l.jsxs(Lc,{sensors:x,onDragStart:P,onDragEnd:F,children:[l.jsxs("div",{className:Lt.shell,children:[l.jsx(h_,{editorMode:e,isSaving:S,isDirty:w,lastSaved:E,isFormValid:p,onToolbarEvent:N}),l.jsxs("div",{className:[Lt.workspace,o?Lt.sidebarCollapsed:"",c?Lt.dockCollapsed:""].filter(Boolean).join(" "),children:[l.jsx("aside",{className:[Lt.outline,o?Lt.outlineHidden:""].join(" "),"aria-label":"Course outline","aria-hidden":o,children:l.jsx($1,{editorMode:e,collapsed:o,onToggleCollapse:()=>a(A=>!A)})}),o&&l.jsx("button",{className:Lt.reopenTab,onClick:()=>a(!1),title:"Show outline",type:"button",children:"›"}),l.jsx("main",{className:Lt.editor,role:"main","aria-label":"Content editor",children:l.jsx(HO,{editorMode:e,onToolbarEvent:N})}),l.jsx("aside",{className:[Lt.dock,c?Lt.dockHidden:""].filter(Boolean).join(" "),"aria-label":"Content library","aria-hidden":c,children:l.jsx(rI,{editorMode:e,collapsed:c,onToggleCollapse:()=>d(A=>!A)})}),c&&l.jsx("button",{className:Lt.dockReopenTab,onClick:()=>d(!1),title:"Show library",type:"button",children:"‹"})]})]}),l.jsx(fv,{dropAnimation:null,children:s?l.jsx("div",{className:Lt.dragChip,children:l.jsx("span",{className:Lt.dragChipLabel,children:s.name})}):null}),u&&l.jsx(p_,{onSave:M,onDiscard:j,onCancel:()=>f(!1),isSaving:S})]})},aI="v1";function lI(e){const t=e.validations,r=t==null?void 0:t.find(s=>s.type==="maxlength"||s.type==="maxLength");if(!r)return e.maxLength;const n=Number(r.value);return Number.isFinite(n)?n:void 0}function Gh(e,t){var r;return{code:e.code??"",label:e.label??e.name??e.code??"",name:e.name,inputType:e.inputType,dataType:e.dataType,required:e.required===!0||Array.isArray(e.validations)&&e.validations.some(n=>n.type==="required")||String(((r=e.renderingHints)==null?void 0:r.class)??"").includes("required"),editable:e.editable!==!1,visible:e.visible!==!1,placeholder:e.placeholder,maxLength:lI(e),depends:e.depends,sourceCategory:e.sourceCategory,range:e.range,enum:e.enum,default:e.default,defaultValue:e.defaultValue,index:e.index,section:t,output:e.output}}function Nr(e){const t=e==null?void 0:e.properties;if(!Array.isArray(t))return[];const r=[];for(const n of t)if(Array.isArray(n.fields)){const s=n.name??void 0,i=n.fields.filter(o=>!!o.code).sort((o,a)=>(o.index??0)-(a.index??0));for(const o of i)r.push(Gh(o,s))}else n.code&&r.push(Gh(n));return r}function cI(e){const t=e==null?void 0:e.properties;if(!t)return{};const r={};for(const[n,s]of Object.entries(t))s&&"default"in s&&(r[n]=s.default);return r}async function uI(e,t,r="Collection",n=aI){var d,u;const i=(u=(d=(await Ae.post(`/action/object/category/definition/${n}/read?fields=objectMetadata,forms,name,label`,{request:{objectCategoryDefinition:{objectType:r,name:e,...t?{channel:t}:{}}}})).data)==null?void 0:d.result)==null?void 0:u.objectCategoryDefinition,o=(i==null?void 0:i.forms)??{},a=(i==null?void 0:i.objectMetadata)??{},c=a.config??{};return{rootForm:Nr(o.create),unitForm:Nr(o.unitMetadata),childForm:Nr(o.childMetadata),searchForm:Nr(o.search??o.searchConfig),relationalForm:Nr(o.relationalMetadata),publishChecklist:Nr(o.publishchecklist),reviewChecklist:Nr(o.review),rfcChecklist:Nr(o.requestforchangeschecklist),schemaDefaults:cI(a.schema),frameworkMetadata:c.frameworkMetadata??{},sourcingSettings:c.sourcingSettings??{}}}function dI({config:e,onError:t}){const[r,n]=h.useState(!0),[s,i]=h.useState(null),[o,a]=h.useState(!1),{setEditorConfig:c,setEditorMode:d,setCategoryDefinition:u,setContentFramework:f}=ae(),{setTreeData:g,selectNode:y}=xe();return h.useEffect(()=>{let _=!1;async function p(){var v,m;try{n(!0),i(null),e.apiBaseUrl&&Yu(e.apiBaseUrl),c(e),d(e.config.mode);const b=e.context.contentId??e.context.identifier??"";if(b){const S=e.config.objectType==="QuestionSet",{rootNode:w}=S?await Zb(b):await Zu(b);if(!_&&(g(w?[w]:[]),w)){y(w.id);const F=w.metadata??{},N=F.framework??e.context.framework??null,M=F.targetFWIds??e.context.targetFWIds??null;f(N,M)}const E=e.config.primaryCategory??"Course",T=e.context.channel??"",x=e.config.categoryDefinitionApiVersion??"v1";try{const P=await uI(E,T,e.config.objectType??"Collection",x);if(!_){u(P);const F=((v=P.sourcingSettings)==null?void 0:v.collection)??{},N={};F.maxDepth&&!e.config.maxDepth&&(N.maxDepth=F.maxDepth),F.children&&!e.config.children&&(N.children=F.children),F.hierarchy&&!((m=e.config.hierarchy)!=null&&m.level1)&&(N.hierarchy={...e.config.hierarchy??{},...F.hierarchy}),Object.keys(N).length>0&&c({...e,config:{...e.config,...N}})}}catch{}}_||a(!0)}catch(b){if(!_){const S=b instanceof Error?b:new Error(String(b));i(S),t==null||t(S)}}finally{_||n(!1)}}return p(),()=>{_=!0}},[e.context.contentId,e.context.identifier]),{isLoading:r,error:s,isReady:o}}const Ls={root:"_root_qcpw6_1",loadingState:"_loadingState_qcpw6_10",loadingSpinner:"_loadingSpinner_qcpw6_20",errorState:"_errorState_qcpw6_34"},fI=new jp({defaultOptions:{queries:{retry:1,refetchOnWindowFocus:!1}}});class hI extends h.Component{constructor(t){super(t),this.state={error:null}}static getDerivedStateFromError(t){return{error:t}}componentDidCatch(t){var r,n;(n=(r=this.props).onError)==null||n.call(r,t)}render(){return this.state.error?l.jsxs("div",{className:Ls.errorState,children:[l.jsx("h3",{children:"Something went wrong"}),l.jsx("p",{children:this.state.error.message}),l.jsx("button",{onClick:()=>this.setState({error:null}),children:"Retry"})]}):this.props.children}}function pI(e){const{isLoading:t,error:r}=dI({config:e,onError:e.onError}),n=ae(s=>s.editorMode);return t?l.jsxs("div",{className:Ls.loadingState,children:[l.jsx("div",{className:Ls.loadingSpinner}),l.jsx("p",{children:"Loading editor..."})]}):r?l.jsxs("div",{className:Ls.errorState,children:[l.jsx("h3",{children:"Failed to load editor"}),l.jsx("p",{children:r.message})]}):l.jsx("div",{className:`sb-split-builder ${Ls.root}`,children:l.jsx(oI,{editorMode:n,onToolbarEvent:e.onToolbarEvent,onContentAdded:e.onContentAdded,onHierarchySaved:e.onHierarchySaved})})}const Yh=e=>l.jsx(hI,{onError:e.onError,children:l.jsxs(Up,{client:fI,children:[l.jsx(pI,{...e}),l.jsx(Bg,{position:"top-right",toastOptions:{duration:3e3}})]})}),lo=Symbol.for("r2wc.reactRender"),Rh=Symbol.for("r2wc.shouldRender"),co=Symbol.for("r2wc.root");function gI(e=""){return e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}function yI(e=""){return e.replace(/-([a-z0-9])/g,function(t){return t[1].toUpperCase()})}var Xh={expando:function(e,t,r){Object.defineProperty(e,t,{enumerable:!0,get:function(){return r},set:function(n){r=n,this[lo]()}}),e[lo]()}};function vI(e,t,r,n={}){var s={isConnected:"isConnected"in HTMLElement.prototype},i=!1,o=function(){var d=Reflect.construct(HTMLElement,arguments,this.constructor);return typeof n.shadow=="string"?d.attachShadow({mode:n.shadow}):n.shadow&&(console.warn('Specifying the "shadow" option as a boolean is deprecated and will be removed in a future version.'),d.attachShadow({mode:"open"})),d},a=Object.create(HTMLElement.prototype);a.constructor=o;var c=new Proxy(a,{has:function(d,u){return u in e.propTypes||u in a},set:function(d,u,f,g){return i&&(s[u]=!0),typeof u=="symbol"||s[u]||u in d?(e.propTypes&&u in e.propTypes&&Xh.expando(g,u,f),Reflect.set(d,u,f,g)):(Xh.expando(g,u,f),!0)},getOwnPropertyDescriptor:function(d,u){var f=Reflect.getOwnPropertyDescriptor(d,u);if(f)return f;if(u in e.propTypes)return{configurable:!0,enumerable:!0,writable:!0,value:void 0}}});return o.prototype=c,a.connectedCallback=function(){this[Rh]=!0,this[lo]()},a.disconnectedCallback=function(){typeof r.createRoot=="function"?this[co].unmount():r.unmountComponentAtNode(this)},a[lo]=function(){if(this[Rh]===!0){var d={};Object.keys(this).forEach(function(g){s[g]!==!1&&(d[g]=this[g])},this),i=!0;const u=n.shadow?this.shadowRoot:this,f=t.createElement(e,d);typeof r.createRoot=="function"?(this[co]||(this[co]=r.createRoot(u)),this[co].render(f)):r.render(f,u),i=!1}},e.propTypes&&(o.observedAttributes=n.dashStyleAttributes?Object.keys(e.propTypes).map(function(d){return gI(d)}):Object.keys(e.propTypes),a.attributeChangedCallback=function(d,u,f){var g=n.dashStyleAttributes?yI(d):d;this[g]=f}),o}var Fs={},$s=Me;if(process.env.NODE_ENV==="production")Fs.createRoot=$s.createRoot,Fs.hydrateRoot=$s.hydrateRoot;else{var uo=$s.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;Fs.createRoot=function(e,t){uo.usingClientEntryPoint=!0;try{return $s.createRoot(e,t)}finally{uo.usingClientEntryPoint=!1}},Fs.hydrateRoot=function(e,t,r){uo.usingClientEntryPoint=!0;try{return $s.hydrateRoot(e,t,r)}finally{uo.usingClientEntryPoint=!1}}}function mI(){if(document.getElementById("sb-ce-react-styles"))return;const e=document.createElement("style");e.id="sb-ce-react-styles",e.textContent="@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');",document.head.insertBefore(e,document.head.firstChild)}function bI(e="sb-collection-editor"){if(mI(),typeof customElements>"u"||customElements.get(e))return;const t=vI(Yh,h,Fs,{});customElements.define(e,t)}ye.CollectionEditor=Yh,ye.registerCollectionEditor=bI,ye.setApiBaseUrl=Yu,ye.useEditorStore=ae,ye.useLibraryStore=Wh,ye.useTreeStore=xe,Object.defineProperty(ye,Symbol.toStringTag,{value:"Module"})});