@project-sunbird/collection-editor-react 0.1.15 → 0.1.16

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.
package/dist/index.cjs CHANGED
@@ -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 i0(e,t){if(e){if(typeof e=="string")return eu(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 eu(e,t)}}function eu(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 o0(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 a0(e){if(Array.isArray(e))return e}function l0(e,t,r){var n=an(),s=r0(e,t),i=XC(e);sn(function(){var a=pC(i,s,n),c=n0(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 c0(){var e=an();return p.useMemo(function(){return new rC(e)},[e])}function u0(e){var t=an(),r=p.useMemo(function(){return new hC(t.getBackend())},[t]);return sn(function(){return r.dropTargetOptions=e||null,r.reconnect(),function(){return r.disconnectDropTarget()}},[e]),r}function d0(e){return p.useMemo(function(){return e.hooks.dropTarget()},[e])}function oh(e,t){var r=nh(e,t),n=c0(),s=u0(r.options);return l0(r,n,s),[ih(r.collect,n,s),d0(s)]}function f0(e,t){return m0(e)||g0(e,t)||p0(e,t)||h0()}function h0(){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 p0(e,t){if(e){if(typeof e=="string")return tu(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 tu(e,t)}}function tu(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 g0(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 m0(e){if(Array.isArray(e))return e}function y0(e){var t=an(),r=t.getMonitor(),n=sh(r,e),s=f0(n,2),i=s[0],o=s[1];return p.useEffect(function(){return r.subscribeToOffsetChange(o)}),p.useEffect(function(){return r.subscribeToStateChange(o)}),i}function ah(e){var t=null,r=function(){return t==null&&(t=e()),t};return r}function v0(e,t){return e.filter(function(r){return r!==t})}function b0(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 _0(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function w0(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 x0(e,t,r){return t&&w0(e.prototype,t),e}function ru(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var S0=function(){function e(t){_0(this,e),ru(this,"entered",[]),ru(this,"isNodeInDocument",void 0),this.isNodeInDocument=t}return x0(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=b0(this.entered.filter(i),[r]),s===0&&this.entered.length>0}},{key:"leave",value:function(r){var n=this.entered.length;return this.entered=v0(this.entered.filter(this.isNodeInDocument),r),n>0&&this.entered.length===0}},{key:"reset",value:function(){this.entered=[]}}]),e}(),C0=ah(function(){return/firefox/i.test(navigator.userAgent)}),lh=ah(function(){return!!window.safari});function O0(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 D0(e,t,r){return t&&E0(e.prototype,t),e}function Xn(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var nu=function(){function e(t,r){O0(this,e),Xn(this,"xs",void 0),Xn(this,"ys",void 0),Xn(this,"c1s",void 0),Xn(this,"c2s",void 0),Xn(this,"c3s",void 0);for(var n=t.length,s=[],i=0;i<n;i++)s.push(i);s.sort(function(k,$){return t[k]<t[$]?-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]],m=0;m<o.length-1;m++){var g=a[m],_=a[m+1];if(g*_<=0)f.push(0);else{c=o[m];var h=o[m+1],y=c+h;f.push(3*y/((y+h)/g+(y+c)/_))}}f.push(a[a.length-1]);for(var v=[],b=[],x,w=0;w<f.length-1;w++){x=a[w];var C=f[w],D=1/o[w],j=C+f[w+1]-x-x;v.push((x-C-j)*D),b.push(j*D*D)}this.xs=t,this.ys=r,this.c1s=f,this.c2s=v,this.c3s=b}return D0(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 m=n[f];if(m<r)d=f+1;else if(m>r)u=f-1;else return s[f]}c=Math.max(0,u);var g=r-n[c],_=g*g;return s[c]+i[c]*g+o[c]*_+a[c]*g*_}}]),e}(),I0=1;function ch(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 Qs(e){return{x:e.clientX,y:e.clientY}}function N0(e){var t;return e.nodeName==="IMG"&&(C0()||!((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 lh()&&e&&(i/=window.devicePixelRatio,s/=window.devicePixelRatio),{dragPreviewWidth:s,dragPreviewHeight:i}}function j0(e,t,r,n,s){var i=N0(t),o=i?e:t,a=ch(o),c={x:r.x-a.x,y:r.y-a.y},d=e.offsetWidth,u=e.offsetHeight,f=n.anchorX,m=n.anchorY,g=T0(i,t,d,u),_=g.dragPreviewWidth,h=g.dragPreviewHeight,y=function(){var j=new nu([0,.5,1],[c.y,c.y/u*h,c.y+h-u]),k=j.interpolate(m);return lh()&&i&&(k+=(window.devicePixelRatio-1)*h),k},v=function(){var j=new nu([0,.5,1],[c.x,c.x/d*_,c.x+_-d]);return j.interpolate(f)},b=s.offsetX,x=s.offsetY,w=b===0||b,C=x===0||x;return{x:w?b:v(),y:C?x:y()}}var uh="__NATIVE_FILE__",dh="__NATIVE_URL__",fh="__NATIVE_TEXT__",hh="__NATIVE_HTML__";const su=Object.freeze(Object.defineProperty({__proto__:null,FILE:uh,HTML:hh,TEXT:fh,URL:dh},Symbol.toStringTag,{value:"Module"}));function Do(e,t,r){var n=t.reduce(function(s,i){return s||e.getData(i)},"");return n??r}var pn;function Gs(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var Ca=(pn={},Gs(pn,uh,{exposeProperties:{files:function(t){return Array.prototype.slice.call(t.files)},items:function(t){return t.items},dataTransfer:function(t){return t}},matchesTypes:["Files"]}),Gs(pn,hh,{exposeProperties:{html:function(t,r){return Do(t,r,"")},dataTransfer:function(t){return t}},matchesTypes:["Html","text/html"]}),Gs(pn,dh,{exposeProperties:{urls:function(t,r){return Do(t,r,"").split(`
465
465
  `)},dataTransfer:function(t){return t}},matchesTypes:["Url","text/uri-list"]}),Gs(pn,fh,{exposeProperties:{text:function(t,r){return Do(t,r,"")},dataTransfer:function(t){return t}},matchesTypes:["Text","text/plain"]}),pn);function R0(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function k0(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&&k0(e.prototype,t),e}function iu(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){R0(this,e),iu(this,"item",void 0),iu(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(Ca[e]);return r.loadDataTransfer(t),r}function Io(e){if(!e)return null;var t=Array.prototype.slice.call(e.types||[]);return Object.keys(Ca).filter(function(r){var n=Ca[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 No(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var B0=function(){function e(t,r){L0(this,e),No(this,"ownerDocument",null),No(this,"globalContext",void 0),No(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 ou(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 au(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?ou(Object(r),!0).forEach(function(n){ge(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ou(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}function U0(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function V0(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&&V0(e.prototype,t),e}function ge(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var q0=function(){function e(t,r,n){var s=this;U0(this,e),ge(this,"options",void 0),ge(this,"actions",void 0),ge(this,"monitor",void 0),ge(this,"registry",void 0),ge(this,"enterLeaveCounter",void 0),ge(this,"sourcePreviewNodes",new Map),ge(this,"sourcePreviewNodeOptions",new Map),ge(this,"sourceNodes",new Map),ge(this,"sourceNodeOptions",new Map),ge(this,"dragStartSourceIds",null),ge(this,"dropTargetIds",[]),ge(this,"dragEnterTargetIds",[]),ge(this,"currentNativeSource",null),ge(this,"currentNativeHandle",null),ge(this,"currentDragSourceNode",null),ge(this,"altKeyPressed",!1),ge(this,"mouseMoveTimeoutTimer",null),ge(this,"asyncEndDragFrameId",null),ge(this,"dragOverTargetIds",null),ge(this,"lastClientOffset",null),ge(this,"hoverRafId",null),ge(this,"getSourceClientOffset",function(i){var o=s.sourceNodes.get(i);return o&&ch(o)||null}),ge(this,"endDragNativeItem",function(){s.isDraggingNativeItem()&&(s.actions.endDrag(),s.currentNativeHandle&&s.registry.removeSource(s.currentNativeHandle),s.currentNativeHandle=null,s.currentNativeSource=null)}),ge(this,"isNodeInDocument",function(i){return!!(i&&s.document&&s.document.body&&s.document.body.contains(i))}),ge(this,"endDragIfSourceWasRemovedFromDOM",function(){var i=s.currentDragSourceNode;i==null||s.isNodeInDocument(i)||s.clearCurrentDragSourceNode()&&s.monitor.isDragging()&&s.actions.endDrag()}),ge(this,"handleTopDragStartCapture",function(){s.clearCurrentDragSourceNode(),s.dragStartSourceIds=[]}),ge(this,"handleTopDragStart",function(i){if(!i.defaultPrevented){var o=s.dragStartSourceIds;s.dragStartSourceIds=null;var a=Qs(i);s.monitor.isDragging()&&s.actions.endDrag(),s.actions.beginDrag(o||[],{publishSource:!1,getSourceClientOffset:s.getSourceClientOffset,clientOffset:a});var c=i.dataTransfer,d=Io(c);if(s.monitor.isDragging()){if(c&&typeof c.setDragImage=="function"){var u=s.monitor.getSourceId(),f=s.sourceNodes.get(u),m=s.sourcePreviewNodes.get(u)||f;if(m){var g=s.getCurrentSourcePreviewNodeOptions(),_=g.anchorX,h=g.anchorY,y=g.offsetX,v=g.offsetY,b={anchorX:_,anchorY:h},x={offsetX:y,offsetY:v},w=j0(f,m,a,b,x);c.setDragImage(m,w.x,w.y)}}try{c==null||c.setData("application/json",{})}catch{}s.setCurrentDragSourceNode(i.target);var C=s.getCurrentSourcePreviewNodeOptions(),D=C.captureDraggingState;D?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()}}}),ge(this,"handleTopDragEndCapture",function(){s.clearCurrentDragSourceNode()&&s.monitor.isDragging()&&s.actions.endDrag()}),ge(this,"handleTopDragEnterCapture",function(i){s.dragEnterTargetIds=[];var o=s.enterLeaveCounter.enter(i.target);if(!(!o||s.monitor.isDragging())){var a=i.dataTransfer,c=Io(a);c&&s.beginDragNativeItem(c,a)}}),ge(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:Qs(i)});var a=o.some(function(c){return s.monitor.canDropOnTarget(c)});a&&(i.preventDefault(),i.dataTransfer&&(i.dataTransfer.dropEffect=s.getCurrentDropEffect()))}}),ge(this,"handleTopDragOverCapture",function(){s.dragOverTargetIds=[]}),ge(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=Qs(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"))}),ge(this,"handleTopDragLeaveCapture",function(i){s.isDraggingNativeItem()&&i.preventDefault();var o=s.enterLeaveCounter.leave(i.target);o&&s.isDraggingNativeItem()&&setTimeout(function(){return s.endDragNativeItem()},0)}),ge(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 Io(i.dataTransfer)&&i.preventDefault();s.enterLeaveCounter.reset()}),ge(this,"handleTopDrop",function(i){var o=s.dropTargetIds;s.dropTargetIds=[],s.actions.hover(o,{clientOffset:Qs(i)}),s.actions.drop({dropEffect:s.getCurrentDropEffect()}),s.isDraggingNativeItem()?s.endDragNativeItem():s.monitor.isDragging()&&s.actions.endDrag()}),ge(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 B0(r,n),this.actions=t.getActions(),this.monitor=t.getMonitor(),this.registry=t.getRegistry(),this.enterLeaveCounter=new S0(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 au({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 au({anchorX:.5,anchorY:.5,captureDraggingState:!1},n||{})}},{key:"isDraggingNativeItem",value:function(){var r=this.monitor.getItemType();return Object.keys(su).some(function(n){return su[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}(),Ys;function H0(){return Ys||(Ys=new Image,Ys.src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="),Ys}var W0=function(t,r,n){return new q0(t,r,n)};function K0(e,t){return typeof e=="function"?e(t):e??"NODE"}function Q0(e){return e.isDraggable&&!e.isEditing}function G0(e){const t=It(),r=t.selectedIds,[n,s,i]=YC(()=>({canDrag:()=>Q0(e),type:K0(t.props.dragType,e),item:()=>{const o=t.isSelected(e.id)?Array.from(r):[e.id];return t.dispatch(Ln.dragStart(e.id,o)),{id:e.id,dragIds:o,data:e.data}},end:()=>{t.hideCursor(),t.redrawList(),t.dispatch(Ln.dragEnd())}}),[r,e,t.props.dragType]);return p.useEffect(()=>{i(H0())},[i]),s}function Y0(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 X0(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 Xs(e,t){return{parentId:e||null,index:t}}function gn(e,t){return{type:"line",index:e,level:t}}function Z0(e){return{type:"highlight",id:e}}function To(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=Ff(n)+1;return{parentId:s,index:i}}function ph(e){var t;const r=Y0(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]=X0(i,a,o,r);if(i&&i.isInternal&&r.inMiddle)return{drop:Xs(i.id,null),cursor:Z0(i.id)};if(!c)return{drop:Xs((t=d==null?void 0:d.parent)===null||t===void 0?void 0:t.id,0),cursor:gn(0,0)};if(Af(c)){const u=ui(s,(d==null?void 0:d.level)||0,c.level);return{drop:To(c,u),cursor:gn(c.rowIndex+1,u)}}if(Pf(c)){const u=ui(s,(d==null?void 0:d.level)||0,c.level);return{drop:To(c,u),cursor:gn(c.rowIndex+1,u)}}if(Mf(c)){const u=ui(s,0,c.level+1);return u>c.level?{drop:Xs(c.id,0),cursor:gn(c.rowIndex+1,u)}:{drop:To(c,u),cursor:gn(c.rowIndex+1,u)}}return{drop:Xs(c==null?void 0:c.id,0),cursor:gn(c.rowIndex+1,c.level+1)}}function J0(e,t){const r=It(),[n,s]=oh(()=>({accept:"NODE",canDrop:()=>r.canDrop(),hover:(i,o)=>{const a=o.getClientOffset();if(!e.current||!a)return;const{cursor:c,drop:d}=ph({element:e.current,offset:a,indent:r.indent,node:t,prevNode:t.prev,nextNode:t.next});d&&r.dispatch(Ln.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 e1(e){const t=It(),r=t.at(e);if(!r)throw new Error(`Could not find node for index: ${e}`);return p.useMemo(()=>{const n=r.clone();return t.visibleNodes[e]=n,n},[...Object.values(r.state),r])}const lu=p.memo(function({index:t,style:r}){kf(),vw();const n=It(),s=e1(t),i=p.useRef(null),o=G0(s),a=J0(i,s),c=p.useCallback(h=>{i.current=h,a(h)},[a]),d=n.indent*s.level,u=p.useMemo(()=>({paddingLeft:d}),[d]),f=p.useMemo(()=>{var h,y;return Object.assign(Object.assign({},r),{top:parseFloat(r.top)+((y=(h=n.props.padding)!==null&&h!==void 0?h:n.props.paddingTop)!==null&&y!==void 0?y:0),minWidth:"max-content"})},[r,n.props.padding,n.props.paddingTop]),m={role:"treeitem","aria-level":s.level+1,"aria-selected":s.isSelected,"aria-expanded":s.isOpen,style:f,tabIndex:-1,className:n.props.rowClassName};p.useEffect(()=>{var h;!s.isEditing&&s.isFocused&&((h=i.current)===null||h===void 0||h.focus({preventScroll:!0}))},[s.isEditing,s.isFocused,i.current]);const g=n.renderNode,_=n.renderRow;return l.jsx(_,{node:s,innerRef:c,attrs:m,children:l.jsx(g,{node:s,tree:n,style:u,dragHandle:o})})});let jo="",cu=null;function gh(){kf();const e=It();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(),$f(t.currentTarget);return}if(t.key==="Tab"&&t.shiftKey){t.preventDefault(),Bf(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(cu),jo+=t.key,cu=setTimeout(()=>{jo=""},600);const n=e.visibleNodes.find(s=>{const i=s.data.name;return typeof i=="string"?i.toLowerCase().startsWith(jo):!1});n&&e.focus(n.id)},children:l.jsx(t1,{})})}function t1(){var e,t;const r=It(),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:ox,innerElementType:(t=r.props.innerElementType)!==null&&t!==void 0?t:cx,onScroll:r.props.onScroll,onItemsRendered:r.onItemsRendered.bind(r)};return typeof r.props.rowHeight=="function"?l.jsx(rx,Object.assign({},n,{itemSize:r.rowHeightAt,ref:r.list,children:lu})):l.jsx(nx,Object.assign({},n,{itemSize:r.rowHeight,ref:r.list,children:lu}))}function uu(e){return e.isFiltered?n1(e.root,e.isMatch.bind(e)):r1(e.root)}function r1(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(mh),t}function n1(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(mh),n}function mh(e,t){e.rowIndex=t}const du=e=>e.reduce((t,r,n)=>(t[r.id]=n,t),{});var Ro=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:ft}=Sw;class ds{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=bc(this),this.visibleNodes=uu(this),this.idToIndex=du(this.visibleNodes)}update(t){this.props=t,this.root=bc(this),this.visibleNodes=uu(this),this.idToIndex=du(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=is(t,n))!==null&&r!==void 0?r:null}accessId(t){const r=this.props.idAccessor||"id",n=is(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 ws)return t.id;const r=this.props.idAccessor||"id";return is(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 Ro(this,arguments,void 0,function*(t={}){var r,n;const s=t.parentId===void 0?qf(this):t.parentId,i=(r=t.index)!==null&&r!==void 0?r:zf(this),o=(n=t.type)!==null&&n!==void 0?n:"leaf",a=yield ft(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 Ro(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 ft(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(_o(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=>{ds.editPromise=i})}submit(t,r){return Ro(this,void 0,void 0,function*(){var n,s;if(!t)return;const i=this.identify(t);yield ft(this.props.onRename,{id:i,name:r,node:this.get(i)}),this.dispatch(_o(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(_o(null)),this.resolveEdit({cancelled:!0}),this.redrawList(),setTimeout(()=>this.onFocus())}activate(t){const r=this.get(this.identifyNull(t));r&&ft(this.props.onActivate,r)}resolveEdit(t){const r=ds.editPromise;r&&r(t),ds.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(un(this.identify(t))),r.scroll!==!1&&this.scrollTo(t),this.focusedNode&&ft(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(un(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&&ft(this.props.onFocus,this.focusedNode)}deselect(t){if(!t)return;const r=this.identify(t);this.dispatch(vr.remove(r)),ft(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(un(n.id)),n.isSelectable&&(this.dispatch(vr.add(n.id)),this.dispatch(vr.anchor(n.id)),this.dispatch(vr.mostRecent(n.id))),this.scrollTo(n,r.align),this.focusedNode&&s&&ft(this.props.onFocus,this.focusedNode),ft(this.props.onSelect,this.selectedNodes)}selectContiguous(t){var r;if(!t)return;const n=this.identify(t);if(this.dispatch(un(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(vr.remove(this.nodesBetween(s,i))),this.dispatch(vr.add(o)),this.dispatch(vr.mostRecent(n))}this.scrollTo(n),this.focusedNode&&ft(this.props.onFocus,this.focusedNode),ft(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(un((n=this.lastNode)===null||n===void 0?void 0:n.id)),this.focusedNode&&ft(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(vr.set({ids:n,anchor:s,mostRecent:i})),ft(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&&Lf(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;ft(this.props.onMove,{dragIds:n,parentId:t===_s?null:t,index:r===null?0:r,dragNodes:this.dragNodes,parentNode:this.get(t)}),this.open(t)}hideCursor(){this.dispatch(Ln.cursor({type:"none"}))}showCursor(t){this.dispatch(Ln.cursor(t))}open(t,r=!0){var n,s;const i=this.identifyNull(t);i&&(this.isOpen(i)||(this.dispatch(ma.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),ft(this.props.onToggle,i)))}close(t,r=!0){var n,s;const i=this.identifyNull(t);i&&this.isOpen(i)&&(this.dispatch(ma.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),ft(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=nl(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(){Ti(this.root,t=>{t.isInternal&&this.open(t.id,!1)}),this.redrawList()}closeAll(){Ti(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),Vf(()=>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===_s)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!is(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(un(t.id))}onBlur(){this.dispatch(kw())}onItemsRendered(t){this.visibleStartIndex=t.visibleStartIndex,this.visibleStopIndex=t.visibleStopIndex}get renderContainer(){return this.props.renderContainer||gh}get renderRow(){return this.props.renderRow||Iw}get renderNode(){return this.props.children||Nw}get renderDragPreview(){return this.props.renderDragPreview||Hf}get renderCursor(){return this.props.renderCursor||Dw}}function ht(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 s1=typeof Symbol=="function"&&Symbol.observable||"@@observable",fu=s1,ko=()=>Math.random().toString(36).substring(7).split("").join("."),i1={INIT:`@@redux/INIT${ko()}`,REPLACE:`@@redux/REPLACE${ko()}`,PROBE_UNKNOWN_ACTION:()=>`@@redux/PROBE_UNKNOWN_ACTION${ko()}`},tn=i1;function yh(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 o1(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(c1(e))return"date";if(l1(e))return"error";const r=a1(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 a1(e){return typeof e.constructor=="function"?e.constructor.name:null}function l1(e){return e instanceof Error||typeof e.message=="string"&&e.constructor&&typeof e.constructor.stackTraceLimit=="number"}function c1(e){return e instanceof Date?!0:typeof e.toDateString=="function"&&typeof e.getDate=="function"&&typeof e.setDate=="function"}function wr(e){let t=typeof e;return process.env.NODE_ENV!=="production"&&(t=o1(e)),t}function vh(e,t,r){if(typeof e!="function")throw new Error(process.env.NODE_ENV==="production"?ht(2):`Expected the root reducer to be a function. Instead, received: '${wr(e)}'`);if(typeof t=="function"&&typeof r=="function"||typeof r=="function"&&typeof arguments[3]=="function")throw new Error(process.env.NODE_ENV==="production"?ht(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"?ht(1):`Expected the enhancer to be a function. Instead, received: '${wr(r)}'`);return r(vh)(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((y,v)=>{o.set(v,y)}))}function u(){if(c)throw new Error(process.env.NODE_ENV==="production"?ht(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(y){if(typeof y!="function")throw new Error(process.env.NODE_ENV==="production"?ht(4):`Expected the listener to be a function. Instead, received: '${wr(y)}'`);if(c)throw new Error(process.env.NODE_ENV==="production"?ht(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 v=!0;d();const b=a++;return o.set(b,y),function(){if(v){if(c)throw new Error(process.env.NODE_ENV==="production"?ht(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.");v=!1,d(),o.delete(b),i=null}}}function m(y){if(!yh(y))throw new Error(process.env.NODE_ENV==="production"?ht(7):`Actions must be plain objects. Instead, the actual type was: '${wr(y)}'. 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 y.type>"u")throw new Error(process.env.NODE_ENV==="production"?ht(8):'Actions may not have an undefined "type" property. You may have misspelled an action type string constant.');if(typeof y.type!="string")throw new Error(process.env.NODE_ENV==="production"?ht(17):`Action "type" property must be a string. Instead, the actual type was: '${wr(y.type)}'. Value was: '${y.type}' (stringified)`);if(c)throw new Error(process.env.NODE_ENV==="production"?ht(9):"Reducers may not dispatch actions.");try{c=!0,s=n(s,y)}finally{c=!1}return(i=o).forEach(b=>{b()}),y}function g(y){if(typeof y!="function")throw new Error(process.env.NODE_ENV==="production"?ht(10):`Expected the nextReducer to be a function. Instead, received: '${wr(y)}`);n=y,m({type:tn.REPLACE})}function _(){const y=f;return{subscribe(v){if(typeof v!="object"||v===null)throw new Error(process.env.NODE_ENV==="production"?ht(11):`Expected the observer to be an object. Instead, received: '${wr(v)}'`);function b(){const w=v;w.next&&w.next(u())}return b(),{unsubscribe:y(b)}},[fu](){return this}}}return m({type:tn.INIT}),{dispatch:m,subscribe:f,getState:u,replaceReducer:g,[fu]:_}}function hu(e){typeof console<"u"&&typeof console.error=="function"&&console.error(e);try{throw new Error(e)}catch{}}function u1(e,t,r,n){const s=Object.keys(t),i=r&&r.type===tn.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(!yh(e))return`The ${i} has unexpected type of "${wr(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===tn.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 d1(e){Object.keys(e).forEach(t=>{const r=e[t];if(typeof r(void 0,{type:tn.INIT})>"u")throw new Error(process.env.NODE_ENV==="production"?ht(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:tn.PROBE_UNKNOWN_ACTION()})>"u")throw new Error(process.env.NODE_ENV==="production"?ht(13):`The slice reducer for key "${t}" returned undefined when probed with a random type. Don't try to handle '${tn.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 pu(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"&&hu(`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{d1(r)}catch(o){i=o}return function(a={},c){if(i)throw i;if(process.env.NODE_ENV!=="production"){const f=u1(a,r,c,s);f&&hu(f)}let d=!1;const u={};for(let f=0;f<n.length;f++){const m=n[f],g=r[m],_=a[m],h=g(_,c);if(typeof h>"u"){const y=c&&c.type;throw new Error(process.env.NODE_ENV==="production"?ht(14):`When called with an action of type ${y?`"${String(y)}"`:"(unknown type)"}, the slice reducer for key "${m}" 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[m]=h,d=d||h!==_}return d=d||n.length!==Object.keys(a).length,d?u:a}}function f1(e=Mn().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 h1=pu({nodes:pu({focus:Aw,edit:Rw,open:Pw,selection:Mw,drag:f1}),dnd:Lw}),p1=Mn();function g1({treeProps:e,imperativeHandle:t,children:r}){const n=p.useRef(null),s=p.useRef(null),i=p.useRef(vh(h1,Mn(e))),o=yw.useSyncExternalStore(i.current.subscribe,i.current.getState,()=>p1),a=p.useMemo(()=>new ds(i.current,e,n,s),[]),c=p.useRef(0);return p.useMemo(()=>{c.current+=1,a.update(e)},Object.values(e)),p.useMemo(()=>{c.current+=1,a.update(a.props)},[o.nodes.open]),p.useImperativeHandle(t,()=>a),p.useEffect(()=>{a.props.selection?a.select(a.props.selection,{focus:!1}):a.deselectAll()},[a.props.selection]),p.useEffect(()=>{a.props.searchTerm||i.current.dispatch(ma.clear(!0))},[a.props.searchTerm]),l.jsx(Nf.Provider,{value:a,children:l.jsx(Rf.Provider,{value:c.current,children:l.jsx(Tf.Provider,{value:o.nodes,children:l.jsx(jf.Provider,{value:o.dnd,children:l.jsx(WS,Object.assign({},e.dndManager?{manager:e.dndManager}:{backend:e.dndBackend||W0,options:{rootElement:a.props.dndRootElement||void 0}},{children:r}))})})})})}function m1(){const e=It(),[,t]=oh(()=>({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}=ph({element:e.listEl.current,offset:s,indent:e.indent,node:null,prevNode:e.visibleNodes[e.visibleNodes.length-1],nextNode:null});o&&e.dispatch(Ln.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 y1(e){return m1(),e.children}function v1(){const t=It().props.renderContainer||gh;return l.jsx(l.Fragment,{children:l.jsx(t,{})})}function b1(){const e=It(),{offset:t,mouse:r,item:n,isDragging:s}=y0(o=>({offset:o.getSourceClientOffset(),mouse:o.getClientOffset(),item:o.getItem(),isDragging:o.isDragging()})),i=e.props.renderDragPreview||Hf;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 _1(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 w1{constructor(t,r={}){this.accessors=_1(r),this.root=x1(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 x1(e,t){const r=new bh({},null,t,"ROOT");return r.children=e.map(n=>ul(n,r,t)),r}function ul(e,t,r){const n=new bh(e,t,r),s=r.getChildren(e);return s&&(n.children=s.map(i=>ul(i,n,r))),n}class bh{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=ul(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 S1=0;function C1(e,t={}){const[r,n]=p.useState(e),s=t.idAccessor,i=t.childrenAccessor,o=p.useMemo(()=>new w1(r,{idAccessor:s,childrenAccessor:i}),[r,s,i]),a=_=>{for(const h of _.dragIds)o.move({id:h,parentId:_.parentId,index:_.index});n(o.data)},c=({name:_,id:h})=>{o.update({id:h,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:h,type:y})=>{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(y==="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 v={[d]:`simple-tree-id-${S1++}`,name:""};return y==="internal"&&(v[u]=[]),o.create({parentId:_,index:h,data:v}),n(o.data),v},onDelete:_=>{_.ids.forEach(h=>o.drop({id:h})),n(o.data)}}]}function O1(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]=C1(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=O1(e);return l.jsxs(g1,{treeProps:r,imperativeHandle:t,children:[l.jsx(y1,{children:l.jsx(v1,{})}),l.jsx(b1,{})]})}const D1=p.forwardRef(E1);function dl(){return Re(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 Re(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 gu={video:"#EA580C",pdf:"#DC2626",h5p:"#0D9488",scorm:"#7C3AED",audio:"#DB2777",quiz:"#16A34A",default:"#6B7280"},mu={video:"Video",pdf:"FileText",h5p:"Layers",scorm:"Package",audio:"Music",quiz:"HelpCircle",default:"File"},yu=["Course Assessment","eTextbook","Exam Question","Explanation Content","Learning Resource","Practice Question Set","SCORM Content","Teacher Resource"],N1=[{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 eo(e){const t=T1(e);return{key:t,color:gu[t]??gu.default,bgClass:`sbx-ct-sq--${t}`,badgeClass:`sbx-ct-badge--${t}`,tintClass:`sbx-ct-tint--${t}`,iconName:mu[t]??mu.default,label:t.charAt(0).toUpperCase()+t.slice(1)}}const j1="_row_i3qt2_1",R1="_grip_i3qt2_16",k1="_menuBtn_i3qt2_19",A1="_selected_i3qt2_23",P1="_title_i3qt2_28",M1="_dropTarget_i3qt2_33",L1="_toggle_i3qt2_50",F1="_ctIcon_i3qt2_65",$1="_folderIcon_i3qt2_77",B1="_renameInput_i3qt2_92",U1="_dropHere_i3qt2_101",V1="_menuWrap_i3qt2_111",z1="_menu_i3qt2_19",q1="_dangerItem_i3qt2_163",Ct={row:j1,grip:R1,menuBtn:k1,selected:A1,title:P1,dropTarget:M1,toggle:L1,ctIcon:F1,folderIcon:$1,renameInput:B1,dropHere:U1,menuWrap:V1,menu:z1,dangerItem:q1},H1={video:Qa,pdf:za,h5p:qa,scorm:Wa,audio:Ha,quiz:Va,default:Vn},W1=({node:e,style:t,dragHandle:r,editorMode:n})=>{const[s,i]=p.useState(!1),[o,a]=p.useState(!1),[c,d]=p.useState(e.data.name),u=p.useRef(null),f=n==="edit",m=dl(),g=eo(e.data),_=H1[g.key]??Vn,h=e.isSelected,y=e.level===0,v=e.data.isFolder??(e.children&&e.children.length>0),b=y?sy:v?cy:_;p.useEffect(()=>{if(!s)return;const C=D=>{var j;(j=u.current)!=null&&j.contains(D.target)||i(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[s]);const x=p.useCallback(()=>{c.trim()&&e.submit(c.trim()),a(!1)},[c,e]),w=p.useCallback(C=>{C.key==="Enter"&&x(),C.key==="Escape"&&(d(e.data.name),a(!1))},[x,e.data.name]);return l.jsxs("div",{className:[Ct.row,h?Ct.selected:"",e.state.isOver&&v?Ct.dropTarget:""].filter(Boolean).join(" "),style:t,onClick:()=>e.select(),"data-node-id":e.data.id,"data-droppable":v?"true":void 0,role:"treeitem","aria-selected":h,"aria-expanded":v?!e.isClosed:void 0,children:[f&&l.jsx("span",{ref:r,className:Ct.grip,"aria-hidden":"true",children:l.jsx(Hd,{size:14})}),l.jsx("button",{className:Ct.toggle,onClick:C=>{C.stopPropagation(),e.toggle()},"aria-label":e.isClosed?"Expand":"Collapse",style:{visibility:v?"visible":"hidden"},children:e.isClosed?l.jsx(Ud,{size:14}):l.jsx(ks,{size:14})}),l.jsx("span",{className:`${Ct.ctIcon} ${y||v?Ct.folderIcon:g.bgClass}`,"aria-hidden":"true",children:l.jsx(b,{size:12})}),o?l.jsx("input",{className:Ct.renameInput,value:c,autoFocus:!0,onChange:C=>d(C.target.value),onBlur:x,onKeyDown:w,onClick:C=>C.stopPropagation()}):l.jsx("span",{className:Ct.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&&v&&l.jsx("span",{className:Ct.dropHere,"aria-hidden":"true",children:"Drop here"}),f&&l.jsxs("div",{className:Ct.menuWrap,ref:u,children:[l.jsx("button",{className:Ct.menuBtn,onClick:C=>{C.stopPropagation(),i(D=>!D)},"aria-label":"Node options",children:l.jsx(zd,{size:14})}),s&&l.jsxs("div",{className:Ct.menu,role:"menu",children:[l.jsxs("button",{role:"menuitem",onClick:()=>{a(!0),i(!1)},children:[l.jsx(gy,{size:13})," Rename"]}),v&&m&&l.jsxs("button",{role:"menuitem",onClick:()=>{e.tree.create({parentId:e.id}),i(!1)},children:[l.jsx(qd,{size:13})," Add sub-unit"]}),e.data.parent&&m&&l.jsxs("button",{role:"menuitem",onClick:()=>{e.tree.create({parentId:e.data.parent}),i(!1)},children:[l.jsx(As,{size:13})," Add Sibling"]}),l.jsxs("button",{role:"menuitem",className:Ct.dangerItem,onClick:()=>{e.tree.delete(e.id),i(!1)},children:[l.jsx(Ka,{size:13})," Delete"]})]})]})]})};async function K1(e,t){var i,o;const n=((i=(await Me.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 Q1(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 G1(e,t){var a;const r=await K1(e,t.name),n=await Q1(r,t),s=new FormData;return s.append("fileUrl",n),s.append("mimeType",t.type||"text/csv"),{processId:(((a=(await Me.post(`/action/collection/v1/import/${e}`,s)).data)==null?void 0:a.result)??{}).processId??""}}async function Y1(e){var r;return((r=(await Me.get(`/action/collection/v1/import/status/${e}`)).data)==null?void 0:r.result)??{status:"PENDING"}}async function _h(e){var n,s,i;const r=(i=(s=(n=(await Me.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 X1(e){return _h(e)}const Z1="_container_jr3ij_1",J1="_header_jr3ij_13",eO="_title_jr3ij_22",tO="_closeBtn_jr3ij_29",rO="_body_jr3ij_45",nO="_dropZone_jr3ij_54",sO="_dragOver_jr3ij_67",iO="_hasFile_jr3ij_72",oO="_hiddenInput_jr3ij_78",aO="_fileInfo_jr3ij_82",lO="_fileIcon_jr3ij_89",cO="_fileName_jr3ij_93",uO="_fileSize_jr3ij_100",dO="_dropHint_jr3ij_105",fO="_dropIcon_jr3ij_112",hO="_dropText_jr3ij_117",pO="_dropSubtext_jr3ij_124",gO="_sampleLink_jr3ij_130",mO="_statusBar_jr3ij_145",yO="_status_uploading_jr3ij_154",vO="_status_processing_jr3ij_154",bO="_status_done_jr3ij_159",_O="_status_error_jr3ij_164",wO="_successDetail_jr3ij_170",xO="_spinner_jr3ij_175",SO="_spin_jr3ij_175",CO="_errorMsg_jr3ij_191",OO="_failedSection_jr3ij_197",EO="_failedTitle_jr3ij_203",DO="_tableWrap_jr3ij_213",IO="_failedTable_jr3ij_219",NO="_reasonCell_jr3ij_244",TO="_footer_jr3ij_248",Ee={container:Z1,header:J1,title:eO,closeBtn:tO,body:rO,dropZone:nO,dragOver:sO,hasFile:iO,hiddenInput:oO,fileInfo:aO,fileIcon:lO,fileName:cO,fileSize:uO,dropHint:dO,dropIcon:fO,dropText:hO,dropSubtext:pO,sampleLink:gO,statusBar:mO,status_uploading:yO,status_processing:vO,status_done:bO,status_error:_O,successDetail:wO,spinner:xO,spin:SO,errorMsg:CO,failedSection:OO,failedTitle:EO,tableWrap:DO,failedTable:IO,reasonCell:NO,footer:TO},jO=({contentId:e,onComplete:t,onClose:r,mode:n="create"})=>{const[s,i]=p.useState(null),[o,a]=p.useState(!1),[c,d]=p.useState("idle"),[u,f]=p.useState(""),[m,g]=p.useState([]),[_,h]=p.useState(null),y=p.useRef(null),v=p.useRef(null),b=p.useCallback(()=>{v.current!==null&&(clearInterval(v.current),v.current=null)},[]);p.useEffect(()=>()=>b(),[b]);const x=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=p.useCallback(N=>{f(""),g([]),h(null),d("idle"),x(N)&&i(N)},[]),C=p.useCallback(N=>{N.preventDefault(),a(!1);const A=N.dataTransfer.files[0];A&&w(A)},[w]),D=p.useCallback(N=>{var U;const A=(U=N.target.files)==null?void 0:U[0];A&&w(A),N.target.value=""},[w]),j=p.useCallback(async()=>{try{const N=await X1(e),A=document.createElement("a");A.href=N,A.download="sample_hierarchy.csv",A.target="_blank",A.click()}catch{f("Failed to download sample CSV.")}},[e]),k=p.useCallback(async()=>{if(s){d("uploading"),f(""),g([]);try{const{processId:N}=await G1(e,s);if(!N){d("done"),h(null),setTimeout(t,1500);return}d("processing"),v.current=setInterval(async()=>{try{const A=await Y1(N);A.status==="COMPLETED"?(b(),d("done"),h(A.successCount??null),A.failedRecords&&A.failedRecords.length>0?g(A.failedRecords):setTimeout(t,1500)):A.status==="FAILED"&&(b(),d("error"),f("Upload processing failed. Please check the error rows below."),A.failedRecords&&g(A.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]),$={idle:"",uploading:"Uploading...",processing:"Processing...",done:"Done!",error:"Error"};return l.jsxs("div",{className:Ee.container,children:[l.jsxs("div",{className:Ee.header,children:[l.jsx("h2",{className:Ee.title,children:n==="update"?"Update Folder Metadata via CSV":"Create Folders via CSV"}),l.jsx("button",{className:Ee.closeBtn,onClick:r,"aria-label":"Close",children:"✕"})]}),l.jsxs("div",{className:Ee.body,children:[l.jsxs("div",{className:`${Ee.dropZone} ${o?Ee.dragOver:""} ${s?Ee.hasFile:""}`,onDragEnter:N=>{N.preventDefault(),a(!0)},onDragOver:N=>{N.preventDefault(),a(!0)},onDragLeave:N=>{N.preventDefault(),a(!1)},onDrop:C,onClick:()=>{var N;return(N=y.current)==null?void 0:N.click()},role:"button",tabIndex:0,"aria-label":"Drop CSV file here or click to browse",onKeyDown:N=>{var A;return N.key==="Enter"&&((A=y.current)==null?void 0:A.click())},children:[l.jsx("input",{ref:y,type:"file",accept:".csv",className:Ee.hiddenInput,onChange:D,"aria-hidden":"true"}),s?l.jsxs("div",{className:Ee.fileInfo,children:[l.jsx("span",{className:Ee.fileIcon,children:"📄"}),l.jsx("span",{className:Ee.fileName,children:s.name}),l.jsxs("span",{className:Ee.fileSize,children:["(",(s.size/1024).toFixed(1)," KB)"]})]}):l.jsxs("div",{className:Ee.dropHint,children:[l.jsx("span",{className:Ee.dropIcon,children:"⬆️"}),l.jsx("p",{className:Ee.dropText,children:"Drag & drop your CSV here"}),l.jsx("p",{className:Ee.dropSubtext,children:"or click to browse"})]})]}),l.jsx("button",{className:Ee.sampleLink,onClick:j,type:"button",children:"Download Sample CSV"}),c!=="idle"&&l.jsxs("div",{className:`${Ee.statusBar} ${Ee[`status_${c}`]}`,role:"status","aria-live":"polite",children:[c==="processing"&&l.jsx("span",{className:Ee.spinner,"aria-hidden":"true"}),$[c],c==="done"&&_!==null&&l.jsxs("span",{className:Ee.successDetail,children:[" — ",_," item(s) imported"]})]}),u&&l.jsx("p",{className:Ee.errorMsg,role:"alert",children:u}),m.length>0&&l.jsxs("div",{className:Ee.failedSection,children:[l.jsxs("h4",{className:Ee.failedTitle,children:["Failed Rows (",m.length,")"]}),l.jsx("div",{className:Ee.tableWrap,children:l.jsxs("table",{className:Ee.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:m.map((N,A)=>l.jsxs("tr",{children:[l.jsx("td",{children:N.rowNumber??A+1}),l.jsx("td",{children:N.name??"—"}),l.jsx("td",{className:Ee.reasonCell,children:N.reason??"Unknown error"})]},A))})]})})]})]}),l.jsxs("div",{className:Ee.footer,children:[l.jsx(Ie,{variant:"ghost",onClick:r,disabled:c==="uploading"||c==="processing",children:"Cancel"}),l.jsx(Ie,{variant:"primary",isLoading:c==="uploading"||c==="processing",disabled:!s||c==="done",onClick:k,children:c==="done"?"Uploaded":"Upload"})]})]})},RO="_container_1y30m_1",kO="_header_1y30m_8",AO="_headerActions_1y30m_19",PO="_iconBtn_1y30m_25",MO="_menuWrap_1y30m_43",LO="_dropdownMenu_1y30m_47",FO="_treeWrapper_1y30m_79",$O="_csvModal_1y30m_95",BO="_footer_1y30m_105",er={container:RO,header:kO,headerActions:AO,iconBtn:PO,menuWrap:MO,dropdownMenu:LO,treeWrapper:FO,csvModal:$O,footer:BO},UO=({editorMode:e,collapsed:t=!1,onToggleCollapse:r})=>{var be;const n=p.useRef(null),s=p.useRef(null),i=p.useRef(null),[o,a]=p.useState(400),[c,d]=p.useState(!1),[u,f]=p.useState(!1),[m,g]=p.useState("create"),{treeData:_,selectedNodeId:h,selectNode:y,addNode:v,deleteNode:b,reorderChildren:x,moveNode:w,setTreeData:C}=Re(),D=e==="edit",j=dl(),k=D&&j,$=(((be=_[0])==null?void 0:be.children)??[]).some(K=>K.isFolder),N=ue(K=>{var M,G,P,Y;return((G=(M=K.editorConfig)==null?void 0:M.context)==null?void 0:G.contentId)??((Y=(P=K.editorConfig)==null?void 0:P.context)==null?void 0:Y.identifier)??""}),A=ue(K=>{var G,P;const M=(P=(G=K.categoryMeta)==null?void 0:G.sourcingSettings)==null?void 0:P.collection;return(M==null?void 0:M.enableBulkUpload)!==!1});p.useEffect(()=>{const K=s.current;if(!K)return;const M=new ResizeObserver(()=>{a(K.clientHeight||400)});return M.observe(K),a(K.clientHeight||400),()=>M.disconnect()},[]),p.useEffect(()=>{if(!c)return;const K=M=>{var G;(G=i.current)!=null&&G.contains(M.target)||d(!1)};return document.addEventListener("mousedown",K),()=>document.removeEventListener("mousedown",K)},[c]);const U=p.useCallback(K=>{K.length>0&&y(K[0].data.id)},[y]),R=p.useCallback(({parentId:K,index:M,dragIds:G})=>{if(!K)return;const P=G[0],Y=Oa(_,P);if(!Y)return;const W=Y.parent;if(W===K){const oe=Oa(_,K);if(!(oe!=null&&oe.children))return;const pe=oe.children.findIndex(Ne=>Ne.id===P);if(pe<0)return;x(K,pe,M>pe?M-1:M)}else w(P,W??"",K)},[_,x,w]),B=p.useCallback(({ids:K})=>{K.forEach(M=>b(M))},[b]),F=p.useCallback(({parentId:K})=>{var P;const M=K??((P=_[0])==null?void 0:P.id)??"";if(!M)return{id:crypto.randomUUID()};const G=v(M,"unit");return G?{id:G}:(Se.error("Maximum depth reached"),{id:crypto.randomUUID()})},[v,_]),J=p.useCallback(()=>{var M;const K=(M=_[0])==null?void 0:M.id;K&&(v(K,"unit")||Se.error("Maximum depth reached"))},[_,v]),ie=p.useCallback(()=>{h&&(v(h,"subunit")||Se.error("Maximum depth reached"))},[h,v]),me=p.useCallback(async()=>{if(d(!1),!!N)try{const K=await _h(N),M=await fetch(K).then(Y=>Y.blob()),G=URL.createObjectURL(M),P=document.createElement("a");P.href=G,P.download=`${N}-folders.csv`,P.style.display="none",document.body.appendChild(P),P.click(),document.body.removeChild(P),URL.revokeObjectURL(G)}catch{Se.error("Failed to download CSV")}},[N]),ve=p.useCallback(async()=>{if(f(!1),!!N)try{const{rootNode:K}=await If(N);C([K]),Se.success("Course outline refreshed.")}catch{Se.error("Outline could not be refreshed automatically. Please reload the page.")}},[N,C]);return l.jsxs("div",{className:er.container,children:[l.jsx("div",{className:er.header,children:l.jsxs("div",{className:er.headerActions,children:[D&&l.jsxs("div",{className:er.menuWrap,ref:i,children:[l.jsx("button",{type:"button",className:er.iconBtn,onClick:()=>d(K=>!K),"aria-label":"More options",title:"More options","aria-haspopup":"true","aria-expanded":c,children:l.jsx(zd,{size:15})}),c&&l.jsx("div",{className:er.dropdownMenu,role:"menu",children:A&&l.jsxs(l.Fragment,{children:[l.jsx("button",{role:"menuitem",type:"button",disabled:$,title:$?'Folders already exist — use "Update" instead':void 0,onClick:()=>{d(!1),g("create"),f(!0)},children:"Create folders using csv file"}),l.jsx("button",{role:"menuitem",type:"button",disabled:!$,title:$?void 0:'No folders yet — use "Create" first',onClick:me,children:"Download folders as csv file"}),l.jsx("button",{role:"menuitem",type:"button",disabled:!$,title:$?void 0:'No folders yet — use "Create" first',onClick:()=>{d(!1),g("update"),f(!0)},children:"Update folder metadata using csv file"})]})})]}),r&&l.jsx("button",{type:"button",className:er.iconBtn,onClick:r,"aria-label":t?"Expand outline":"Collapse outline",title:t?"Expand outline":"Collapse outline",children:t?l.jsx(hy,{size:15}):l.jsx(fy,{size:15})})]})}),l.jsx("div",{className:er.treeWrapper,ref:s,children:l.jsx(D1,{ref:n,data:_,idAccessor:"id",childrenAccessor:"children",onSelect:U,onMove:D?R:void 0,onDelete:D?B:void 0,onCreate:D?F:void 0,disableEdit:!D,disableDrop:!D,selection:h??void 0,rowHeight:40,indent:20,paddingBottom:16,height:o,width:"100%",children:K=>l.jsx(W1,{...K,editorMode:e})})}),D&&l.jsxs("div",{className:er.footer,children:[l.jsxs(Ie,{variant:"ghost",size:"sm",onClick:J,disabled:!k,children:[l.jsx(As,{size:14})," Add Unit"]}),l.jsxs(Ie,{variant:"ghost",size:"sm",onClick:ie,disabled:!k||!h,children:[l.jsx(qd,{size:14})," Add Sub-unit"]})]}),u&&l.jsx("div",{className:er.csvModal,children:l.jsx(jO,{contentId:N,mode:m,onComplete:ve,onClose:()=>f(!1)})})]})};function Oa(e,t){for(const r of e){if(r.id===t)return r;if(r.children){const n=Oa(r.children,t);if(n)return n}}}const VO="_breadcrumb_zd1aj_1",zO="_crumb_zd1aj_10",qO="_sep_zd1aj_26",HO="_current_zd1aj_31",Zn={breadcrumb:VO,crumb:zO,sep:qO,current:HO},WO=({crumbs:e})=>{const t=Re(r=>r.selectNode);return e.length?l.jsxs("nav",{className:Zn.breadcrumb,"aria-label":"Node path",children:[l.jsx("button",{className:Zn.crumb,onClick:()=>t(e[0].id),"aria-label":"Home",children:l.jsx(uy,{size:13})}),e.map((r,n)=>l.jsxs(p.Fragment,{children:[l.jsx(Ud,{size:13,className:Zn.sep}),n<e.length-1?l.jsx("button",{className:Zn.crumb,onClick:()=>t(r.id),children:r.name}):l.jsx("span",{className:Zn.current,children:r.name})]},r.id))]}):null},KO="_tabBar_qhks1_1",QO="_tab_qhks1_1",GO="_active_qhks1_29",YO="_error_qhks1_35",XO="_errorDot_qhks1_39",Jn={tabBar:KO,tab:QO,active:GO,error:YO,errorDot:XO},vu=[{id:"details",label:"Details"},{id:"audience",label:"Audience & Curriculum"},{id:"licensing",label:"Licensing"}],ZO=({activeTab:e,onChange:t,errorTabs:r=[],visibleTabs:n})=>{const s=n?vu.filter(i=>n.includes(i.id)):vu;return l.jsx("div",{className:Jn.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:[Jn.tab,e===i.id?Jn.active:"",r.includes(i.id)?Jn.error:""].join(" "),onClick:()=>t(i.id),children:[i.label,r.includes(i.id)&&l.jsx("span",{className:Jn.errorDot,"aria-label":"Has errors"})]},i.id))})};var $s=e=>e.type==="checkbox",zr=e=>e instanceof Date,st=e=>e==null;const wh=e=>typeof e=="object";var Be=e=>!st(e)&&!Array.isArray(e)&&wh(e)&&!zr(e),Ea=e=>Be(e)&&e.target?$s(e.target)?e.target.checked:e.target.value:e,xh=(e,t)=>t.split(".").some((r,n,s)=>!isNaN(Number(r))&&e.has(s.slice(0,n).join("."))),Sh=e=>{const t=e.constructor&&e.constructor.prototype;return Be(t)&&t.hasOwnProperty("isPrototypeOf")},to=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function Ue(e){if(e instanceof Date)return new Date(e);const t=typeof FileList<"u"&&e instanceof FileList;if(to&&(e instanceof Blob||t))return e;const r=Array.isArray(e);if(!r&&!(Be(e)&&Sh(e)))return e;const n=r?[]:Object.create(Object.getPrototypeOf(e));for(const s in e)Object.prototype.hasOwnProperty.call(e,s)&&(n[s]=Ue(e[s]));return n}const Sr={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change",SUBMIT:"submit",TRIGGER:"trigger",VALID:"valid"},Wt={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},qt={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"},Ao="form",Ch="root",Oh=["__proto__","constructor","prototype"];var Bs=e=>/^\w*$/.test(e),Ae=e=>e===void 0,ro=e=>e.split(/[.[\]'"]/g).filter(Boolean),H=(e,t,r)=>{if(!t||!Be(e))return r;const n=Bs(t)?[t]:ro(t);if(n.some(i=>Oh.includes(i)))return r;const s=n.reduce((i,o)=>st(i)?void 0:i[o],e);return Ae(s)||s===e?Ae(e[t])?r:e[t]:s},kt=e=>typeof e=="boolean",gt=e=>typeof e=="function",je=(e,t,r)=>{let n=-1;const s=Bs(t)?[t]:ro(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=Be(d)||Array.isArray(d)?d:isNaN(+s[n+1])?{}:[]}if(Oh.includes(a))return;e[a]=c,e=e[a]}};const fl=p.createContext(null);fl.displayName="HookFormControlContext";const hl=()=>p.useContext(fl);var Eh=(e,t,r,n=!0)=>{const s={};for(const i in e)Object.defineProperty(s,i,{get:()=>{const o=i;return t._proxyFormState[o]!==Wt.all&&(t._proxyFormState[o]=!n||Wt.all),r&&(r[o]=!0),e[o]}});return s};const pl=to?p.useLayoutEffect:p.useEffect;function JO(e){const t=hl(),{control:r=t,disabled:n,name:s,exact:i}=e||{},[o,a]=p.useState(()=>({...r._formState,defaultValues:r._defaultValues})),c=p.useRef({isDirty:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,validatingFields:!1,isValidating:!1,isValid:!1,errors:!1});return pl(()=>r._subscribe({name:s,formState:c.current,exact:i,callback:d=>{!n&&a({...r._formState,...d,defaultValues:r._defaultValues})}}),[s,n,i]),p.useEffect(()=>{c.current.isValid&&r._setValid(!0)},[r]),p.useMemo(()=>Eh(o,r,c.current,!1),[o,r])}var mt=e=>typeof e=="string",Da=(e,t,r,n,s)=>mt(e)?(n&&t.watch.add(e),H(r,e,s)):Array.isArray(e)?e.map(i=>(n&&t.watch.add(i),H(r,i))):(n&&(t.watchAll=!0),r),Ia=e=>st(e)||!wh(e);const bu=(e,t)=>t.length===0&&!Array.isArray(e)&&!Sh(e);function At(e,t,r=new WeakMap){if(e===t)return!0;if(Ia(e)||Ia(t))return Object.is(e,t);if(zr(e)&&zr(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(bu(e,n)||bu(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(zr(a)&&zr(c)||(Be(a)||Array.isArray(a))&&(Be(c)||Array.isArray(c))?!At(a,c,r):!Object.is(a,c))return!1}}return!0}function eE(e){const t=hl(),{control:r=t,name:n,defaultValue:s,disabled:i,exact:o,compute:a}=e||{},c=p.useRef(s),d=p.useRef(a),u=p.useRef(void 0),f=p.useRef(r),m=p.useRef(n);d.current=a;const[g,_]=p.useState(()=>{const w=r._getWatch(n,c.current);return d.current?d.current(w):w}),h=p.useCallback(w=>{const C=Da(n,r._names,w||r._formValues,!1,c.current);return d.current?d.current(C):C},[r._formValues,r._names,n]),y=p.useCallback(w=>{if(!i){const C=Da(n,r._names,w||r._formValues,!1,c.current);if(d.current){const D=d.current(C);At(D,u.current)||(_(D),u.current=D)}else _(C)}},[r._formValues,r._names,i,n]);pl(()=>((f.current!==r||!At(m.current,n))&&(f.current=r,m.current=n,y()),r._subscribe({name:n,formState:{values:!0},exact:o,callback:w=>{y(w.values)}})),[r,o,n,y]),p.useEffect(()=>r._removeUnmounted());const v=f.current!==r,b=m.current,x=p.useMemo(()=>{if(i)return null;const w=!v&&!At(b,n);return v||w?h():null},[i,v,n,b,h]);return x!==null?x:g}function no(e){const t=hl(),{name:r,disabled:n,control:s=t,shouldUnregister:i,defaultValue:o,exact:a=!0}=e,c=xh(s._names.array,r),d=p.useMemo(()=>H(s._formValues,r,H(s._defaultValues,r,o)),[s,r,o]),u=eE({control:s,name:r,defaultValue:d,exact:a}),f=JO({control:s,name:r,exact:a}),m=p.useRef(e),g=p.useRef(null),_=p.useRef(s.register(r,{...e.rules,value:u,...kt(e.disabled)?{disabled:e.disabled}:{}}));m.current=e;const h=p.useMemo(()=>Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!H(f.errors,r)},isDirty:{enumerable:!0,get:()=>!!H(f.dirtyFields,r)},isTouched:{enumerable:!0,get:()=>!!H(f.touchedFields,r)},isValidating:{enumerable:!0,get:()=>!!H(f.validatingFields,r)},error:{enumerable:!0,get:()=>H(f.errors,r)}}),[f,r]),y=p.useCallback(w=>{const C=Ea(w);return H(s._fields,r)||(_.current=s.register(r,{...m.current.rules,value:C})),_.current.onChange({target:{value:Ea(w),name:r},type:Sr.CHANGE})},[r,s]),v=p.useCallback(()=>_.current.onBlur({target:{value:H(s._formValues,r),name:r},type:Sr.BLUR}),[r,s._formValues]),b=p.useCallback(w=>{w&&(g.current={focus:()=>gt(w.focus)&&w.focus(),select:()=>gt(w.select)&&w.select(),setCustomValidity:D=>gt(w.setCustomValidity)&&w.setCustomValidity(D),reportValidity:()=>gt(w.reportValidity)&&w.reportValidity()});const C=H(s._fields,r);C&&C._f&&w&&(C._f.ref=g.current)},[s._fields,r]),x=p.useMemo(()=>({name:r,value:u,...kt(n)||f.disabled?{disabled:f.disabled||n}:{},onChange:y,onBlur:v,ref:b}),[r,n,f.disabled,y,v,b,u]);return p.useEffect(()=>{const w=s._options.shouldUnregister||i;s.register(r,{...m.current.rules,...kt(m.current.disabled)?{disabled:m.current.disabled}:{}});const C=(D,j)=>{const k=H(s._fields,D);k&&k._f&&(k._f.mount=j)};if(C(r,!0),w){const D=Ue(H(i?s._defaultValues:s._options.values||s._defaultValues,r,H(s._options.defaultValues,r,m.current.defaultValue)));je(s._defaultValues,r,D),Ae(H(s._formValues,r))&&je(s._formValues,r,D)}if(!c&&s.register(r),g.current){const D=H(s._fields,r);D&&D._f&&(D._f.ref=g.current)}return()=>{(c?w&&!s._state.action:w)?s.unregister(r):C(r,!1)}},[r,s,c,i]),p.useEffect(()=>{s._setDisabledField({disabled:n,name:r})},[n,r,s]),p.useMemo(()=>({field:x,formState:f,fieldState:h}),[x,f,h])}const gl=p.createContext(null);gl.displayName="HookFormContext";const Yt=()=>p.useContext(gl),tE=({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:m,unregister:g,control:_,register:h,setFocus:y,subscribe:v})=>{const b=p.useMemo(()=>({watch:t,getValues:r,getFieldState:n,setError:s,clearErrors:i,setValue:o,setValues:a,trigger:c,formState:d,resetField:u,reset:f,handleSubmit:m,unregister:g,control:_,register:h,setFocus:y,subscribe:v}),[i,_,d,n,r,m,h,f,u,s,y,o,a,v,c,g,t]);return p.createElement(gl.Provider,{value:b},p.createElement(fl.Provider,{value:b.control},e))};var rE=(e,t,r,n,s)=>t?{...r[e],types:{...r[e]&&r[e].types?r[e].types:{},[n]:s||!0}}:{},Dh=e=>Array.isArray(e)?e.filter(Boolean):[],vi=e=>Array.isArray(e)?e:[e],_u=()=>{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 Ih(e,t){const r={};for(const n in e)if(e.hasOwnProperty(n)){const s=e[n],i=t[n];if(s&&Be(s)&&i){const o=Ih(s,i);Be(o)&&(r[n]=o)}else e[n]&&(r[n]=i)}return r}var Je=e=>Be(e)&&!Object.keys(e).length,ml=e=>e.type==="file",Ri=e=>{if(!to)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},Nh=e=>e.type==="select-multiple",yl=e=>e.type==="radio",nE=e=>yl(e)||$s(e),Po=e=>Ri(e)&&e.isConnected;function sE(e,t){const r=t.slice(0,-1).length;let n=0;for(;n<r;){if(st(e)){e=void 0;break}e=e[t[n]],n++}return e}function iE(e){for(const t in e)if(e.hasOwnProperty(t)&&!Ae(e[t]))return!1;return!0}function Ke(e,t){if(mt(t)&&Object.prototype.hasOwnProperty.call(e,t))return delete e[t],e;const r=Array.isArray(t)?t:Bs(t)?[t]:ro(t),n=r.length===1?e:sE(e,r),s=r.length-1,i=r[s];return n&&delete n[i],s!==0&&(Be(n)&&Je(n)||Array.isArray(n)&&iE(n))&&Ke(e,r.slice(0,-1)),e}var oE=e=>{for(const t in e)if(gt(e[t]))return!0;return!1};function Th(e){return Array.isArray(e)||Be(e)&&!oE(e)}function Na(e,t={}){for(const r in e){const n=e[r];Th(n)?(t[r]=Array.isArray(n)?[]:{},Na(n,t[r])):Ae(n)||(t[r]=!0)}return t}function Ta(e){if(e!==!1){if(e===!0)return!0;if(Array.isArray(e)){const t=e.map(r=>Ta(r));return t.some(r=>r!==void 0)?t:void 0}if(Be(e)){const t={};for(const r in e){const n=Ta(e[r]);Ae(n)||(t[r]=n)}return Object.keys(t).length?t:void 0}}}function $r(e,t,r){r||(r=Na(t));for(const n in e){const s=e[n];if(Th(s))Ae(t)||Ia(r[n])?r[n]=Na(s,Array.isArray(s)?[]:{}):$r(s,st(t)?{}:t[n],r[n]);else{const i=t[n];r[n]=!At(s,i)}}return Ta(r)||{}}const wu={value:!1,isValid:!1},xu={value:!0,isValid:!0};var jh=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&&!Ae(e[0].attributes.value)?Ae(e[0].value)||e[0].value===""?xu:{value:e[0].value,isValid:!0}:xu:wu}return wu},Rh=(e,{valueAsNumber:t,valueAsDate:r,setValueAs:n})=>Ae(e)?e:t?e===""?NaN:e&&+e:r&&mt(e)?new Date(e):n?n(e):e;const Su={isValid:!1,value:null};var kh=e=>Array.isArray(e)?e.reduce((t,r)=>r&&r.checked&&!r.disabled?{isValid:!0,value:r.value}:t,Su):Su;function Cu(e){const t=e.ref;return ml(t)?t.files:yl(t)?kh(e.refs).value:Nh(t)?[...t.selectedOptions].map(({value:r})=>r):$s(t)?jh(e.refs).value:Rh(Ae(t.value)?e.ref.value:t.value,e)}var aE=(e,t,r,n)=>{const s={};for(const i of e){const o=H(t,i);o&&je(s,i,o._f)}return{criteriaMode:r,names:[...e],fields:s,shouldUseNativeValidation:n}},ki=e=>e instanceof RegExp,es=e=>Ae(e)?e:ki(e)?e.source:Be(e)?ki(e.value)?e.value.source:e.value:e,Ou=e=>({isOnSubmit:!e||e===Wt.onSubmit,isOnBlur:e===Wt.onBlur,isOnChange:e===Wt.onChange,isOnAll:e===Wt.all,isOnTouch:e===Wt.onTouched});const Eu="AsyncFunction";var lE=e=>!!e&&!!e.validate&&!!(gt(e.validate)&&e.validate.constructor.name===Eu||Be(e.validate)&&Object.values(e.validate).find(t=>t.constructor.name===Eu)),cE=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate),Mo=(e,t,r)=>!r&&(t.watchAll||t.watch.has(e)||[...t.watch].some(n=>e.startsWith(`${n}.`)));const fs=(e,t,r,n)=>{for(const s of r||Object.keys(e)){const i=H(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(fs(a,t))break}else if(Be(a)&&fs(a,t))break}}};function Du(e,t,r){const n=H(e,r);if(n||Bs(r))return{error:n,name:r};const s=r.split(".");for(;s.length;){const i=s.join("."),o=H(t,i),a=H(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 uE=(e,t,r,n)=>{r(e);const{name:s,...i}=e;return Je(i)||n&&Object.keys(i).length>=Object.keys(t).length||Object.keys(i).find(o=>t[o]===(!n||Wt.all))},dE=(e,t,r)=>!e||!t||e===t||vi(e).some(n=>n&&(r?n===t:n.startsWith(t)||t.startsWith(n))),fE=(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,hE=(e,t)=>!Dh(H(e,t)).length&&Ke(e,t),Iu=(e,t,r)=>{const n=H(e,r),s=Array.isArray(n)?n:[];return je(s,Ch,t[r]),je(e,r,s),e};function Nu(e,t,r="validate"){if(mt(e)||Array.isArray(e)&&e.every(mt)||kt(e)&&!e)return{type:r,message:mt(e)?e:"",ref:t}}var mn=e=>Be(e)&&!ki(e)?e:{value:e,message:""},Tu=async(e,t,r,n,s,i)=>{const{ref:o,refs:a,required:c,maxLength:d,minLength:u,min:f,max:m,pattern:g,validate:_,name:h,valueAsNumber:y,mount:v}=e._f,b=H(r,h);if(!v||t.has(h))return{};const x=a?a[0]:o,w=U=>{if(s&&x.reportValidity){const R=kt(U)?"":U||"";a?a.forEach(B=>B.setCustomValidity(R)):x.setCustomValidity(R),x.reportValidity()}},C={},D=yl(o),j=$s(o),k=D||j,$=(y||ml(o))&&Ae(o.value)&&Ae(b)||Ri(o)&&o.value===""||b===""||Array.isArray(b)&&!b.length,N=rE.bind(null,h,n,C),A=(U,R,B,F=qt.maxLength,J=qt.minLength)=>{const ie=U?R:B;C[h]={type:U?F:J,message:ie,ref:o,...N(U?F:J,ie)}};if(i?!Array.isArray(b)||!b.length:c&&(!k&&($||st(b))||kt(b)&&!b||j&&!jh(a).isValid||D&&!kh(a).isValid)){const{value:U,message:R}=mt(c)?{value:!!c,message:c}:mn(c);if(U&&(C[h]={type:qt.required,message:R,ref:x,...N(qt.required,R)},!n))return w(R),C}if(!$&&(!st(f)||!st(m))){let U,R;const B=mn(m),F=mn(f);if(!st(b)&&!isNaN(b)){const J=o.valueAsNumber||b&&+b;st(B.value)||(U=J>B.value),st(F.value)||(R=J<F.value)}else{const J=o.valueAsDate||new Date(b),ie=be=>new Date(new Date().toDateString()+" "+be),me=o.type=="time",ve=o.type=="week";mt(B.value)&&b&&(U=me?ie(b)>ie(B.value):ve?b>B.value:J>new Date(B.value)),mt(F.value)&&b&&(R=me?ie(b)<ie(F.value):ve?b<F.value:J<new Date(F.value))}if((U||R)&&(A(!!U,B.message,F.message,qt.max,qt.min),!n))return w(C[h].message),C}if((d||u)&&!$&&(mt(b)||i&&Array.isArray(b))){const U=mn(d),R=mn(u),B=!st(U.value)&&b.length>+U.value,F=!st(R.value)&&b.length<+R.value;if((B||F)&&(A(B,U.message,R.message),!n))return w(C[h].message),C}if(g&&!$&&mt(b)){const{value:U,message:R}=mn(g);if(ki(U)&&!b.match(U)&&(C[h]={type:qt.pattern,message:R,ref:o,...N(qt.pattern,R)},!n))return w(R),C}if(_){if(gt(_)){const U=await _(b,r),R=Nu(U,x);if(R&&(C[h]={...R,...N(qt.validate,R.message)},!n))return w(R.message),C}else if(Be(_)){let U={};for(const R in _){if(!Je(U)&&!n)break;const B=Nu(await _[R](b,r),x,R);B&&(U={...B,...N(R,B.message)},w(B.message),n&&(C[h]=U))}if(!Je(U)&&(C[h]={ref:x,...U},!n))return C}}return w(!0),C};const pE={mode:Wt.onSubmit,reValidateMode:Wt.onChange,shouldFocusError:!0},Ah={submitCount:0,isDirty:!1,isReady:!1,isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{}};function gE(e={}){let t={...pE,...e},r={...Ue(Ah),isLoading:gt(t.defaultValues),errors:t.errors||{},disabled:t.disabled||!1},n={},s=Be(t.defaultValues)||Be(t.values)?Ue(t.defaultValues||t.values)||{}:{},i=t.shouldUnregister?{}:Ue(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 m={...f};const g={array:_u(),state:_u()},_=t.criteriaMode===Wt.all,h=S=>I=>{clearTimeout(d),d=setTimeout(S,I)},y=async S=>{if(!o.keepIsValid&&!t.disabled&&(f.isValid||m.isValid||S)){let I;t.resolver?(I=Je((await N()).errors),v()):I=await R({fields:n,onlyCheckValid:!0,eventType:Sr.VALID}),I!==r.isValid&&g.state.next({isValid:I})}},v=(S,I)=>{!t.disabled&&(f.isValidating||f.validatingFields||m.isValidating||m.validatingFields)&&((S||Array.from(a.mount)).forEach(T=>{T&&(I?je(r.validatingFields,T,I):Ke(r.validatingFields,T))}),g.state.next({validatingFields:r.validatingFields,isValidating:!Je(r.validatingFields)}))},b=()=>{r.dirtyFields=$r(s,i)},x=(S,I=[],T,V,z=!0,Q=!0)=>{if(V&&T&&!t.disabled){if(o.action=!0,Q&&Array.isArray(H(n,S))){const q=T(H(n,S),V.argA,V.argB);z&&je(n,S,q)}if(Q&&Array.isArray(H(r.errors,S))){const q=T(H(r.errors,S),V.argA,V.argB);z&&je(r.errors,S,q),hE(r.errors,S)}if((f.touchedFields||m.touchedFields)&&Q&&Array.isArray(H(r.touchedFields,S))){const q=T(H(r.touchedFields,S),V.argA,V.argB);z&&je(r.touchedFields,S,q)}(f.dirtyFields||m.dirtyFields)&&b(),g.state.next({name:S,isDirty:F(S,I),dirtyFields:r.dirtyFields,errors:r.errors,isValid:r.isValid})}else je(i,S,I)},w=(S,I)=>{je(r.errors,S,I),r.errors={...r.errors},g.state.next({errors:r.errors})},C=S=>{r.errors=S,g.state.next({errors:r.errors,isValid:!1})},D=S=>{const I=Bs(S)?[S]:ro(S);let T=i,V=s;for(let z=0;z<I.length-1;z++){const Q=I[z];if(T=st(T)?T:T[Q],V=st(V)?V:V[Q],T===null&&V!==null)return!0}return!1},j=(S,I,T,V)=>{const z=H(n,S);if(z){if(D(S))return;const Q=Ae(H(i,S)),q=H(i,S,Ae(T)?H(s,S):T);Ae(q)||V&&V.defaultChecked||I?je(i,S,I?q:Cu(z._f)):me(S,q),o.mount&&!o.action&&(y(),Q&&r.isDirty&&(f.isDirty||m.isDirty)&&(F()||(r.isDirty=!1,g.state.next({...r}))),e.shouldUnregister&&Q&&!Ae(H(i,S))&&Mo(S,a)&&(o.watch=!0))}},k=(S,I,T,V,z)=>{let Q=!1,q=!1;const ee={name:S};if(!t.disabled){if(!T||V){(f.isDirty||m.isDirty)&&(q=r.isDirty,r.isDirty=ee.isDirty=F(),Q=q!==ee.isDirty);const he=At(H(s,S),I);q=!!H(r.dirtyFields,S),he!==r.isDirty?r.dirtyFields=$r(s,i):he?Ke(r.dirtyFields,S):je(r.dirtyFields,S,!0),ee.dirtyFields=r.dirtyFields,Q=Q||(f.dirtyFields||m.dirtyFields)&&q!==!he}if(T){const he=H(r.touchedFields,S);he||(je(r.touchedFields,S,T),ee.touchedFields=r.touchedFields,Q=Q||(f.touchedFields||m.touchedFields)&&he!==T)}Q&&z&&g.state.next(ee)}return Q?ee:{}},$=(S,I,T,V)=>{const z=H(r.errors,S),Q=(f.isValid||m.isValid)&&kt(I)&&r.isValid!==I;if(t.delayError&&T?(c=h(()=>w(S,T)),c(t.delayError)):(clearTimeout(d),c=null,T?je(r.errors,S,T):Ke(r.errors,S),r.errors={...r.errors}),(T?!At(z,T):z)||!Je(V)||Q){const q={...V,...Q&&kt(I)?{isValid:I}:{},errors:r.errors,name:S};r={...r,...q},g.state.next(q)}},N=async S=>(v(S,!0),await t.resolver(i,t.context,aE(S||a.mount,n,t.criteriaMode,t.shouldUseNativeValidation))),A=async S=>{const{errors:I}=await N(S);if(v(S),S){for(const T of S){const V=H(I,T);V?a.array.has(T)&&Be(V)&&!Object.keys(V).some(z=>!Number.isNaN(Number(z)))?Iu(r.errors,{[T]:V},T):je(r.errors,T,V):Ke(r.errors,T)}r.errors={...r.errors}}else r.errors=I;return I},U=async({name:S,eventType:I})=>{if(e.validate){const T=await e.validate({formValues:i,formState:r,name:S,eventType:I});if(Be(T))for(const V in T){const z=T[V];z&&Ne(`${Ao}.${V}`,{message:mt(z.message)?z.message:"",type:z.type||qt.validate})}else mt(T)||!T?Ne(Ao,{message:T||"",type:qt.validate}):pe(Ao);return T}return!0},R=async({fields:S,onlyCheckValid:I,name:T,eventType:V,context:z={valid:!0,runRootValidation:!1}})=>{if(e.validate&&(z.runRootValidation=!0,!await U({name:T,eventType:V})&&(z.valid=!1,I)))return z.valid;for(const Q in S){const q=S[Q];if(q){const{_f:ee,...he}=q;if(ee){const Fe=a.array.has(ee.name),xt=q._f&&lE(q._f),St=f.validatingFields||f.isValidating||m.validatingFields||m.isValidating;xt&&St&&v([ee.name],!0);const lr=await Tu(q,a.disabled,i,_,t.shouldUseNativeValidation&&!I,Fe);if(xt&&St&&v([ee.name]),lr[ee.name]&&(z.valid=!1,I)||(!I&&(H(lr,ee.name)?Fe?Iu(r.errors,lr,ee.name):je(r.errors,ee.name,lr[ee.name]):Ke(r.errors,ee.name)),e.shouldUseNativeValidation&&lr[ee.name]))break}!Je(he)&&await R({context:z,onlyCheckValid:I,fields:he,name:Q,eventType:V})}}return z.valid},B=()=>{for(const S of a.unMount){const I=H(n,S);I&&(I._f.refs?I._f.refs.every(T=>!Po(T)):!Po(I._f.ref))&&Le(S)}a.unMount=new Set},F=(S,I)=>!t.disabled&&(S&&I&&je(i,S,I),!At(W(),s)),J=(S,I,T)=>Da(S,a,{...o.mount?i:Ae(I)?s:mt(S)?{[S]:I}:I},T,I),ie=S=>Dh(H(o.mount?i:s,S,t.shouldUnregister?H(s,S,[]):[])),me=(S,I,T={},V=!1)=>{const z=H(n,S);let Q=I;if(z){const q=z._f;q&&(!q.disabled&&je(i,S,Rh(I,q)),Q=Ri(q.ref)&&st(I)?"":I,Nh(q.ref)?[...q.ref.options].forEach(ee=>ee.selected=Q.includes(ee.value)):q.refs?$s(q.ref)?q.refs.forEach(ee=>{(!ee.defaultChecked||!ee.disabled)&&(Array.isArray(Q)?ee.checked=!!Q.find(he=>he===ee.value):ee.checked=Q===ee.value||!!Q)}):q.refs.forEach(ee=>ee.checked=ee.value===Q):ml(q.ref)?q.ref.value="":(q.ref.value=Q,q.ref.type||g.state.next({name:S,values:V?i:Ue(i)})))}(T.shouldDirty||T.shouldTouch)&&k(S,Q,T.shouldTouch,T.shouldDirty,!0),T.shouldValidate&&Y(S)},ve=(S,I,T,V=!1)=>{for(const z in I){if(!I.hasOwnProperty(z))return;const Q=I[z],q=S+"."+z,ee=H(n,q);(a.array.has(S)||Be(Q)||ee&&!ee._f)&&!zr(Q)?ve(q,Q,T,V):me(q,Q,T,V)}},be=(S,I,T,V)=>{const z=H(n,S),Q=a.array.has(S),q=V?I:Ue(I),ee=H(i,S),he=At(ee,q);if(he||je(i,S,q),Q)g.array.next({name:S,values:V?i:Ue(i)}),(f.isDirty||f.dirtyFields||m.isDirty||m.dirtyFields)&&T.shouldDirty&&(b(),g.state.next({name:S,dirtyFields:r.dirtyFields,isDirty:F(S,q)}));else{const Fe=Array.isArray(q)&&!q.length||Je(q);!z||z._f||st(q)||Fe?me(S,q,T,V):ve(S,q,T,V)}if(!he){const Fe=Mo(S,a),xt=V?i:Ue(i);g.state.next({...Fe&&r,name:o.mount||Fe?S:void 0,values:xt})}},K=(S,I,T={})=>be(S,I,T,!1),M=(S,I={})=>{const T=gt(S)?S(i):S;if(!At(i,T)){i={...i,...T};for(const V of a.mount)be(V,H(T,V),I,!0);g.state.next({...r,name:void 0,type:void 0,values:i}),I.shouldValidate&&y()}},G=async S=>{o.mount=!0;const I=S.target;let T=I.name,V=!0;const z=H(n,T),Q=he=>{V=Number.isNaN(he)||zr(he)&&isNaN(he.getTime())||At(he,H(i,T,he))},q=Ou(t.mode),ee=Ou(t.reValidateMode);if(z){let he,Fe;const xt=I.type?Cu(z._f):Ea(S),St=S.type===Sr.BLUR||S.type===Sr.FOCUS_OUT,lr=!cE(z._f)&&!e.validate&&!t.resolver&&!H(r.errors,T)&&!z._f.deps||fE(St,H(r.touchedFields,T),r.isSubmitted,ee,q),Hn=Mo(T,a,St);je(i,T,xt),St?(!I||!I.readOnly)&&(z._f.onBlur&&z._f.onBlur(S),c&&c(0)):z._f.onChange&&z._f.onChange(S);const Mr=k(T,xt,St),Xe=!Je(Mr)||Hn;if(!St&&g.state.next({name:T,type:S.type,values:Ue(i)}),lr)return(f.isValid||m.isValid)&&(t.mode==="onBlur"?St&&y():St||y()),Xe&&g.state.next({name:T,...Hn?{}:Mr});if(!t.resolver&&e.validate&&await U({name:T,eventType:S.type}),!St&&Hn&&g.state.next({...r}),t.resolver){const{errors:ct}=await N([T]);if(v([T]),Q(xt),!V){!Je(Mr)&&g.state.next(Mr);return}const bt=Du(r.errors,n,T),Vt=Du(ct,n,bt.name||T);he=Vt.error,T=Vt.name,Fe=Je(ct)}else v([T],!0),he=(await Tu(z,a.disabled,i,_,t.shouldUseNativeValidation))[T],v([T]),Q(xt),V&&(he?Fe=!1:(f.isValid||m.isValid)&&(Fe=await R({fields:n,onlyCheckValid:!0,name:T,eventType:S.type})));V&&(z._f.deps&&(!Array.isArray(z._f.deps)||z._f.deps.length>0)&&Y(z._f.deps),$(T,Fe,he,Mr))}},P=(S,I)=>{if(H(r.errors,I)&&S.focus)return S.focus(),1},Y=async(S,I={})=>{let T,V;const z=vi(S);if(t.resolver){const Q=await A(Ae(S)?S:z);T=Je(Q),V=S?!z.some(q=>H(Q,q)):T}else S?(V=(await Promise.all(z.map(async Q=>{const q=H(n,Q);return await R({fields:q&&q._f?{[Q]:q}:q,eventType:Sr.TRIGGER})}))).every(Boolean),!(!V&&!r.isValid)&&y()):V=T=await R({fields:n,name:S,eventType:Sr.TRIGGER});return g.state.next({...!mt(S)||(f.isValid||m.isValid)&&T!==r.isValid?{}:{name:S},...t.resolver||!S?{isValid:T}:{},errors:r.errors}),I.shouldFocus&&!V&&fs(n,P,S?z:a.mount),V},W=(S,I)=>{let T={...o.mount?i:s};return I&&(T=Ih(I.dirtyFields?r.dirtyFields:r.touchedFields,T)),Ae(S)?T:mt(S)?H(T,S):S.map(V=>H(T,V))},oe=(S,I)=>({invalid:!!H((I||r).errors,S),isDirty:!!H((I||r).dirtyFields,S),error:H((I||r).errors,S),isValidating:!!H(r.validatingFields,S),isTouched:!!H((I||r).touchedFields,S)}),pe=S=>{const I=S?vi(S):void 0;I==null||I.forEach(T=>Ke(r.errors,T)),I?I.forEach(T=>{g.state.next({name:T,errors:r.errors})}):g.state.next({errors:{}})},Ne=(S,I,T)=>{const V=(H(n,S,{_f:{}})._f||{}).ref,z=H(r.errors,S)||{},{ref:Q,message:q,type:ee,...he}=z;je(r.errors,S,{...he,...I,ref:V}),g.state.next({name:S,errors:r.errors,isValid:!1}),T&&T.shouldFocus&&V&&V.focus&&V.focus()},re=(S,I)=>gt(S)?g.state.subscribe({next:T=>"values"in T&&S(T.values||J(void 0,I),T)}):J(S,I,!0),se=S=>g.state.subscribe({next:I=>{if(dE(S.name,I.name,S.exact)&&uE(I,S.formState||f,Us,S.reRenderRoot)){const T={...i};S.callback({values:T,...r,...I,defaultValues:s})}}}).unsubscribe,le=S=>(o.mount=!0,m={...m,...S.formState},se({...S,formState:{...u,...S.formState}})),Le=(S,I={})=>{for(const T of S?vi(S):a.mount)a.mount.delete(T),a.array.delete(T),I.keepValue||(Ke(n,T),Ke(i,T)),!I.keepError&&Ke(r.errors,T),!I.keepDirty&&Ke(r.dirtyFields,T),!I.keepTouched&&Ke(r.touchedFields,T),!I.keepIsValidating&&Ke(r.validatingFields,T),!t.shouldUnregister&&!I.keepDefaultValue&&Ke(s,T);g.state.next({values:Ue(i)}),g.state.next({...r,...I.keepDirty?{isDirty:F()}:{}}),!I.keepIsValid&&y()},ze=({disabled:S,name:I})=>{if(kt(S)&&o.mount||S||a.disabled.has(I)){const z=a.disabled.has(I)!==!!S;S?a.disabled.add(I):a.disabled.delete(I),z&&o.mount&&!o.action&&y()}},Te=(S,I={})=>{let T=H(n,S);const V=kt(I.disabled)||kt(t.disabled),z=!a.registerName.has(S)&&T&&T._f&&!T._f.mount;return je(n,S,{...T||{},_f:{...T&&T._f?T._f:{ref:{name:S}},name:S,mount:!0,...I}}),a.mount.add(S),T&&!z?ze({disabled:kt(I.disabled)?I.disabled:t.disabled,name:S}):j(S,!0,I.value),{...V?{disabled:I.disabled||t.disabled}:{},...t.progressive?{required:!!I.required,min:es(I.min),max:es(I.max),minLength:es(I.minLength),maxLength:es(I.maxLength),pattern:es(I.pattern)}:{},name:S,onChange:G,onBlur:G,ref:Q=>{if(Q){a.registerName.add(S),Te(S,I),a.registerName.delete(S),T=H(n,S);const q=Ae(Q.value)&&Q.querySelectorAll&&Q.querySelectorAll("input,select,textarea")[0]||Q,ee=nE(q),he=T._f.refs||[];if(ee?he.find(Fe=>Fe===q):q===T._f.ref)return;je(n,S,{_f:{...T._f,...ee?{refs:[...he.filter(Po),q,...Array.isArray(H(s,S))?[{}]:[]],ref:{type:q.type,name:S}}:{ref:q}}}),j(S,!1,void 0,q)}else T=H(n,S,{}),T._f&&(T._f.mount=!1),(t.shouldUnregister||I.shouldUnregister)&&!(xh(a.array,S)&&o.action)&&a.unMount.add(S)}}},te=()=>t.shouldFocusError&&!t.shouldUseNativeValidation&&fs(n,P,a.mount),We=S=>{kt(S)&&(g.state.next({disabled:S}),fs(n,(I,T)=>{const V=H(n,T);V&&(I.disabled=V._f.disabled||S,Array.isArray(V._f.refs)&&V._f.refs.forEach(z=>{z.disabled=V._f.disabled||S}))},0,!1))},at=(S,I)=>async T=>{let V;T&&(T.preventDefault&&T.preventDefault(),T.persist&&T.persist());let z=Ue(i);if(g.state.next({isSubmitting:!0}),t.resolver){const{errors:Q,values:q}=await N();v(),r.errors=Q,z=Ue(q)}else await R({fields:n,eventType:Sr.SUBMIT});if(a.disabled.size)for(const Q of a.disabled)Ke(z,Q);if(Ke(r.errors,Ch),Je(r.errors)){g.state.next({errors:{}});try{await S(z,T)}catch(Q){V=Q}}else I&&await I({...r.errors},T),te(),setTimeout(te);if(g.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:Je(r.errors)&&!V,submitCount:r.submitCount+1,errors:r.errors}),V)throw V},vt=(S,I={})=>{H(n,S)&&(Ae(I.defaultValue)?K(S,Ue(H(s,S))):(K(S,I.defaultValue),je(s,S,Ue(I.defaultValue))),I.keepTouched||Ke(r.touchedFields,S),I.keepDirty||(Ke(r.dirtyFields,S),r.isDirty=I.defaultValue?F(S,Ue(H(s,S))):F()),I.keepError||(Ke(r.errors,S),f.isValid&&y()),g.state.next({...r}))},qe=(S,I={})=>{const T=S?Ue(S):s,V=Ue(T),z=Je(S),Q=V;if(I.keepDefaultValues||(s=T),!I.keepValues){if(I.keepDirtyValues){const q=new Set([...a.mount,...Object.keys($r(s,i))]);for(const ee of Array.from(q)){const he=H(r.dirtyFields,ee),Fe=H(i,ee),xt=H(Q,ee);he&&!Ae(Fe)?je(Q,ee,Fe):!he&&!Ae(xt)&&K(ee,xt)}}else{if(to&&Ae(S))for(const q of a.mount){const ee=H(n,q);if(ee&&ee._f){const he=Array.isArray(ee._f.refs)?ee._f.refs[0]:ee._f.ref;if(Ri(he)){const Fe=he.closest("form");if(Fe){Fe.reset();break}}}}if(I.keepFieldsRef)for(const q of a.mount)K(q,H(Q,q));else n={}}if(t.shouldUnregister){if(i=I.keepDefaultValues?Ue(s):{},I.keepFieldsRef)for(const q of a.mount)je(i,q,H(Q,q))}else i=Ue(Q);g.array.next({values:{...Q}}),g.state.next({values:{...Q}})}a={mount:I.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||!!I.keepIsValid||!!I.keepDirtyValues||!t.shouldUnregister&&!Je(Q),o.watch=!!t.shouldUnregister,o.keepIsValid=!!I.keepIsValid,o.action=!1,I.keepErrors||(r.errors={}),g.state.next({submitCount:I.keepSubmitCount?r.submitCount:0,isDirty:z?!1:I.keepDirty?r.isDirty:I.keepValues?F():!!(I.keepDefaultValues&&!At(S,s)),isSubmitted:I.keepIsSubmitted?r.isSubmitted:!1,dirtyFields:z?{}:I.keepDirtyValues?I.keepDefaultValues&&i?$r(s,i):r.dirtyFields:I.keepDefaultValues&&S?$r(s,S):I.keepDirty?r.dirtyFields:{},touchedFields:I.keepTouched?r.touchedFields:{},errors:I.keepErrors?r.errors:{},isSubmitSuccessful:I.keepIsSubmitSuccessful?r.isSubmitSuccessful:!1,isSubmitting:!1,defaultValues:s})},Ye=(S,I)=>qe(gt(S)?S(i):S,{...t.resetOptions,...I}),lt=(S,I={})=>{const T=H(n,S),V=T&&T._f;if(V){const z=V.refs?V.refs[0]:V.ref;z.focus&&setTimeout(()=>{z.focus(),I.shouldSelect&&gt(z.select)&&z.select()})}},Us=S=>{r={...r,...S}},Vs={control:{register:Te,unregister:Le,getFieldState:oe,handleSubmit:at,setError:Ne,_subscribe:se,_runSchema:N,_updateIsValidating:v,_focusError:te,_getWatch:J,_getDirty:F,_setValid:y,_setFieldArray:x,_setDisabledField:ze,_setErrors:C,_getFieldArray:ie,_reset:qe,_resetDefaultValues:()=>gt(t.defaultValues)&&t.defaultValues().then(S=>{Ye(S,t.resetOptions),g.state.next({isLoading:!1})}),_removeUnmounted:B,_disableForm:We,_subjects:g,_proxyFormState:f,get _fields(){return n},get _formValues(){return i},get _state(){return o},set _state(S){o=S},get _defaultValues(){return s},get _names(){return a},set _names(S){a=S},get _formState(){return r},get _options(){return t},set _options(S){t={...t,...S}}},subscribe:le,trigger:Y,register:Te,handleSubmit:at,watch:re,setValue:K,setValues:M,getValues:W,reset:Ye,resetField:vt,resetDefaultValues:(S,I={})=>{if(s=Ue(S),!I.keepDirty){const T=$r(s,i);r.dirtyFields=T,r.isDirty=!Je(T)}I.keepIsValid||y(),g.state.next({...r,defaultValues:s})},clearErrors:pe,unregister:Le,setError:Ne,setFocus:lt,getFieldState:oe};return{...Vs,formControl:Vs}}function mE(e={}){const t=p.useRef(void 0),r=p.useRef(void 0),n=p.useRef(e.formControl),[s,i]=p.useState(()=>({...Ue(Ah),isLoading:gt(e.defaultValues),errors:e.errors||{},disabled:e.disabled||!1,defaultValues:gt(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&&!gt(e.defaultValues)&&e.formControl.reset(e.defaultValues,e.resetOptions);else{const{formControl:a,...c}=gE(e);t.current={...c,formState:s}}const o=t.current.control;return o._options=e,pl(()=>{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]),p.useEffect(()=>o._disableForm(e.disabled),[o,e.disabled]),p.useEffect(()=>{e.mode&&(o._options.mode=e.mode),e.reValidateMode&&(o._options.reValidateMode=e.reValidateMode)},[o,e.mode,e.reValidateMode]),p.useEffect(()=>{e.errors&&(o._setErrors(e.errors),o._focusError())},[o,e.errors]),p.useEffect(()=>{e.shouldUnregister&&o._subjects.state.next({values:o._getWatch()})},[o,e.shouldUnregister]),p.useEffect(()=>{if(o._proxyFormState.isDirty){const a=o._getDirty();a!==s.isDirty&&o._subjects.state.next({isDirty:a})}},[o,s.isDirty]),p.useEffect(()=>{var a;e.values&&!At(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]),p.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=p.useMemo(()=>Eh(s,o),[o,s]),t.current}async function ju(e){var r,n;return(n=(r=(await Me.get(`/api/framework/v1/read/${e}`)).data)==null?void 0:r.result)==null?void 0:n.framework}function Ph(e,t){const r=ea({queryKey:["framework",e],queryFn:()=>ju(e),enabled:!!e,staleTime:3e5}),n=t==null?void 0:t[0],s=ea({queryKey:["framework",n],queryFn:()=>ju(n),enabled:!!n,staleTime:5*60*1e3}),i=s.data?[s.data]:[];return{organisationFramework:r.data,targetFrameworks:i,isLoading:r.isLoading||s.isLoading}}async function yE(e){var r,n;return(n=(r=(await Me.get(`/api/channel/v1/read/${e}`)).data)==null?void 0:r.result)==null?void 0:n.channel}function vE(e){var r,n,s,i,o,a;const t=ea({queryKey:["channel",e],queryFn:()=>yE(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 bE={"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."}},Zs={"First Section":"details","Second Section":"details","Third Section":"details","Organisation Framework Terms":"details","Target Framework Terms":"audience","Fourth Section":"licensing","Sixth Section":"licensing"},_E={Categorisation:"Second Section","Basic Information":"First Section","Licensing & Attribution":"Fourth Section",Curriculum:"Organisation Framework Terms","Target Audience":"Target Framework Terms"},wE={name:"details",description:"details",keywords:"details",appIcon:"details",primaryCategory:"details",additionalCategories:"details",board:"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"},Mh={board:"board",medium:"medium",gradeLevel:"gradeLevel",subject:"subject",subjectIds:"subject",topicsIds:"topic",topic:"topic",targetBoardIds:"board",targetMediumIds:"medium",targetGradeLevelIds:"gradeLevel",targetSubjectIds:"subject"},Ru=new Set(["targetBoardIds","targetMediumIds","targetGradeLevelIds","targetSubjectIds"]);function xE(e,t,r,n){if(!(e!=null&&e.length))return IE(t,n,r);const s=new Set;return e.filter(i=>{if(n&&(i.code==="dialCode"||i.code==="dialcode")||i.visible===!1)return!1;const o=i.code;return s.has(o)?!1:(s.add(o),!0)}).map(i=>{const o=i.code??"",a=EE(i),c=DE(i,r,t),d=t[o],u=Lh(d,a),f={code:o,label:i.label??o,inputType:a,required:!!(i.required===!0||Array.isArray(i.validations)&&i.validations.some(m=>m.type==="required")),editable:i.editable!==!1,placeholder:i.placeholder,maxLength:i.maxLength,options:CE(c,u,a,r),depends:i.depends,tab:OE(i),section:i.section,defaultValue:i.defaultValue??i.default,currentValue:u};if(o==="dialcodes"){const m=t.dialcodeRequired==="Yes";return{...f,required:m,visible:m}}return f})}function SE(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 CE(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=SE(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 OE(e){const t=e.section;if(t){if(Zs[t])return Zs[t];const n=_E[t];if(n&&Zs[n])return Zs[n]}const r=e.code??"";return wE[r]??"details"}function Lh(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 EE(e){const t=(e.inputType??e.dataType??"").toLowerCase(),n=(e.dataType??"").toLowerCase()==="list";return t==="select"||t==="framework"?"select":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 DE(e,t,r){var a;const n=e.range;if(Array.isArray(n)&&n.length)return typeof n[0]=="string"?n.map(c=>({label:c,value:c})):n.map(c=>({label:c.name,value:c.identifier}));const s=e.enum;if(s!=null&&s.length)return s.map(c=>({label:c,value:c}));const i=e.code??"";if(i==="framework")return t.orgFrameworks;if(i==="additionalCategories")return(a=t.channelAdditionalCategories)==null?void 0:a.map(c=>({label:c,value:c}));const o=e.sourceCategory??Mh[i];if(o)return Fh(i,o,e,t,r)}function Fh(e,t,r,n,s){var f,m,g,_,h;const i=Ru.has(e)||r.output==="identifier"||typeof r.section=="string"&&r.section.includes("Target"),o=y=>({label:y.name,value:i?y.identifier:y.name}),a=(m=(f=n.organisationFramework)==null?void 0:f.categories)==null?void 0:m.find(y=>y.code===t),c=(h=(_=(g=n.targetFrameworks)==null?void 0:g[0])==null?void 0:_.categories)==null?void 0:h.find(y=>y.code===t);let d=(Ru.has(e)?c==null?void 0:c.terms:a==null?void 0:a.terms)??(c==null?void 0:c.terms)??(a==null?void 0:a.terms)??[];const u=r.depends;if(u!=null&&u.length){const y=u.flatMap(v=>{const b=s[v];return Array.isArray(b)?b:b!=null&&b!==""?[b]:[]}).map(String);if(y.length){const v=d.filter(b=>{const x=b.associations;return!x||!x.length?!0:x.some(w=>y.includes(w.identifier)||y.includes(w.code)||y.includes(w.name))});v.length&&(d=v)}}return d.map(o)}function ts(e,t){const r=Mh[e];if(r)return Fh(e,r,{},t,{})}function nt(e,t,r){return Lh(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:nt(e,"name","text")},{code:"description",label:"Description",inputType:"textarea",editable:!0,tab:"details",section:"First Section",maxLength:2e3,currentValue:nt(e,"description","textarea")},{code:"keywords",label:"Keywords",inputType:"chips",editable:!0,tab:"details",section:"First Section",currentValue:nt(e,"keywords","chips")}];return t&&(n.push({code:"primaryCategory",label:"Category",inputType:"select",editable:!1,tab:"details",section:"Second Section",currentValue:nt(e,"primaryCategory","select")},{code:"additionalCategories",label:"Additional Category",inputType:"multiselect",editable:!0,tab:"details",section:"Second Section",currentValue:nt(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:nt(e,"framework","select")},{code:"subjectIds",label:"Subjects covered",inputType:"multiselect",required:!0,editable:!0,tab:"details",section:"Organisation Framework Terms",options:ts("subjectIds",r),currentValue:nt(e,"subjectIds","multiselect")}),n.push({code:"audience",label:"Audience Type",inputType:"multiselect",editable:!0,tab:"audience",section:"Target Framework Terms",currentValue:nt(e,"audience","multiselect")},{code:"targetBoardIds",label:"Board/Syllabus of the audience",inputType:"select",required:!0,editable:!0,tab:"audience",section:"Target Framework Terms",options:ts("targetBoardIds",r),currentValue:nt(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:ts("targetMediumIds",r),currentValue:nt(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:ts("targetGradeLevelIds",r),currentValue:nt(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:ts("targetSubjectIds",r),currentValue:nt(e,"targetSubjectIds","multiselect")}),n.push({code:"creator",label:"Author",inputType:"text",editable:!0,tab:"licensing",section:"Fourth Section",currentValue:nt(e,"creator","text")},{code:"attributions",label:"Attributions",inputType:"text",editable:!0,tab:"licensing",section:"Fourth Section",currentValue:nt(e,"attributions","text")},{code:"copyright",label:"Copyright",inputType:"text",required:!0,editable:!0,tab:"licensing",section:"Fourth Section",currentValue:nt(e,"copyright","text")},{code:"copyrightYear",label:"Copyright Year",inputType:"text",required:!0,editable:!0,tab:"licensing",section:"Fourth Section",currentValue:nt(e,"copyrightYear","text")},{code:"license",label:"License",inputType:"select",required:!0,editable:!0,tab:"licensing",section:"Fourth Section",currentValue:nt(e,"license","select")})),n}function NE(e,t){const{watch:r,setValue:n}=e;p.useEffect(()=>{const s=r((i,{name:o})=>{o&&t.forEach(a=>{var c;(c=a.depends)!=null&&c.includes(o)&&n(a.code,a.inputType==="multiselect"||a.inputType==="chips"?[]:"",{shouldDirty:!0})})});return()=>s.unsubscribe()},[r,n,t])}const TE="_section_ylgu8_1",jE="_header_ylgu8_11",RE="_title_ylgu8_17",kE="_description_ylgu8_24",AE="_divider_ylgu8_30",PE="_fields_ylgu8_36",yn={section:TE,header:jE,title:RE,description:kE,divider:AE,fields:PE},ME=({title:e,description:t,children:r})=>l.jsxs("div",{className:yn.section,children:[l.jsxs("div",{className:yn.header,children:[l.jsx("h3",{className:yn.title,children:e}),t&&l.jsx("p",{className:yn.description,children:t})]}),l.jsx("hr",{className:yn.divider}),l.jsx("div",{className:yn.fields,children:r})]}),LE="_field_1s288_1",FE="_fullWidth_1s288_7",$E="_label_1s288_11",BE="_required_1s288_19",UE="_input_1s288_24",VE="_textarea_1s288_45",zE="_inputError_1s288_50",qE="_error_1s288_54",HE="_selectBtn_1s288_59",WE="_selectOpen_1s288_83",KE="_placeholder_1s288_87",QE="_selectedVal_1s288_91",GE="_chevronUp_1s288_95",YE="_dropdown_1s288_100",XE="_option_1s288_116",ZE="_optionSelected_1s288_134",JE="_noOpts_1s288_139",eD="_chipGroup_1s288_146",tD="_chipInput_1s288_158",rD="_addChipBtn_1s288_167",nD="_radioGroup_1s288_184",sD="_radioLabel_1s288_191",iD="_iconWrap_1s288_199",oD="_iconPreview_1s288_214",aD="_iconPlaceholder_1s288_220",lD="_removeIconBtn_1s288_233",cD="_tagChip_1s288_252",uD="_tagChipRemove_1s288_264",dD="_nestedSelectRow_1s288_278",fD="_dialcodeRow_1s288_287",hD="_validateBtn_1s288_293",pD="_dialcodeValid_1s288_315",gD="_dialcodeSpinner_1s288_325",L={field:LE,fullWidth:FE,label:$E,required:BE,input:UE,textarea:VE,inputError:zE,error:qE,selectBtn:HE,selectOpen:WE,placeholder:KE,selectedVal:QE,chevronUp:GE,dropdown:YE,option:XE,optionSelected:ZE,noOpts:JE,chipGroup:eD,chipInput:tD,addChipBtn:rD,radioGroup:nD,radioLabel:sD,iconWrap:iD,iconPreview:oD,iconPlaceholder:aD,removeIconBtn:lD,tagChip:cD,tagChipRemove:uD,nestedSelectRow:dD,dialcodeRow:fD,validateBtn:hD,dialcodeValid:pD,dialcodeSpinner:gD},ku=({name:e,label:t,required:r,disabled:n,multiline:s,maxLength:i,placeholder:o})=>{const{register:a,formState:{errors:c}}=Yt(),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)})]})},mD=({name:e,label:t,options:r,required:n,disabled:s})=>{var h;const[i,o]=p.useState(!1),a=p.useRef(null),{register:c,watch:d,setValue:u,formState:{errors:f}}=Yt(),m=d(e),g=((h=r.find(y=>y.value===m))==null?void 0:h.label)??"Select…",_=f[e];return p.useEffect(()=>{if(!i)return;const y=v=>{var b;(b=a.current)!=null&&b.contains(v.target)||o(!1)};return document.addEventListener("mousedown",y),()=>document.removeEventListener("mousedown",y)},[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(y=>!y),children:[l.jsx("span",{className:m?L.selectedVal:L.placeholder,children:g}),l.jsx(ks,{size:14,className:i?L.chevronUp:""})]}),i&&l.jsxs("div",{className:L.dropdown,children:[r.map(y=>l.jsxs("button",{type:"button",className:[L.option,m===y.value?L.optionSelected:""].join(" "),onClick:()=>{u(e,y.value,{shouldDirty:!0,shouldValidate:!0}),o(!1)},children:[l.jsx("span",{children:y.label}),m===y.value&&l.jsx(Un,{size:13})]},y.value)),!r.length&&l.jsx("span",{className:L.noOpts,children:"No options"})]}),_&&l.jsx("span",{className:L.error,children:String(_.message)})]})},yD=({name:e,label:t,options:r,required:n,disabled:s})=>{const[i,o]=p.useState(!1),a=p.useRef(null),{register:c,watch:d,setValue:u,formState:{errors:f}}=Yt(),m=d(e)??[],g=f[e],_=m.length?`${m.length} selected`:"Select…";p.useEffect(()=>{if(!i)return;const y=v=>{var b;(b=a.current)!=null&&b.contains(v.target)||o(!1)};return document.addEventListener("mousedown",y),()=>document.removeEventListener("mousedown",y)},[i]);const h=y=>{const v=m.includes(y)?m.filter(b=>b!==y):[...m,y];u(e,v,{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,g?L.inputError:"",i?L.selectOpen:""].join(" "),onClick:()=>o(y=>!y),children:[l.jsx("span",{className:m.length?L.selectedVal:L.placeholder,children:_}),l.jsx(ks,{size:14,className:i?L.chevronUp:""})]}),i&&l.jsxs("div",{className:L.dropdown,children:[r.map(y=>l.jsxs("button",{type:"button",className:[L.option,m.includes(y.value)?L.optionSelected:""].join(" "),onClick:()=>h(y.value),children:[l.jsx(Un,{size:13,style:{opacity:m.includes(y.value)?1:0}}),l.jsx("span",{children:y.label})]},y.value)),!r.length&&l.jsx("span",{className:L.noOpts,children:"No options"})]}),g&&l.jsx("span",{className:L.error,children:String(g.message)})]})},vD=({name:e,label:t,required:r,disabled:n,placeholder:s="Add…"})=>{const[i,o]=p.useState(""),[a,c]=p.useState(!1),d=p.useRef(null),{watch:u,setValue:f,formState:{errors:m}}=Yt(),g=u(e)??[],_=m[e],h=()=>{const v=i.trim();v&&!g.includes(v)&&f(e,[...g,v],{shouldDirty:!0}),o(""),c(!1)},y=v=>f(e,g.filter(b=>b!==v),{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:[g.map(v=>l.jsxs("span",{className:"sbx-chip filled",children:[v,!n&&l.jsx("button",{type:"button",className:"sbx-chip-remove",onClick:()=>y(v),"aria-label":`Remove ${v}`,children:"×"})]},v)),!n&&(a?l.jsx("input",{ref:d,autoFocus:!0,className:L.chipInput,value:i,onChange:v=>o(v.target.value),onKeyDown:v=>{v.key==="Enter"&&(v.preventDefault(),h()),v.key==="Escape"&&(o(""),c(!1))},onBlur:h,placeholder:s}):l.jsxs("button",{type:"button",className:L.addChipBtn,onClick:()=>{c(!0),setTimeout(()=>{var v;return(v=d.current)==null?void 0:v.focus()},50)},children:[l.jsx(As,{size:12})," Add"]}))]}),_&&l.jsx("span",{className:L.error,children:String(_.message)})]})},bD=({name:e,label:t,options:r,required:n,disabled:s})=>{const{register:i,formState:{errors:o}}=Yt(),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 _D(e,t,r,n){var o,a;const i=(a=(o=(await Me.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 wD(e,t){var s,i;const n=(i=(s=(await Me.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 xD(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 SD(e,t,r){var o,a;const n=new FormData;n.append("fileUrl",t),n.append("mimeType",r);const i=(a=(o=(await Me.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 CD="_overlay_ga6eh_1",OD="_modal_ga6eh_12",ED="_header_ga6eh_24",DD="_title_ga6eh_33",ID="_closeBtn_ga6eh_39",ND="_tabs_ga6eh_57",TD="_tab_ga6eh_57",jD="_activeTab_ga6eh_83",RD="_body_ga6eh_88",kD="_searchWrap_ga6eh_99",AD="_searchIcon_ga6eh_104",PD="_searchInput_ga6eh_113",MD="_grid_ga6eh_132",LD="_imgCell_ga6eh_148",FD="_imgCellSelected_ga6eh_166",$D="_thumb_ga6eh_171",BD="_noThumb_ga6eh_177",UD="_checkBadge_ga6eh_183",VD="_loadMoreBtn_ga6eh_198",zD="_loadingRow_ga6eh_220",qD="_empty_ga6eh_230",HD="_spinner_ga6eh_237",WD="_uploadArea_ga6eh_247",KD="_dropZone_ga6eh_256",QD="_uploadIcon_ga6eh_277",GD="_dropText_ga6eh_281",YD="_dropSubtext_ga6eh_288",XD="_uploadPreview_ga6eh_294",ZD="_hiddenInput_ga6eh_301",JD="_fileName_ga6eh_305",eI="_errorText_ga6eh_311",tI="_footer_ga6eh_318",rI="_cancelBtn_ga6eh_328",nI="_confirmBtn_ga6eh_345",fe={overlay:CD,modal:OD,header:ED,title:DD,closeBtn:ID,tabs:ND,tab:TD,activeTab:jD,body:RD,searchWrap:kD,searchIcon:AD,searchInput:PD,grid:MD,imgCell:LD,imgCellSelected:FD,thumb:$D,noThumb:BD,checkBadge:UD,loadMoreBtn:VD,loadingRow:zD,empty:qD,spinner:HD,uploadArea:WD,dropZone:KD,uploadIcon:QD,dropText:GD,dropSubtext:YD,uploadPreview:XD,hiddenInput:ZD,fileName:JD,errorText:eI,footer:tI,cancelBtn:rI,confirmBtn:nI},Au=18,$h=({nodeId:e,currentValue:t,onSelect:r,onClose:n})=>{const[s,i]=p.useState("my"),[o,a]=p.useState(""),[c,d]=p.useState([]),[u,f]=p.useState(0),[m,g]=p.useState(!1),[_,h]=p.useState(null),[y,v]=p.useState(0),[b,x]=p.useState(null),[w,C]=p.useState(""),[D,j]=p.useState(!1),[k,$]=p.useState(""),N=p.useRef(null),A=ue(P=>{var Y,W;return((W=(Y=P.editorConfig)==null?void 0:Y.context)==null?void 0:W.channel)??""}),U=ue(P=>{var Y,W;return((W=(Y=P.editorConfig)==null?void 0:Y.context)==null?void 0:W.uid)??""}),R=ue(P=>{var Y,W,oe;return((oe=(W=(Y=P.editorConfig)==null?void 0:Y.context)==null?void 0:W.cloudStorage)==null?void 0:oe.presigned_headers)??{}}),B=ue(P=>{var Y,W,oe;return((oe=(W=(Y=P.editorConfig)==null?void 0:Y.config)==null?void 0:W.assetConfig)==null?void 0:oe.size)??1*1024*1024}),F=ue(P=>{var Y,W,oe;return((oe=(W=(Y=P.editorConfig)==null?void 0:Y.config)==null?void 0:W.assetConfig)==null?void 0:oe.accepted)??"image/png,image/jpeg"}),J=p.useCallback(async(P,Y,W=!1)=>{var oe;g(!0);try{const pe={status:["Live"],mediaType:["image"],mimeType:["image/png","image/jpeg","image/jpg","image/gif","image/svg+xml"]};s==="my"&&U&&(pe.createdBy=U),A&&(pe.channel=A);const re=((oe=(await Me.post("/action/composite/v3/search",{request:{filters:pe,query:P,limit:Au,offset:Y,sort_by:{createdOn:"desc"},fields:["identifier","name","appIcon","artifactUrl","downloadUrl"]}},{headers:{"X-Source":"web"}})).data)==null?void 0:oe.result)??{},se=re.content??[];f(re.count??0),d(le=>W?[...le,...se]:se)}catch{}finally{g(!1)}},[s,U,A]);p.useEffect(()=>{s!=="upload"&&(d([]),v(0),J(o,0))},[s]);const ie=p.useRef(),me=P=>{a(P),clearTimeout(ie.current),ie.current=setTimeout(()=>{d([]),v(0),J(P,0)},400)},ve=()=>{const P=y+Au;v(P),J(o,P,!0)},be=()=>{const P=(_==null?void 0:_.artifactUrl)??(_==null?void 0:_.appIcon)??(_==null?void 0:_.downloadUrl)??"";P&&r(P)};p.useEffect(()=>()=>{w&&URL.revokeObjectURL(w)},[w]);const K=P=>{var oe;const Y=(oe=P.target.files)==null?void 0:oe[0];if(P.target.value="",!Y)return;const W=F.split(",").map(pe=>pe.trim());if(!W.includes(Y.type)){const pe=W.map(Ne=>Ne.replace("image/","").toUpperCase()).join(", ");$(`Only ${pe} files are accepted.`);return}if(Y.size>B){const pe=(B/1048576).toFixed(0);$(`Image must be under ${pe} MB.`);return}w&&URL.revokeObjectURL(w),x(Y),C(URL.createObjectURL(Y)),$("")},M=async()=>{if(b){j(!0),$("");try{const P=await _D(b.name.split(".").slice(0,-1).join(".")||b.name,b.type,U,A),Y=await wD(P,b.name);await xD(Y,b,R);const W=Y.split("?")[0],oe=await SD(P,W,b.type);r(oe)}catch(P){$(P instanceof Error?P.message:"Upload failed.")}finally{j(!1)}}},G=c.length<u;return l.jsx("div",{className:fe.overlay,role:"dialog","aria-modal":"true","aria-label":"Select App Icon",children:l.jsxs("div",{className:fe.modal,children:[l.jsxs("div",{className:fe.header,children:[l.jsx("span",{className:fe.title,children:"Select App Icon"}),l.jsx("button",{className:fe.closeBtn,onClick:n,"aria-label":"Close",children:l.jsx(on,{size:18})})]}),l.jsxs("div",{className:fe.tabs,role:"tablist",children:[l.jsx("button",{role:"tab","aria-selected":s==="my",className:`${fe.tab} ${s==="my"?fe.activeTab:""}`,onClick:()=>i("my"),children:"My Images"}),l.jsx("button",{role:"tab","aria-selected":s==="all",className:`${fe.tab} ${s==="all"?fe.activeTab:""}`,onClick:()=>i("all"),children:"All Images"}),l.jsxs("button",{role:"tab","aria-selected":s==="upload",className:`${fe.tab} ${s==="upload"?fe.activeTab:""}`,onClick:()=>i("upload"),children:[l.jsx(Wl,{size:13,style:{marginRight:4}}),"Upload"]})]}),l.jsx("div",{className:fe.body,children:s!=="upload"?l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:fe.searchWrap,children:[l.jsx(la,{size:14,className:fe.searchIcon}),l.jsx("input",{type:"search",className:fe.searchInput,placeholder:"Search images…",value:o,onChange:P=>me(P.target.value)})]}),m&&c.length===0?l.jsxs("div",{className:fe.loadingRow,children:[l.jsx(ii,{size:20,className:fe.spinner}),l.jsx("span",{children:"Loading…"})]}):c.length===0?l.jsx("div",{className:fe.empty,children:"No images found"}):l.jsx("div",{className:fe.grid,children:c.map(P=>{const Y=P.appIcon??P.artifactUrl??P.downloadUrl??"",W=(_==null?void 0:_.identifier)===P.identifier;return l.jsxs("button",{type:"button",className:`${fe.imgCell} ${W?fe.imgCellSelected:""}`,onClick:()=>h(P),title:P.name,children:[Y?l.jsx("img",{src:Y,alt:P.name,className:fe.thumb}):l.jsx("div",{className:fe.noThumb,children:"IMG"}),W&&l.jsx("div",{className:fe.checkBadge,children:l.jsx(Un,{size:12})})]},P.identifier)})}),G&&!m&&l.jsx("button",{className:fe.loadMoreBtn,onClick:ve,children:"Load More"}),m&&c.length>0&&l.jsx("div",{className:fe.loadingRow,children:l.jsx(ii,{size:16,className:fe.spinner})})]}):l.jsxs("div",{className:fe.uploadArea,children:[l.jsx("div",{className:fe.dropZone,onClick:()=>{var P;return(P=N.current)==null?void 0:P.click()},onDragOver:P=>P.preventDefault(),onDrop:P=>{P.preventDefault();const Y=P.dataTransfer.files[0];Y&&K({target:{files:[Y],value:""}})},children:w?l.jsx("img",{src:w,alt:"Preview",className:fe.uploadPreview}):l.jsxs(l.Fragment,{children:[l.jsx(Wl,{size:32,className:fe.uploadIcon}),l.jsx("p",{className:fe.dropText,children:"Drag & drop or click to browse"}),l.jsxs("p",{className:fe.dropSubtext,children:[F.split(",").map(P=>P.replace("image/","").toUpperCase()).join(", ")," · max ",(B/(1024*1024)).toFixed(0)," MB"]})]})}),l.jsx("input",{ref:N,type:"file",accept:F,className:fe.hiddenInput,onChange:K}),b&&l.jsx("p",{className:fe.fileName,children:b.name}),k&&l.jsx("p",{className:fe.errorText,children:k})]})}),l.jsxs("div",{className:fe.footer,children:[l.jsx("button",{className:fe.cancelBtn,onClick:n,children:"Cancel"}),s==="upload"?l.jsx("button",{className:fe.confirmBtn,disabled:!b||D,onClick:M,children:D?l.jsxs(l.Fragment,{children:[l.jsx(ii,{size:14,className:fe.spinner})," Uploading…"]}):"Upload & Use"}):l.jsx("button",{className:fe.confirmBtn,disabled:!_,onClick:be,children:"Use Selected"})]})]})})},sI=({name:e,label:t,nodeId:r,required:n,disabled:s})=>{const[i,o]=p.useState(!1),{watch:a,setValue:c,register:d,formState:{errors:u}}=Yt(),f=a(e),m=u[e],g=h=>{c(e,h,{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:h=>{(h.key==="Enter"||h.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(Wd,{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(Ka,{size:13}),l.jsx("span",{children:"Remove"})]}),m&&l.jsx("span",{className:L.error,children:String(m.message)}),i&&l.jsx($h,{nodeId:r,currentValue:f,onSelect:g,onClose:()=>o(!1)})]})},iI=({name:e,label:t,required:r,disabled:n})=>{const{control:s}=Yt(),{field:i,fieldState:{error:o}}=no({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)})]})},oI=({name:e,label:t,required:r,disabled:n})=>{const{control:s}=Yt(),{field:i,fieldState:{error:o}}=no({name:e,control:s,rules:{required:r?`${t} is required`:!1},defaultValue:[]}),[a,c]=p.useState(""),d=p.useRef(null),u=i.value??[],f=h=>{const y=h.trim();!y||u.includes(y)||i.onChange([...u,y])},m=h=>{i.onChange(u.filter(y=>y!==h))},g=h=>{h.key==="Enter"||h.key===","?(h.preventDefault(),f(a),c("")):h.key==="Backspace"&&a===""&&u.length>0&&m(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 h;return!n&&((h=d.current)==null?void 0:h.focus())},style:{cursor:n?"not-allowed":"text"},children:[u.map(h=>l.jsxs("span",{className:L.tagChip,children:[h,!n&&l.jsx("button",{type:"button",className:L.tagChipRemove,onClick:y=>{y.stopPropagation(),m(h)},"aria-label":`Remove ${h}`,children:l.jsx(on,{size:11})})]},h)),!n&&l.jsx("input",{ref:d,className:L.chipInput,value:a,onChange:h=>c(h.target.value),onKeyDown:g,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)})]})},aI=({name:e,label:t,levels:r,required:n,disabled:s})=>{const{control:i}=Yt(),{field:o,fieldState:{error:a}}=no({name:e,control:i,rules:{required:n?`${t} is required`:!1},defaultValue:{}}),c=o.value??{},d=(u,f,m)=>{const g={};for(let _=0;_<f;_++)g[r[_].code]=c[r[_].code]??"";g[u]=m;for(let _=f+1;_<r.length;_++)g[r[_].code]="";o.onChange(g)};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 m=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||m,value:c[u.code]??"",onChange:g=>d(u.code,f,g.target.value),onBlur:o.onBlur,children:[l.jsx("option",{value:"",children:"Select…"}),u.options.map(g=>l.jsx("option",{value:g.value,children:g.label},g.value))]})]},u.code)})}),a&&l.jsx("span",{className:L.error,children:String(a.message)})]})},Pu=[{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"}],lI=({name:e,label:t,required:r,disabled:n})=>{const[s,i]=p.useState(!1),o=p.useRef(null),{register:a,watch:c,setValue:d,formState:{errors:u}}=Yt(),f=c(e),m=Pu.find(h=>h.value===f),g=(m==null?void 0:m.label)??"Select license…",_=u[e];return p.useEffect(()=>{if(!s)return;const h=y=>{var v;(v=o.current)!=null&&v.contains(y.target)||i(!1)};return document.addEventListener("mousedown",h),()=>document.removeEventListener("mousedown",h)},[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(h=>!h),"aria-haspopup":"listbox","aria-expanded":s,children:[l.jsx("span",{className:f?L.selectedVal:L.placeholder,children:g}),l.jsx(ks,{size:14,className:s?L.chevronUp:""})]}),s&&l.jsx("div",{className:L.dropdown,role:"listbox",children:Pu.map(h=>l.jsxs("button",{type:"button",role:"option","aria-selected":f===h.value,className:[L.option,f===h.value?L.optionSelected:""].join(" "),onClick:()=>{d(e,h.value,{shouldDirty:!0,shouldValidate:!0}),i(!1)},children:[l.jsx("span",{children:h.label}),f===h.value&&l.jsx(Un,{size:13})]},h.value))}),_&&l.jsx("span",{className:L.error,children:String(_.message)})]})},cI=({name:e,label:t,required:r,disabled:n})=>{const{control:s}=Yt(),{field:i,fieldState:{error:o}}=no({name:e,control:s,rules:{required:r?`${t} is required`:!1},defaultValue:""}),[a,c]=p.useState("idle"),[d,u]=p.useState(""),f=async()=>{const g=(i.value??"").trim();if(!g){c("invalid"),u("Enter a dial code to validate.");return}c("loading"),u("");try{const _=await L_(g),h=_==null?void 0:_.result,y=h==null?void 0:h.dialcodes;Array.isArray(y)&&y.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.")}},m=()=>a==="loading"?l.jsx(ii,{size:16,className:L.dialcodeSpinner}):a==="valid"?l.jsx(Vd,{size:16,color:"var(--sbx-success, #2e7d32)"}):a==="invalid"?l.jsx(aa,{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:g=>{i.onChange(g),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"}),m()]}),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})]})},uI="_form_szqex_1",dI="_ungrouped_szqex_7",fI="_noFields_szqex_18",Lo={form:uI,ungrouped:dI,noFields:fI},hI=({nodeMetadata:e,activeTab:t,isRoot:r,isFolder:n,editorMode:s,onFormValueChange:i,onFormStatusChange:o})=>{var me,ve,be,K;const a=ue(M=>M.editorConfig),c=ue(M=>M.rootFormConfig),d=ue(M=>M.unitFormConfig),{organisationFramework:u,targetFrameworks:f,isLoading:m}=Ph((me=a==null?void 0:a.context)==null?void 0:me.framework,(ve=a==null?void 0:a.context)==null?void 0:ve.targetFWIds),{frameworks:g,collectionAdditionalCategories:_}=vE((be=a==null?void 0:a.context)==null?void 0:be.channel),h=g==null?void 0:g.map(M=>({label:M.name,value:M.identifier})),y={organisationFramework:u,targetFrameworks:f,orgFrameworks:h,channelAdditionalCategories:_},v=Re(M=>M.selectedNodeId),b=Re(M=>M.treeCache),x=v?b[v]??{}:{},w={...e,...x},C=r?c:d,D=C||(((K=a==null?void 0:a.config.hierarchy)==null?void 0:K.formConfig)??[]),j=xE(D,w,y,r),k=j.filter(M=>M.tab===t&&M.inputType!=="appIcon"&&M.visible!==!1),$=mE({mode:"onChange",defaultValues:Object.fromEntries(j.map(M=>{const G=["multiselect","chips","keywords","tagsinput"],P=["nestedselect"];return G.includes(M.inputType)?[M.code,M.currentValue??M.defaultValue??[]]:P.includes(M.inputType)?[M.code,M.currentValue??M.defaultValue??{}]:[M.code,M.currentValue??M.defaultValue??""]}))});NE($,j);const{updateNode:N}=Re(),A=p.useRef(j);A.current=j;const U=p.useRef(v);U.current=v;const R=p.useRef(i);R.current=i;const B=p.useRef(o);B.current=o,p.useEffect(()=>{const M=U.current;if(M){const G=Object.fromEntries(A.current.filter(P=>P.currentValue!==void 0&&P.currentValue!==null).map(P=>[P.code,P.currentValue]));Object.keys(G).length>0&&N(M,G)}$.trigger().then(()=>{const G=$.formState.errors,P=A.current,Y=Array.from(new Set(Object.keys(G).map(W=>{var oe;return(oe=P.find(pe=>pe.code===W))==null?void 0:oe.tab}).filter(Boolean)));B.current(Object.keys(G).length===0,Y)})},[]),p.useEffect(()=>{const M=$.watch((G,{name:P})=>{const Y=U.current;if(!Y)return;const W=A.current,oe=new Set(W.map(re=>re.code));if(P&&oe.has(P)){let re=$.getValues(P);P==="dialcodes"&&(re=Array.isArray(re)?re:re?[re]:[]),N(Y,{[P]:re}),R.current({[P]:re})}else if(!P){const re=$.getValues(),se=Object.fromEntries(Object.entries(re).filter(([le])=>oe.has(le)));Object.keys(se).length>0&&(N(Y,se),R.current(se))}const pe=$.formState.errors,Ne=Array.from(new Set(Object.keys(pe).map(re=>{var se;return(se=W.find(le=>le.code===re))==null?void 0:se.tab}).filter(Boolean)));B.current(Object.keys(pe).length===0,Ne)});return()=>M.unsubscribe()},[$]);const F=s!=="edit",J=k.reduce((M,G)=>{const P=M[M.length-1];return P&&P.section===G.section?P.fields.push(G):M.push({section:G.section,fields:[G]}),M},[]),ie=M=>{const G={key:M.code,name:M.code,label:M.label,required:M.required,disabled:F||M.editable===!1};switch(M.inputType){case"textarea":return l.jsx(ku,{...G,multiline:!0,maxLength:M.maxLength});case"select":return l.jsx(mD,{...G,options:M.options??[]});case"multiselect":return l.jsx(yD,{...G,options:M.options??[]});case"chips":return l.jsx(vD,{...G});case"radio":return l.jsx(bD,{...G,options:M.options??[]});case"appIcon":return l.jsx(sI,{...G,nodeId:v??""});case"datepicker":case"datetime":return l.jsx(iI,{...G});case"keywords":case"tagsinput":return l.jsx(oI,{...G});case"nestedselect":return l.jsx(aI,{...G,levels:M.levels??[]});case"license":return l.jsx(lI,{...G});case"dialcode":return l.jsx(cI,{...G});default:return l.jsx(ku,{...G,maxLength:M.maxLength})}};return l.jsx(tE,{...$,children:l.jsxs("div",{className:Lo.form,children:[J.map((M,G)=>{const P=M.section?bE[M.section]:void 0;return P?l.jsx(ME,{title:P.title,description:P.description,children:M.fields.map(ie)},M.section??G):l.jsx("div",{className:Lo.ungrouped,children:M.fields.map(ie)},G)}),k.length===0&&!m&&l.jsx("p",{className:Lo.noFields,children:"No fields configured for this tab."})]})})};function Bh(e,t,r){const n=e.slice();return n.splice(r<0?n.length+r:r,0,n.splice(t,1)[0]),n}function pI(e,t){return e.reduce((r,n,s)=>{const i=t.get(n);return i&&(r[s]=i),r},Array(e.length))}function Js(e){return e!==null&&e>=0}function gI(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 mI(e){return typeof e=="boolean"?{draggable:e,droppable:e}:e}const Uh=e=>{let{rects:t,activeIndex:r,overIndex:n,index:s}=e;const i=Bh(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}},ei={scaleX:1,scaleY:1},yI=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,...ei}:null}const c=vI(i,s,r);return s>r&&s<=o?{x:0,y:-a.height-c,...ei}:s<r&&s>=o?{x:0,y:a.height+c,...ei}:{x:0,y:0,...ei}};function vI(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 Vh="Sortable",zh=p.createContext({activeIndex:-1,containerId:Vh,disableTransforms:!1,items:[],overIndex:-1,useDragOverlay:!1,sortedRects:[],strategy:Uh,disabled:{draggable:!1,droppable:!1}});function bI(e){let{children:t,id:r,items:n,strategy:s=Uh,disabled:i=!1}=e;const{active:o,dragOverlay:a,droppableRects:c,over:d,measureDroppableContainers:u}=$d(),f=js(Vh,r),m=a.rect!==null,g=p.useMemo(()=>n.map(D=>typeof D=="object"&&"id"in D?D.id:D),[n]),_=o!=null,h=o?g.indexOf(o.id):-1,y=d?g.indexOf(d.id):-1,v=p.useRef(g),b=!gI(g,v.current),x=y!==-1&&h===-1||b,w=mI(i);Kt(()=>{b&&_&&u(g)},[b,g,_,u]),p.useEffect(()=>{v.current=g},[g]);const C=p.useMemo(()=>({activeIndex:h,containerId:f,disabled:w,disableTransforms:x,items:g,overIndex:y,useDragOverlay:m,sortedRects:pI(g,c),strategy:s}),[h,f,w.draggable,w.droppable,x,g,y,c,m,s]);return p.createElement(zh.Provider,{value:C},t)}const _I=e=>{let{id:t,items:r,activeIndex:n,overIndex:s}=e;return Bh(r,n,s).indexOf(t)},wI=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},xI={duration:200,easing:"ease"},qh="transform",SI=Ar.Transition.toString({property:qh,duration:0,easing:"linear"}),CI={roleDescription:"sortable"};function OI(e){let{disabled:t,index:r,node:n,rect:s}=e;const[i,o]=p.useState(null),a=p.useRef(r);return Kt(()=>{if(!t&&r!==a.current&&n.current){const c=s.current;if(c){const d=Bn(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]),p.useEffect(()=>{i&&o(null)},[i]),i}function EI(e){let{animateLayoutChanges:t=wI,attributes:r,disabled:n,data:s,getNewIndex:i=_I,id:o,strategy:a,resizeObserverConfig:c,transition:d=xI}=e;const{items:u,containerId:f,activeIndex:m,disabled:g,disableTransforms:_,sortedRects:h,overIndex:y,useDragOverlay:v,strategy:b}=p.useContext(zh),x=DI(n,g),w=u.indexOf(o),C=p.useMemo(()=>({sortable:{containerId:f,index:w,items:u},...s}),[f,s,w,u]),D=p.useMemo(()=>u.slice(u.indexOf(o)),[u,o]),{rect:j,node:k,isOver:$,setNodeRef:N}=$m({id:o,data:C,disabled:x.droppable,resizeObserverConfig:{updateMeasurementsFor:D,...c}}),{active:A,activatorEvent:U,activeNodeRect:R,attributes:B,setNodeRef:F,listeners:J,isDragging:ie,over:me,setActivatorNodeRef:ve,transform:be}=Fd({id:o,data:C,attributes:{...CI,...r},disabled:x.draggable}),K=Cg(N,F),M=!!A,G=M&&!_&&Js(m)&&Js(y),P=!v&&ie,Y=P&&G?be:null,oe=G?Y??(a??b)({rects:h,activeNodeRect:R,activeIndex:m,overIndex:y,index:w}):null,pe=Js(m)&&Js(y)?i({id:o,items:u,activeIndex:m,overIndex:y}):w,Ne=A==null?void 0:A.id,re=p.useRef({activeId:Ne,items:u,newIndex:pe,containerId:f}),se=u!==re.current.items,le=t({active:A,containerId:f,isDragging:ie,isSorting:M,id:o,index:w,items:u,newIndex:re.current.newIndex,previousItems:re.current.items,previousContainerId:re.current.containerId,transition:d,wasDragging:re.current.activeId!=null}),Le=OI({disabled:!le,index:w,node:k,rect:j});return p.useEffect(()=>{M&&re.current.newIndex!==pe&&(re.current.newIndex=pe),f!==re.current.containerId&&(re.current.containerId=f),u!==re.current.items&&(re.current.items=u)},[M,pe,f,u]),p.useEffect(()=>{if(Ne===re.current.activeId)return;if(Ne&&!re.current.activeId){re.current.activeId=Ne;return}const Te=setTimeout(()=>{re.current.activeId=Ne},50);return()=>clearTimeout(Te)},[Ne]),{active:A,activeIndex:m,attributes:B,data:C,rect:j,index:w,newIndex:pe,items:u,isOver:$,isSorting:M,isDragging:ie,listeners:J,node:k,overIndex:y,over:me,setNodeRef:K,setActivatorNodeRef:ve,setDroppableNodeRef:N,setDraggableNodeRef:F,transform:Le??oe,transition:ze()};function ze(){if(Le||se&&re.current.newIndex===w)return SI;if(!(P&&!Bi(U)||!d)&&(M||le))return Ar.Transition.toString({...d,property:qh})}}function DI(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 Ai(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 II=[we.Down,we.Right,we.Up,we.Left],NI=(e,t)=>{let{context:{active:r,collisionRect:n,droppableRects:s,droppableContainers:i,over:o,scrollableAncestors:a}}=t;if(II.includes(e.code)){if(e.preventDefault(),!r||!n)return;const c=[];i.getEnabled().forEach(f=>{if(!f||f!=null&&f.disabled)return;const m=s.get(f.id);if(m)switch(e.code){case we.Down:n.top<m.top&&c.push(f);break;case we.Up:n.top>m.top&&c.push(f);break;case we.Left:n.left>m.left&&c.push(f);break;case we.Right:n.left<m.left&&c.push(f);break}});const d=Ug({collisionRect:n,droppableRects:s,droppableContainers:c});let u=wd(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),m=i.get(u),g=m?s.get(m.id):null,_=m==null?void 0:m.node.current;if(_&&g&&f&&m){const y=Ui(_).some((D,j)=>a[j]!==D),v=Hh(f,m),b=TI(f,m),x=y||!v?{x:0,y:0}:{x:b?n.width-g.width:0,y:b?n.height-g.height:0},w={x:g.left,y:g.top};return x.x&&x.y?w:ys(w,x)}}}};function Hh(e,t){return!Ai(e)||!Ai(t)?!1:e.data.current.sortable.containerId===t.data.current.sortable.containerId}function TI(e,t){return!Ai(e)||!Ai(t)||!Hh(e,t)?!1:e.data.current.sortable.index<t.data.current.sortable.index}const jI="_row_11nth_1",RI="_removeBtn_11nth_14",kI="_grip_11nth_17",AI="_ctIcon_11nth_34",PI="_info_11nth_38",MI="_name_11nth_46",LI="_meta_11nth_55",Lr={row:jI,removeBtn:RI,grip:kI,ctIcon:AI,info:PI,name:MI,meta:LI},FI={video:Qa,pdf:za,h5p:qa,scorm:Wa,audio:Ha,quiz:Va,default:Vn},$I=({item:e,onRemove:t,isEditable:r})=>{const n=eo(e),s=FI[n.key]??Vn,{attributes:i,listeners:o,setNodeRef:a,transform:c,transition:d,isDragging:u}=EI({id:e.id,disabled:!r}),f={transform:Ar.Transform.toString(c),transition:d,opacity:u?.5:1};return l.jsxs("div",{ref:a,style:f,className:Lr.row,role:"listitem",children:[r&&l.jsx("span",{className:Lr.grip,...i,...o,"aria-label":"Drag to reorder",children:l.jsx(Hd,{size:15})}),l.jsx("span",{className:[`sbx-ct-sq--${n.key}`,Lr.ctIcon].join(" "),"aria-hidden":"true",children:l.jsx(s,{size:14})}),l.jsxs("div",{className:Lr.info,children:[l.jsx("span",{className:Lr.name,title:e.name,children:e.name}),l.jsx("span",{className:Lr.meta,children:n.label})]}),l.jsx("span",{className:`sbx-ct-badge--${n.key}`,children:n.label}),r&&l.jsx("button",{type:"button",className:Lr.removeBtn,onClick:()=>t(e.id),"aria-label":`Remove ${e.name}`,children:l.jsx(on,{size:14})})]})},BI="_container_lzvke_1",UI="_header_lzvke_7",VI="_heading_lzvke_13",zI="_count_lzvke_21",qI="_list_lzvke_30",HI="_emptyState_lzvke_36",WI="_addRow_lzvke_52",Fr={container:BI,header:UI,heading:VI,count:zI,list:qI,emptyState:HI,addRow:WI},KI=({editorMode:e})=>{const{selectedNodeId:t,getChildrenOf:r,reorderChildren:n,deleteNode:s}=Re(),i=t?r(t):[],o=e==="edit",a=vd(na(Vi,{activationConstraint:{distance:5}}),na($a,{coordinateGetter:NI})),c=p.useCallback(u=>{const{active:f,over:m}=u;if(!m||f.id===m.id||!t)return;const g=Re.getState().getChildrenOf(t),_=g.findIndex(y=>y.id===f.id),h=g.findIndex(y=>y.id===m.id);_<0||h<0||n(t,_,h)},[t,n]),d=p.useCallback(u=>{window.confirm("Remove this content from the unit?")&&s(u)},[s]);return t?l.jsxs("div",{className:Fr.container,children:[l.jsxs("div",{className:Fr.header,children:[l.jsx("span",{className:Fr.heading,children:"Content in this unit"}),l.jsx("span",{className:Fr.count,children:i.length})]}),i.length>0?l.jsx(Ld,{sensors:a,collisionDetection:Bg,onDragEnd:c,children:l.jsx(bI,{items:i.map(u=>u.id),strategy:yI,children:l.jsx("div",{className:Fr.list,role:"list",children:i.map(u=>l.jsx($I,{item:u,onRemove:d,isEditable:o},u.id))})})}):l.jsxs("div",{className:Fr.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:Fr.addRow,type:"button","aria-label":"Add content to unit",children:[l.jsx(As,{size:14})," Add content"]})]}):null},QI="_dropZone_ijo5w_1",GI="_active_ijo5w_14",Mu={dropZone:QI,active:GI},YI=({isActive:e,label:t="Drop here",nodeId:r,className:n})=>l.jsx("div",{className:`${Mu.dropZone} ${e?Mu.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 XI(e){var o;const t={status:["Live"],...e.filters??{}};e.channel&&(t.channel=e.channel);const n=((o=(await Me.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 ZI(e){var r,n;return(n=(r=(await Me.get(`/action/content/v3/read/${e}`)).data)==null?void 0:r.result)==null?void 0:n.content}const JI="_contentPlayerRoot_ryh6z_1",eN="_stage_ryh6z_9",tN="_playerHeader_ryh6z_19",rN="_playerHeaderThumb_ryh6z_33",nN="_playerHeaderTitle_ryh6z_43",sN="_typeBadge_ryh6z_53",iN="_typeDot_ryh6z_92",oN="_aspectRatio_ryh6z_99",aN="_playerFrame_ryh6z_112",lN="_coverOverlay_ryh6z_120",cN="_coverHidden_ryh6z_132",uN="_coverThumb_ryh6z_137",dN="_coverPlayRing_ryh6z_146",fN="_coverPlayIcon_ryh6z_159",hN="_coverLabel_ryh6z_168",pN="_coverSkeleton_ryh6z_174",gN="_playerWrapper_ryh6z_200",mN="_infoStrip_ryh6z_210",yN="_infoChip_ryh6z_226",vN="_infoChipLabel_ryh6z_245",bN="_infoChipIcon_ryh6z_254",_N="_playerError_ryh6z_260",wN="_playerErrorIcon_ryh6z_274",xN="_playerErrorMsg_ryh6z_279",SN="_qumlRoot_ryh6z_286",Pe={contentPlayerRoot:JI,stage:eN,playerHeader:tN,playerHeaderThumb:rN,playerHeaderTitle:nN,typeBadge:sN,typeDot:iN,aspectRatio:oN,playerFrame:aN,coverOverlay:lN,coverHidden:cN,coverThumb:uN,coverPlayRing:dN,coverPlayIcon:fN,coverLabel:hN,coverSkeleton:pN,playerWrapper:gN,infoStrip:mN,infoChip:yN,infoChipLabel:vN,infoChipIcon:bN,playerError:_N,playerErrorIcon:wN,playerErrorMsg:xN,qumlRoot:SN},CN=[{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 ON(e){return CN.find(t=>t.mimes.includes(e))??{key:"other",label:"Content",icon:"📱"}}const EN={"pdf-player":["application/pdf"],"video-player":["video/mp4","video/webm"],"epub-player":["application/epub"]},DN={"pdf-player":"/assets/sunbird-pdf-player.js","video-player":"/assets/sunbird-video-player.js","epub-player":"/assets/sunbird-epub-player.js"},IN={"pdf-player":"sunbird-pdf-player","video-player":"sunbird-video-player","epub-player":"sunbird-epub-player"},NN="/content/preview/preview.html?webview=true&build_number=2.8.0.e552fcd";function Fo(e){for(const[t,r]of Object.entries(EN))if(r.includes(e))return t;return"default-player"}function TN(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 jN(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 RN(e,t,r=100){await jN(DN[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 kN=[{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 AN({node:e}){const t=e.metadata??{},r=kN.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:Pe.infoStrip,children:r.map(n=>l.jsxs("div",{className:Pe.infoChip,children:[n.icon&&l.jsx("span",{className:Pe.infoChipIcon,children:n.icon}),l.jsx("span",{className:Pe.infoChipLabel,children:n.label}),n.val]},n.key))}):null}function PN({node:e,hidden:t}){var n;const r=e.appIcon??((n=e.metadata)==null?void 0:n.appIcon);return l.jsx("div",{className:`${Pe.coverOverlay} ${t?Pe.coverHidden:""}`,children:r?l.jsxs(l.Fragment,{children:[l.jsx("img",{src:r,alt:e.name,className:Pe.coverThumb}),l.jsx("div",{className:Pe.coverPlayRing,children:l.jsx("div",{className:Pe.coverPlayIcon})}),l.jsx("span",{className:Pe.coverLabel,children:"Loading preview…"})]}):l.jsx("div",{className:Pe.coverSkeleton})})}function MN({message:e}){return l.jsxs("div",{className:Pe.playerError,children:[l.jsx("span",{className:Pe.playerErrorIcon,children:"⚠"}),l.jsx("span",{className:Pe.playerErrorMsg,children:e})]})}function LN({mimeType:e}){const t=ON(e);return l.jsxs("span",{className:Pe.typeBadge,"data-type":t.key,children:[l.jsx("span",{className:Pe.typeDot}),t.label]})}const ja=({node:e,editorMode:t,type:r})=>{var s;if(r==="quml")return l.jsx($N,{node:e,editorMode:t});const n=e.appIcon??((s=e.metadata)==null?void 0:s.appIcon);return l.jsxs("div",{className:Pe.contentPlayerRoot,children:[l.jsxs("div",{className:Pe.stage,children:[l.jsxs("div",{className:Pe.playerHeader,children:[n&&l.jsx("img",{src:n,alt:"",className:Pe.playerHeaderThumb}),l.jsx("span",{className:Pe.playerHeaderTitle,children:e.name}),l.jsx(LN,{mimeType:e.mimeType??""})]}),l.jsx(FN,{node:e})]}),l.jsx(AN,{node:e})]})};function FN({node:e}){var y;const t=ue(v=>v.editorConfig),[r,n]=p.useState(()=>Fo(e.mimeType??"")),[s,i]=p.useState(!1),[o,a]=p.useState(null),[c,d]=p.useState(e.metadata??{}),[u,f]=p.useState(!1),m=p.useRef(null),g=p.useRef(null),_=((y=t==null?void 0:t.config)==null?void 0:y.previewCdnUrl)??NN;p.useEffect(()=>{let v=!1;return f(!1),i(!1),a(null),d(e.metadata??{}),n(Fo(e.mimeType??"")),ZI(e.identifier).then(b=>{if(v)return;const x={...e.metadata??{},...b};d(x);const w=b.mimeType??e.mimeType??"";n(Fo(w)),f(!0)}).catch(()=>{v||f(!0)}),()=>{v=!0}},[e.identifier]);const h=TN(e,c,t);return p.useEffect(()=>{if(!u||r!=="default-player")return;const v=m.current;if(!v)return;v.src=_;const b=()=>{try{const w=v.contentWindow;if(typeof(w==null?void 0:w.initializePreview)!="function"){a("Preview player unavailable. Check that /content/preview is reachable.");return}w.initializePreview(h),setTimeout(()=>i(!0),300)}catch(w){console.error("[ContentPlayer] initializePreview failed",w),a("Failed to initialize the content player.")}},x=()=>a("Preview player could not be loaded.");return v.addEventListener("load",b),v.addEventListener("error",x),()=>{v.removeEventListener("load",b),v.removeEventListener("error",x),v.src=""}},[e.identifier,r,_,u]),p.useEffect(()=>{if(!u||r==="default-player")return;const v=g.current;if(!v)return;const b=IN[r];if(!b)return;const x=h;RN(b,r).then(()=>{if(!g.current)return;if(!customElements.get(b)){n("default-player");return}const w=document.createElement(b);w.setAttribute("player-config",JSON.stringify(x)),w.addEventListener("playerEvent",()=>{}),w.addEventListener("telemetryEvent",()=>{}),v.innerHTML="",v.appendChild(w),setTimeout(()=>{try{w.playerConfig=x}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:Pe.aspectRatio,children:[o?l.jsx(MN,{message:o}):l.jsx(PN,{node:e,hidden:s}),r==="default-player"?l.jsx("iframe",{ref:m,id:"contentPlayer",title:e.name,className:Pe.playerFrame,name:"contentPlayer",allowFullScreen:!0}):l.jsx("div",{ref:g,className:Pe.playerFrame})]})}function $N({node:e,editorMode:t}){const r=ue(s=>s.editorConfig),n=p.useRef(null);return p.useEffect(()=>{var a;if(!n.current)return;const s=r==null?void 0:r.context,i={context:{mode:t==="edit"?"edit":"play",pdata:{id:((a=s==null?void 0:s.pdata)==null?void 0:a.id)??"sunbird.portal",ver:"1.0",pid:"sunbird-portal"},contentId:e.identifier,sid:(s==null?void 0:s.sid)??"",uid:(s==null?void 0:s.uid)??"",channel:(s==null?void 0:s.channel)??"",did:(s==null?void 0:s.did)??""},config:{enable:!1,showShare:!1,showDownload:!1,showReplay:!0,showExit:!1},metadata:e.metadata??{},data:{}},o=document.createElement("sunbird-quml-player");o.setAttribute("player-config",JSON.stringify(i)),n.current.innerHTML="",n.current.appendChild(o)},[e.identifier,t]),l.jsx("div",{className:Pe.qumlRoot,children:l.jsx("div",{ref:n,className:Pe.playerWrapper})})}const BN="_overlay_ifddx_1",UN="_modal_ifddx_11",VN="_header_ifddx_21",zN="_body_ifddx_37",qN="_hint_ifddx_43",HN="_list_ifddx_49",WN="_item_ifddx_55",KN="_selected_ifddx_68",QN="_empty_ifddx_73",GN="_footer_ifddx_79",YN="_cancelBtn_ifddx_87",XN="_moveBtn_ifddx_95",Ft={overlay:BN,modal:UN,header:VN,body:zN,hint:qN,list:HN,item:WN,selected:KN,empty:QN,footer:GN,cancelBtn:YN,moveBtn:XN};function ZN(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 JN=({resourceId:e,resourceName:t,currentUnitId:r,onClose:n})=>{var u;const{treeData:s,moveNode:i}=Re(),o=ZN(s,((u=s[0])==null?void 0:u.id)??"",r),[a,c]=p.useState(null),d=()=>{a&&(i(e,r,a),n())};return l.jsx("div",{className:Ft.overlay,role:"dialog","aria-label":"Move resource",children:l.jsxs("div",{className:Ft.modal,children:[l.jsxs("div",{className:Ft.header,children:[l.jsxs("span",{children:['Move "',t,'"']}),l.jsx("button",{onClick:n,"aria-label":"Close",children:l.jsx(on,{size:16})})]}),l.jsxs("div",{className:Ft.body,children:[l.jsx("p",{className:Ft.hint,children:"Select a unit to move this content to:"}),l.jsxs("ul",{className:Ft.list,children:[o.map(f=>l.jsxs("li",{className:`${Ft.item} ${a===f.id?Ft.selected:""}`,onClick:()=>c(f.id),children:[l.jsx(ly,{size:14}),l.jsx("span",{children:f.name})]},f.id)),o.length===0&&l.jsx("li",{className:Ft.empty,children:"No other units available"})]})]}),l.jsxs("div",{className:Ft.footer,children:[l.jsx("button",{className:Ft.cancelBtn,onClick:n,children:"Cancel"}),l.jsx("button",{className:Ft.moveBtn,onClick:d,disabled:!a,children:"Move here"})]})]})})},eT="_overlay_16at9_1",tT="_modal_16at9_11",rT="_header_16at9_21",nT="_body_16at9_37",sT="_table_16at9_43",iT="_pageInput_16at9_61",oT="_empty_16at9_68",aT="_footer_16at9_74",lT="_cancelBtn_16at9_82",cT="_saveBtn_16at9_90",tr={overlay:eT,modal:tT,header:rT,body:nT,table:sT,pageInput:iT,empty:oT,footer:aT,cancelBtn:lT,saveBtn:cT};function uT(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 dT=({onClose:e})=>{const{treeData:t,updateNode:r}=Re(),n=uT(t),[s,i]=p.useState(()=>Object.fromEntries(n.map(a=>{var c;return[a.id,String(((c=a.metadata)==null?void 0:c.pageNumber)??"")]}))),o=p.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:tr.overlay,role:"dialog","aria-label":"Assign Page Numbers",children:l.jsxs("div",{className:tr.modal,children:[l.jsxs("div",{className:tr.header,children:[l.jsx("span",{children:"Assign Page Numbers"}),l.jsx("button",{onClick:e,"aria-label":"Close",children:l.jsx(on,{size:16})})]}),l.jsx("div",{className:tr.body,children:n.length===0?l.jsx("p",{className:tr.empty,children:"No content items found in this collection."}):l.jsxs("table",{className:tr.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:tr.pageInput})})]},a.id))})]})}),l.jsxs("div",{className:tr.footer,children:[l.jsx("button",{className:tr.cancelBtn,onClick:e,children:"Cancel"}),l.jsxs("button",{className:tr.saveBtn,onClick:o,children:[l.jsx(yy,{size:14})," Save"]})]})]})})},fT="_container_1a7t2_1",hT="_panelHeader_1a7t2_10",pT="_panelHeaderLeft_1a7t2_19",gT="_panelCollapseBtn_1a7t2_27",mT="_titleRow_1a7t2_46",yT="_field_1a7t2_47",vT="_moveBtn_1a7t2_64",bT="_icon_1a7t2_84",_T="_nameInput_1a7t2_93",wT="_fieldHeader_1a7t2_118",xT="_label_1a7t2_124",ST="_fieldCount_1a7t2_133",CT="_chips_1a7t2_170",OT="_chip_1a7t2_170",ET="_chipRemove_1a7t2_188",DT="_keywordInput_1a7t2_202",IT="_input_1a7t2_207",NT="_addBtn_1a7t2_220",TT="_radioGroup_1a7t2_234",jT="_radioLabel_1a7t2_239",$e={container:fT,panelHeader:hT,panelHeaderLeft:pT,panelCollapseBtn:gT,titleRow:mT,field:yT,moveBtn:vT,icon:bT,nameInput:_T,fieldHeader:wT,label:xT,fieldCount:ST,chips:CT,chip:OT,chipRemove:ET,keywordInput:DT,input:IT,addBtn:NT,radioGroup:TT,radioLabel:jT},RT=({node:e,editorMode:t,onMoveClick:r,reorderDialog:n})=>{var A,U;const{updateNode:s,markDirty:i}=Re(),o=t==="edit",a=eo(e),c=ue(R=>R.relationalFormConfig),d=R=>c==null?void 0:c.find(B=>B.code===R),u=R=>!c||!!d(R),f=(R,B)=>{var F;return((F=d(R))==null?void 0:F.label)||B},[m,g]=p.useState(!0),_=((A=e.metadata)==null?void 0:A.relationalMetadata)??{},[h,y]=p.useState(_.name??e.name??""),[v,b]=p.useState(""),[x,w]=p.useState(Array.isArray(_.keywords)?_.keywords:Array.isArray((U=e.metadata)==null?void 0:U.keywords)?e.metadata.keywords:[]),[C,D]=p.useState(!!_.optional);p.useEffect(()=>{var B,F;const R=((B=e.metadata)==null?void 0:B.relationalMetadata)??{};y(R.name??e.name??""),w(Array.isArray(R.keywords)?R.keywords:Array.isArray((F=e.metadata)==null?void 0:F.keywords)?e.metadata.keywords:[]),D(!!R.optional)},[e.id]);const j=()=>{h.trim()&&h!==e.name&&(s(e.id,{name:h.trim()}),i())},k=()=>{const R=v.trim();if(R&&!x.includes(R)){const B=[...x,R];w(B),s(e.id,{keywords:B}),i()}b("")},$=R=>{const B=x.filter(F=>F!==R);w(B),s(e.id,{keywords:B}),i()},N=R=>{D(R),s(e.id,{optional:R}),i()};return l.jsxs("div",{className:$e.container,children:[l.jsxs("div",{className:$e.panelHeader,children:[l.jsxs("div",{className:$e.panelHeaderLeft,children:[l.jsx("span",{className:`sbx-ct-badge--${a.key}`,children:a.label}),o&&l.jsx("button",{type:"button",className:$e.moveBtn,onClick:r,children:"Move to another unit"})]}),l.jsx("button",{type:"button",className:$e.panelCollapseBtn,onClick:()=>g(R=>!R),"aria-expanded":m,"aria-label":m?"Collapse metadata panel":"Expand metadata panel",title:m?"Collapse":"Expand",children:m?l.jsx(ks,{size:15}):l.jsx(iy,{size:15})})]}),m&&l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:$e.titleRow,children:[e.appIcon&&l.jsx("img",{src:e.appIcon,alt:"icon",className:$e.icon}),l.jsx("input",{type:"text",className:$e.nameInput,value:h,disabled:!o,onChange:R=>y(R.target.value),onBlur:j,placeholder:"Content name"})]}),u("keywords")&&l.jsxs("div",{className:$e.field,children:[l.jsx("div",{className:$e.fieldHeader,children:l.jsxs("label",{className:$e.label,children:[f("keywords","Keywords"),x.length>0&&l.jsx("span",{className:$e.fieldCount,children:x.length})]})}),x.length>0&&l.jsx("div",{className:$e.chips,children:x.map(R=>l.jsxs("span",{className:$e.chip,children:[R,o&&l.jsx("button",{type:"button",className:$e.chipRemove,onClick:()=>$(R),children:"×"})]},R))}),o&&l.jsxs("div",{className:$e.keywordInput,children:[l.jsx("input",{type:"text",className:$e.input,value:v,placeholder:"Add keyword and press Enter",onChange:R=>b(R.target.value),onKeyDown:R=>{R.key==="Enter"&&(R.preventDefault(),k())}}),l.jsx("button",{type:"button",className:$e.addBtn,onClick:k,children:"Add"})]})]}),u("optional")&&l.jsxs("div",{className:$e.field,children:[l.jsx("label",{className:$e.label,children:f("optional","Optional in Collection")}),l.jsxs("div",{className:$e.radioGroup,children:[l.jsxs("label",{className:$e.radioLabel,children:[l.jsx("input",{type:"radio",name:`optional-${e.id}`,checked:C===!0,onChange:()=>N(!0),disabled:!o}),"Yes"]}),l.jsxs("label",{className:$e.radioLabel,children:[l.jsx("input",{type:"radio",name:`optional-${e.id}`,checked:C===!1,onChange:()=>N(!1),disabled:!o}),"No"]})]})]})]}),n]})},kT="_iconBtn_vl14u_1",AT="_editable_vl14u_14",PT="_iconImg_vl14u_26",MT="_placeholder_vl14u_34",LT="_removeBtn_vl14u_41",rs={iconBtn:kT,editable:AT,iconImg:PT,placeholder:MT,removeBtn:LT},FT=({nodeId:e,value:t,editable:r})=>{const[n,s]=p.useState(!1),{updateNode:i,markDirty:o}=Re(),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:[rs.iconBtn,r?rs.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:rs.iconImg}):l.jsx("div",{className:rs.placeholder,children:l.jsx(Wd,{size:18})}),t&&r&&l.jsx("button",{type:"button",className:rs.removeBtn,onClick:c,"aria-label":"Remove icon",children:l.jsx(Ka,{size:11})})]}),n&&l.jsx($h,{nodeId:e,currentValue:t,onSelect:a,onClose:()=>s(!1)})]})},$T="_leafContentLayout_1osey_1",BT="_container_1osey_17",UT="_emptyState_1osey_26",VT="_titleRow_1osey_36",zT="_nodeTitle_1osey_52",qT="_formArea_1osey_74",HT="_contentListArea_1osey_78",WT="_dropZone_1osey_83",KT="_reviewComment_1osey_90",QT="_reviewCommentLabel_1osey_103",GT="_reviewCommentText_1osey_109",zt={leafContentLayout:$T,container:BT,emptyState:UT,titleRow:VT,nodeTitle:zT,formArea:qT,contentListArea:HT,dropZone:WT,reviewComment:KT,reviewCommentLabel:QT,reviewCommentText:GT},YT=["application/vnd.sunbird.questionset"],XT=({editorMode:e,onToolbarEvent:t})=>{var A,U,R,B;const[r,n]=p.useState("details"),[s,i]=p.useState([]),[o,a]=p.useState(null),[c,d]=p.useState(!1),u=p.useRef(null),f=p.useRef(),{selectedNodeId:m,breadcrumb:g,activeNodeMeta:_,updateNode:h,treeData:y}=Re(),v=ue(F=>{var J,ie,me,ve;return((ie=(J=F.editorConfig)==null?void 0:J.context)==null?void 0:ie.contentId)??((ve=(me=F.editorConfig)==null?void 0:me.context)==null?void 0:ve.identifier)??""}),b=m?Wh(y,m):null,x=!!b&&!b.parent,w=!!(b!=null&&b.isFolder),C=b&&YT.includes(b.mimeType??""),D=b&&!b.isFolder&&!C&&!x,j=((A=b==null?void 0:b.metadata)==null?void 0:A.rejectComment)??(x?(R=(U=y[0])==null?void 0:U.metadata)==null?void 0:R.rejectComment:void 0),k=p.useCallback(()=>{const F=u.current;if(!F||!m)return;const J=F.innerText.trim();clearTimeout(f.current),f.current=setTimeout(()=>{h(m,{name:J})},600)},[m,h]),$=p.useCallback(F=>{t({action:"onFormValueChange",data:F})},[t]),N=p.useCallback((F,J)=>{i(J),t({action:"onFormStatusChange",data:{isValid:F,nodeId:m}})},[t,m]);return b?C?l.jsx(ja,{node:b,editorMode:e,type:"quml"}):D?l.jsxs("div",{className:zt.leafContentLayout,children:[l.jsx(ja,{node:b,editorMode:e,type:"content"}),l.jsx(RT,{node:b,editorMode:e,onMoveClick:()=>a(b.identifier),reorderDialog:o?l.jsx(JN,{resourceId:o,resourceName:b.name,currentUnitId:b.parent??"",onClose:()=>a(null)}):null})]}):l.jsxs("div",{className:zt.container,children:[l.jsx(WO,{crumbs:g}),j&&l.jsxs("div",{className:zt.reviewComment,role:"alert",children:[l.jsx("span",{className:zt.reviewCommentLabel,children:"Reviewer comment:"}),l.jsx("span",{className:zt.reviewCommentText,children:j})]}),l.jsxs("div",{className:zt.titleRow,children:[x&&m&&l.jsx(FT,{nodeId:m,value:String(b.appIcon??((B=b.metadata)==null?void 0:B.appIcon)??""),editable:e==="edit"}),l.jsx("div",{ref:u,className:zt.nodeTitle,contentEditable:e==="edit",suppressContentEditableWarning:!0,onInput:k,onBlur:k,"data-placeholder":"Untitled","aria-label":"Node title",children:b.name})]}),l.jsx(ZO,{activeTab:r,onChange:F=>n(F),errorTabs:s,visibleTabs:x?void 0:["details"]}),l.jsx("div",{className:zt.formArea,children:l.jsx(hI,{nodeMetadata:_,activeTab:r,isRoot:x,isFolder:w,editorMode:e,onFormValueChange:$,onFormStatusChange:N},`${m??"none"}:${x?"root":"node"}`)}),(w||x)&&r==="details"&&l.jsx("div",{className:zt.contentListArea,children:l.jsx(KI,{editorMode:e})}),l.jsx(YI,{isActive:!1,label:"Drop to add content to this unit",nodeId:m??void 0,className:zt.dropZone}),c&&l.jsx(dT,{contentId:v,onClose:()=>d(!1)})]}):l.jsx("div",{className:zt.emptyState,children:l.jsx("p",{children:"Select a unit from the outline to edit its details"})})};function Wh(e,t){for(const r of e){if(r.id===t)return r;if(r.children){const n=Wh(r.children,t);if(n)return n}}}const Kh=Hi((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})}})),ZT=20;function Qh(){var d;const e=ue(u=>u.editorConfig),t=Re(u=>u.selectedNodeId),r=Re(u=>u.treeData),n=p.useCallback(()=>{if(!t||!r.length)return 0;function u(f,m,g=0){var _;for(const h of f){if(h.id===m)return g;if((_=h.children)!=null&&_.length){const y=u(h.children,m,g+1);if(y>=0)return y}}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[...yu];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:[...yu]}function JT(){const e=Kh(),t=ue(f=>{var m,g;return((g=(m=f.editorConfig)==null?void 0:m.context)==null?void 0:g.channel)??""}),r=Qh(),n=p.useRef(),s=p.useCallback(async(f="",m="all",g={},_=!0,h=!1)=>{var y,v,b,x,w;e.setLoading(!0);try{const C={status:["Live"],primaryCategory:m&&m!=="all"?[m]:r};(y=g==null?void 0:g.board)!=null&&y.length&&(C.board=g.board),(v=g==null?void 0:g.medium)!=null&&v.length&&(C.medium=g.medium),(b=g==null?void 0:g.gradeLevel)!=null&&b.length&&(C.gradeLevel=g.gradeLevel),(x=g==null?void 0:g.subject)!=null&&x.length&&(C.subject=g.subject),(w=g==null?void 0:g.primaryCategory)!=null&&w.length&&(C.primaryCategory=g.primaryCategory);const D=_?0:e.offset,{content:j,count:k}=await XI({filters:C,query:f,limit:f?50:ZT,offset:D,channel:t||void 0,sortBy:h?{name:"asc"}:{lastUpdatedOn:"desc"}});_?e.setContent(j,k):e.appendContent(j,k)}catch(C){console.error("[useLibrary] load error:",C)}finally{e.setLoading(!1)}},[r,t]);p.useEffect(()=>{s()},[t]);const i=p.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=p.useCallback(f=>{e.setFilter(f),s(e.searchQuery,f,e.advancedFilters,!0,e.sortAZ)},[e.searchQuery,e.advancedFilters,e.sortAZ,s]),a=p.useCallback(f=>{e.setAdvancedFilters(f),s(e.searchQuery,e.activeFilter,f,!0,e.sortAZ)},[e.searchQuery,e.activeFilter,e.sortAZ,s]),c=p.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=p.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 ej="_card_jzciw_1",tj="_addBtn_jzciw_17",rj="_dragging_jzciw_24",nj="_ctIcon_jzciw_29",sj="_info_jzciw_33",ij="_name_jzciw_41",oj="_meta_jzciw_50",aj="_addBtnMuted_jzciw_78",lj="_added_jzciw_87",cj="_addedBadge_jzciw_96",rr={card:ej,addBtn:tj,dragging:rj,ctIcon:nj,info:sj,name:ij,meta:oj,addBtnMuted:aj,added:lj,addedBadge:cj},uj={video:Qa,pdf:za,h5p:qa,scorm:Wa,audio:Ha,quiz:Va,default:Vn},dj=({item:e,onAdd:t,onPreview:r,isDraggable:n,isAdded:s})=>{var h,y;const i=eo(e),o=uj[i.key]??Vn,a=dl(),c=I1(),d=a&&!s&&c,{attributes:u,listeners:f,setNodeRef:m,isDragging:g}=Fd({id:e.identifier,disabled:!n||!a||!c,data:{type:"library-item",item:e}}),_=()=>{r&&r(e)};return l.jsxs("div",{ref:m,className:[rr.card,g?rr.dragging:"",s?rr.added:""].join(" "),"aria-label":e.name,...n?{...u,...f}:{},role:"listitem",onClick:_,children:[l.jsx("span",{className:[`sbx-ct-sq--${i.key}`,rr.ctIcon].join(" "),"aria-hidden":"true",children:l.jsx(o,{size:14})}),l.jsxs("div",{className:rr.info,children:[l.jsx("span",{className:rr.name,title:e.name,children:e.name}),l.jsxs("span",{className:rr.meta,children:[((h=e.organisation)==null?void 0:h[0])??e.channel??"",(y=e.organisation)!=null&&y[0]&&e.primaryCategory?" · ":"",e.primaryCategory??""]})]}),s&&l.jsx("span",{className:rr.addedBadge,"aria-label":"Already added",title:"Already added to this collection",children:l.jsx(Un,{size:12})}),!s&&l.jsx("button",{type:"button",className:[rr.addBtn,!d&&a?rr.addBtnMuted:""].join(" "),onClick:v=>{v.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(As,{size:14})})]})},fj="_chips_xhhaq_1",hj="_chip_xhhaq_1",Lu={chips:fj,chip:hj},pj=({filters:e,active:t,onChange:r})=>l.jsx("div",{className:Lu.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",Lu.chip].join(" "),onClick:()=>r(n.value),children:n.label},n.value))}),gj="_panel_1cl11_1",mj="_header_1cl11_10",yj="_headerTitle_1cl11_19",vj="_closeBtn_1cl11_25",bj="_body_1cl11_43",_j="_section_1cl11_59",wj="_sectionLabel_1cl11_65",xj="_chips_1cl11_73",Sj="_chip_1cl11_73",Cj="_active_1cl11_96",Oj="_footer_1cl11_102",Ej="_resetBtn_1cl11_112",Dj="_applyBtn_1cl11_129",et={panel:gj,header:mj,headerTitle:yj,closeBtn:vj,body:bj,section:_j,sectionLabel:wj,chips:xj,chip:Sj,active:Cj,footer:Oj,resetBtn:Ej,applyBtn:Dj},Ij=[{key:"board",label:"Board"},{key:"medium",label:"Medium"},{key:"gradeLevel",label:"Class"},{key:"subject",label:"Subject"}],Nj=new Set(["board","medium","gradeLevel","subject","topic"]),Tj=({local:e,toggle:t})=>{const r=Qh();return r.length?l.jsxs("div",{className:et.section,children:[l.jsx("div",{className:et.sectionLabel,children:"Primary Category"}),l.jsx("div",{className:et.chips,children:r.map(n=>l.jsx("button",{type:"button",className:[et.chip,(e.primaryCategory??[]).includes(n)?et.active:""].join(" "),onClick:()=>t("primaryCategory",n),children:n},n))})]}):null},jj=({isOpen:e,filters:t,onApply:r,onClose:n})=>{var g,_;const s=ue(h=>h.editorConfig),i=ue(h=>h.searchFormConfig),{organisationFramework:o}=Ph((g=s==null?void 0:s.context)==null?void 0:g.framework,(_=s==null?void 0:s.context)==null?void 0:_.targetFWIds),[a,c]=p.useState(t),d=i!=null&&i.length?i.filter(h=>Nj.has(h.code)).map(h=>({key:h.code,label:h.label||h.code})):Ij;p.useEffect(()=>{c(t)},[t]);const u=(h,y)=>{c(v=>{const b=v[h]??[],x=b.includes(y)?b.filter(w=>w!==y):[...b,y];return{...v,[h]:x}})},f=(o==null?void 0:o.categories)??[],m=h=>{var y;return((y=f.find(v=>v.code===h))==null?void 0:y.terms)??[]};return e?l.jsxs("div",{className:et.panel,role:"dialog","aria-label":"Filter library","aria-modal":"true",children:[l.jsxs("div",{className:et.header,children:[l.jsx("span",{className:et.headerTitle,children:"Filters"}),l.jsx("button",{type:"button",className:et.closeBtn,onClick:n,"aria-label":"Close filters",children:l.jsx(on,{size:16})})]}),l.jsxs("div",{className:et.body,children:[d.map(({key:h,label:y})=>{const v=m(h);return v.length?l.jsxs("div",{className:et.section,children:[l.jsx("div",{className:et.sectionLabel,children:y}),l.jsx("div",{className:et.chips,children:v.slice(0,20).map(b=>l.jsx("button",{type:"button",className:[et.chip,(a[h]??[]).includes(b.name)?et.active:""].join(" "),onClick:()=>u(h,b.name),children:b.name},b.identifier))})]},h):null}),l.jsx(Tj,{local:a,toggle:u})]}),l.jsxs("div",{className:et.footer,children:[l.jsx("button",{type:"button",className:et.resetBtn,onClick:()=>c({}),children:"Reset"}),l.jsx("button",{type:"button",className:et.applyBtn,onClick:()=>{r(a),n()},children:"Apply"})]})]}):null},Rj="_header_6qdpu_10",kj="_title_6qdpu_20",Aj="_headerActions_6qdpu_31",Pj="_iconBtn_6qdpu_38",Mj="_playerArea_6qdpu_56",Lj="_footer_6qdpu_64",Fj="_addBtn_6qdpu_73",$j="_modalOverlay_6qdpu_92",Bj="_modalPanel_6qdpu_103",ur={header:Rj,title:kj,headerActions:Aj,iconBtn:Pj,playerArea:Mj,footer:Lj,addBtn:Fj,modalOverlay:$j,modalPanel:Bj},Uj=({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 Rr.createPortal(l.jsx("div",{className:ur.modalOverlay,role:"dialog","aria-modal":"true","aria-label":"Content preview",onClick:r,children:l.jsxs("div",{className:ur.modalPanel,onClick:s=>s.stopPropagation(),children:[l.jsxs("div",{className:ur.header,children:[l.jsx("span",{className:ur.title,title:e.name,children:e.name}),l.jsx("div",{className:ur.headerActions,children:l.jsx("button",{type:"button",className:ur.iconBtn,onClick:r,"aria-label":"Close preview",children:l.jsx(on,{size:16})})})]}),l.jsx("div",{className:ur.playerArea,children:l.jsx(ja,{node:n,editorMode:"read",type:"content"})}),l.jsx("div",{className:ur.footer,children:l.jsx("button",{type:"button",className:ur.addBtn,onClick:()=>t(e),children:"+ Add to Unit"})})]})}),document.body)},Vj="_dock_1lpg0_1",zj="_header_1lpg0_8",qj="_headerLeft_1lpg0_17",Hj="_headerTitle_1lpg0_24",Wj="_count_1lpg0_30",Kj="_searchRow_1lpg0_39",Qj="_searchWrap_1lpg0_47",Gj="_searchIcon_1lpg0_53",Yj="_searchInput_1lpg0_62",Xj="_filterToggleBtn_1lpg0_80",Zj="_filterToggleBtnActive_1lpg0_99",Jj="_filterBadge_1lpg0_105",eR="_filters_1lpg0_124",tR="_mainArea_1lpg0_134",rR="_sidePanelOverlay_1lpg0_143",nR="_cardList_1lpg0_152",sR="_skeleton_1lpg0_168",iR="_skeletonIcon_1lpg0_178",oR="_skeletonText_1lpg0_186",aR="_skeletonLine_1lpg0_193",lR="_skeletonLineSm_1lpg0_200",cR="_loadMoreBtn_1lpg0_215",uR="_emptyState_1lpg0_240",dR="_collapseBtn_1lpg0_260",ke={dock:Vj,header:zj,headerLeft:qj,headerTitle:Hj,count:Wj,searchRow:Kj,searchWrap:Qj,searchIcon:Gj,searchInput:Yj,filterToggleBtn:Xj,filterToggleBtnActive:Zj,filterBadge:Jj,filters:eR,mainArea:tR,sidePanelOverlay:rR,cardList:nR,skeleton:sR,skeletonIcon:iR,skeletonText:oR,skeletonLine:aR,skeletonLineSm:lR,loadMoreBtn:cR,emptyState:uR,collapseBtn:dR};function fR(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 hR=({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:m,toggleSort:g,loadMore:_}=JT(),{addResource:h,selectedNodeId:y,treeData:v}=Re(),b=e==="edit",[x,w]=p.useState(!1),[C,D]=p.useState({}),[j,k]=p.useState(null),$=p.useMemo(()=>fR(v),[v]),N=p.useCallback(F=>{var me;if(!y){Se.error("Select a unit first");return}const J=(me=v[0])==null?void 0:me.id;if(y===J){Se("Select a unit from the outline to add content — resources cannot be added directly to the course.",{icon:"ℹ️",duration:4e3});return}if(h(F,y)===!1){Se.error(`"${F.name}" is already in this collection`);return}Se.success(`Added "${F.name}"`)},[y,h,v]),A=p.useCallback(F=>{D(F),m(F)},[m]),U=p.useCallback(F=>{k(F)},[]),R=p.useCallback(F=>{N(F),k(null)},[N]),B=p.useMemo(()=>Object.values(C).reduce((F,J)=>F+((J==null?void 0:J.length)??0),0),[C]);return l.jsxs("div",{className:ke.dock,children:[l.jsx("div",{className:ke.header,children:l.jsxs("div",{className:ke.headerLeft,children:[l.jsx("button",{type:"button",className:ke.collapseBtn,onClick:r,"aria-label":"Collapse library panel",title:"Collapse library",children:l.jsx(py,{size:15})}),l.jsx(dy,{size:16}),l.jsx("span",{className:ke.headerTitle,children:"Library"}),i>0&&l.jsx("span",{className:ke.count,children:i})]})}),l.jsxs("div",{className:ke.searchRow,children:[l.jsxs("div",{className:ke.searchWrap,children:[l.jsx(la,{size:14,className:ke.searchIcon}),l.jsx("input",{type:"search",className:ke.searchInput,placeholder:"Search content…",value:a,onChange:F=>u(F.target.value),"aria-label":"Search library"})]}),l.jsx("button",{type:"button",className:[ke.filterToggleBtn,c?ke.filterToggleBtnActive:""].join(" "),onClick:g,"aria-label":c?"Sort: A–Z (click for Recent)":"Sort: Recent (click for A–Z)",title:c?"A–Z":"Recent",children:c?l.jsx(ny,{size:15}):l.jsx(oy,{size:15})}),l.jsxs("button",{type:"button",className:[ke.filterToggleBtn,x?ke.filterToggleBtnActive:""].join(" "),onClick:()=>w(F=>!F),"aria-label":"Toggle advanced filters","aria-pressed":x,title:"Advanced filters",children:[l.jsx(_y,{size:15}),B>0&&l.jsx("span",{className:ke.filterBadge,children:B})]})]}),l.jsx("div",{className:ke.filters,children:l.jsx(pj,{filters:N1,active:o,onChange:f})}),l.jsxs("div",{className:ke.mainArea,children:[l.jsx("div",{className:ke.cardList,role:"list","aria-label":"Library content",children:s&&n.length===0?Array.from({length:4}).map((F,J)=>l.jsxs("div",{className:ke.skeleton,"aria-hidden":"true",children:[l.jsx("div",{className:ke.skeletonIcon}),l.jsxs("div",{className:ke.skeletonText,children:[l.jsx("div",{className:ke.skeletonLine}),l.jsx("div",{className:ke.skeletonLineSm})]})]},J)):n.length>0?l.jsxs(l.Fragment,{children:[n.map(F=>l.jsx(dj,{item:F,onAdd:N,onPreview:U,isDraggable:b,isAdded:$.has(F.identifier)},F.identifier)),d&&l.jsx("button",{type:"button",className:ke.loadMoreBtn,onClick:_,disabled:s,"aria-label":"Load more content",children:s?"Loading…":"Load More"})]}):l.jsxs("div",{className:ke.emptyState,children:[l.jsx(la,{size:24}),l.jsx("p",{children:"No content found"}),l.jsx("span",{children:"Try a different search or filter"})]})}),x&&l.jsx("div",{className:ke.sidePanelOverlay,children:l.jsx(jj,{isOpen:x,filters:C,onApply:A,onClose:()=>w(!1)})}),j&&l.jsx(Uj,{content:j,onAdd:R,onClose:()=>k(null)})]})]})};function pR(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","targetBoardIds","targetMediumIds","targetGradeLevelIds","targetSubjectIds","medium","gradeLevel","subject","additionalCategories","keywords","language"]),c=new Set(["copyrightYear","compatibilityLevel","version"]);function d(m,g=!1){const _={};for(const[h,y]of Object.entries(m))if(!i.has(h)&&!(g&&o.has(h)))if(a.has(h))Array.isArray(y)?_[h]=y:y!=null&&y!==""?_[h]=[y]:_[h]=[];else if(c.has(h)){const v=Number(y);isNaN(v)||(_[h]=v)}else _[h]=y;return _}function u(m){var _;const g={};for(const h of m.children??[]){if(h.isFolder)continue;const y=t[h.identifier];if(!y)continue;const{isNew:v,...b}=y;if(Object.keys(b).length===0)continue;const x=((_=h.metadata)==null?void 0:_.relationalMetadata)??{};g[h.identifier]={name:h.name,...x,...b}}return g}function f(m,g){var x,w;const _=m.identifier,h=t[_],y=_.startsWith("temp-")||!!(h!=null&&h.isNew),v=!m.isFolder&&!g;if(g||y||h&&!v){let C;if(y)C={mimeType:"application/vnd.ekstep.content-collection",code:_,contentType:((x=m.metadata)==null?void 0:x.contentType)??"CourseUnit",primaryCategory:((w=m.metadata)==null?void 0:w.primaryCategory)??"Course Unit",name:m.name,visibility:"Parent",channel:r,...d(m.metadata??{})};else if(g){const{isNew:D,...j}=h??{};C={...d(m.metadata??{},!0),...d(j,!1),name:m.name}}else{const{isNew:D,...j}=h??{};C={name:m.name,visibility:"Parent",...d(j,!0)}}n[_]={metadata:C,objectType:m.objectType||(m.isFolder?"Collection":"Content"),root:g,isNew:y}}const b=m.isFolder?u(m):{};s[_]={name:m.name,children:(m.children??[]).map(C=>C.identifier),...Object.keys(b).length>0?{relationalMetadata:b}:{},root:g},(m.children??[]).forEach(C=>f(C,!1))}return e.forEach((m,g)=>f(m,g===0)),{nodesModified:n,hierarchy:s}}function gR(){const[e,t]=p.useState(!1),r=Re(u=>u.treeCache),n=Re(u=>u.treeData),s=ue(u=>u.isDirty),i=ue(u=>u.lastSaved),{setIsDirty:o,setLastSaved:a}=ue(),c=ue(u=>u.editorConfig);return{save:p.useCallback(async()=>{if(!c||e)return;const u=c.context.contentId??c.context.identifier??"";if(!u)return;const f=c.context.channel??"",m=c.context.userId??c.context.uid??"";t(!0);try{const{nodesModified:g,hierarchy:_}=pR(n,r,f),{identifiers:h}=await n_(u,g,_,m);h&&Object.keys(h).length>0&&Re.getState().replaceNodeIds(h);const y=new Date().toISOString();a(y),o(!1)}catch(g){console.error("[useSaveHierarchy] save failed:",g),Se.error("Failed to save. Please try again.")}finally{t(!1)}},[c,e,n,r,o,a]),isSaving:e,isDirty:s,lastSaved:i}}function mR(e){const t=ue(o=>o.editorConfig),r=ue(o=>o.setButtonLoader),n=ue(o=>o.validateAllForms),s=Re(o=>o.treeData);return{runAction:p.useCallback(async(o,a)=>{var u,f,m,g;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 Se.error("No content identifier found."),!1;const d=((m=t==null?void 0:t.context)==null?void 0:m.userId)??((g=t==null?void 0:t.context)==null?void 0:g.uid)??"";try{switch(o){case"sendForReview":return n(s)?(r("saveCollection",!0),await e(),await o_(c),Se.success("Content sent for review"),!0):(Se.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 a_(c,_),Se.success("Content rejected and sent back to the author"),!0}case"publish":return n(s)?(r("publishCollection",!0),await e(),await s_(c,d),Se.success("Content published successfully"),!0):(Se.error("Some units have missing required fields. Please fill them before publishing."),!1);default:return!1}}catch(_){console.error(`[useToolbarActions] ${o} failed`,_);const h=o==="sendForReview"?"send for review":o==="reject"?"reject":"publish";return Se.error(`Failed to ${h}. Please try again.`),!1}finally{r("saveCollection",!1),r("rejectCollection",!1),r("publishCollection",!1)}},[t,e,r])}}const yR="_shell_90fon_1",vR="_workspace_90fon_8",bR="_sidebarCollapsed_90fon_16",_R="_dockCollapsed_90fon_19",wR="_dock_90fon_19",xR="_outline_90fon_40",SR="_reopenTab_90fon_45",CR="_outlineHidden_90fon_79",OR="_editor_90fon_86",ER="_dockHidden_90fon_101",DR="_dockReopenTab_90fon_108",IR="_dragChip_90fon_133",NR="_dragChipLabel_90fon_148",Tt={shell:yR,workspace:vR,sidebarCollapsed:bR,dockCollapsed:_R,dock:wR,outline:xR,reopenTab:SR,outlineHidden:CR,editor:OR,dockHidden:ER,dockReopenTab:DR,dragChip:IR,dragChipLabel:NR},TR=({editorMode:e,onToolbarEvent:t,onContentAdded:r,onHierarchySaved:n})=>{const[s,i]=p.useState(null),[o,a]=p.useState(!1),[c,d]=p.useState(!1),[u,f]=p.useState(!1),{addResource:m,treeData:g}=Re(),_=ue(R=>R.setFormStatus),[h,y]=p.useState(!0),v=Re(R=>R.selectedNodeId),{save:b,isSaving:x,isDirty:w,lastSaved:C}=gR(),{runAction:D}=mR(b);p.useEffect(()=>{if(!w)return;const R=B=>{B.preventDefault(),B.returnValue=""};return window.addEventListener("beforeunload",R),()=>window.removeEventListener("beforeunload",R)},[w]);const j=vd(na(Vi,{activationConstraint:{distance:8}})),k=p.useCallback(R=>{var F;const B=(F=R.active.data.current)==null?void 0:F.item;B&&i(B)},[]),$=p.useCallback(R=>{var ve,be;i(null);const B=(ve=R.active.data.current)==null?void 0:ve.item;if(!B)return;const F=R.over,J=(F==null?void 0:F.id)??v??void 0;if(!J){Se.error("Drop onto a unit to add content");return}const ie=(be=g[0])==null?void 0:be.id;if(J===ie){Se.error("Drop content onto a unit, not directly on the course.");return}if(!m(B,J)){Se.error(`"${B.name}" is already in this collection`);return}r==null||r(B,J),Se.success(`Added "${B.name}" to unit`)},[v,m,r]),N=p.useCallback(async R=>{if(R.action==="onFormStatusChange"){const{isValid:B,nodeId:F}=R.data??{},J=B!==!1;y(J),F&&_(F,J);return}if(R.action==="back"&&w){f(!0);return}if(R.action==="saveCollection"){if(!h){Se.error("Please fill the required metadata");return}await b(),n==null||n(g),t==null||t(R);return}if(R.action==="sendForReview"||R.action==="reject"||R.action==="publish"){await D(R.action,R.data)&&(t==null||t(R));return}t==null||t(R)},[b,D,t,n,g,w,h]),A=p.useCallback(async()=>{await b(),f(!1),n==null||n(g),t==null||t({action:"back"})},[b,n,t,g]),U=p.useCallback(()=>{f(!1),t==null||t({action:"back"})},[t]);return l.jsxs(Ld,{sensors:j,onDragStart:k,onDragEnd:$,children:[l.jsxs("div",{className:Tt.shell,children:[l.jsx(gw,{editorMode:e,isSaving:x,isDirty:w,lastSaved:C,isFormValid:h,onToolbarEvent:N}),l.jsxs("div",{className:[Tt.workspace,o?Tt.sidebarCollapsed:"",c?Tt.dockCollapsed:""].filter(Boolean).join(" "),children:[l.jsx("aside",{className:[Tt.outline,o?Tt.outlineHidden:""].join(" "),"aria-label":"Course outline","aria-hidden":o,children:l.jsx(UO,{editorMode:e,collapsed:o,onToggleCollapse:()=>a(R=>!R)})}),o&&l.jsx("button",{className:Tt.reopenTab,onClick:()=>a(!1),title:"Show outline",type:"button",children:"›"}),l.jsx("main",{className:Tt.editor,role:"main","aria-label":"Content editor",children:l.jsx(XT,{editorMode:e,onToolbarEvent:N})}),l.jsx("aside",{className:[Tt.dock,c?Tt.dockHidden:""].filter(Boolean).join(" "),"aria-label":"Content library","aria-hidden":c,children:l.jsx(hR,{editorMode:e,collapsed:c,onToggleCollapse:()=>d(R=>!R)})}),c&&l.jsx("button",{className:Tt.dockReopenTab,onClick:()=>d(!1),title:"Show library",type:"button",children:"‹"})]})]}),l.jsx(Zm,{dropAnimation:null,children:s?l.jsx("div",{className:Tt.dragChip,children:l.jsx("span",{className:Tt.dragChipLabel,children:s.name})}):null}),u&&l.jsx(mw,{onSave:A,onDiscard:U,onCancel:()=>f(!1),isSaving:x})]})},jR="v1";function RR(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 Fu(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:RR(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 br(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(Fu(o,s))}else n.code&&r.push(Fu(n));return r}function kR(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 AR(e,t,r="Collection",n=jR){var d,u;const i=(u=(d=(await Me.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:br(o.create),unitForm:br(o.unitMetadata),childForm:br(o.childMetadata),searchForm:br(o.search??o.searchConfig),relationalForm:br(o.relationalMetadata),publishChecklist:br(o.publishchecklist),reviewChecklist:br(o.review),rfcChecklist:br(o.requestforchangeschecklist),schemaDefaults:kR(a.schema),frameworkMetadata:c.frameworkMetadata??{},sourcingSettings:c.sourcingSettings??{}}}function PR({config:e,onError:t}){const[r,n]=p.useState(!0),[s,i]=p.useState(null),[o,a]=p.useState(!1),{setEditorConfig:c,setEditorMode:d,setCategoryDefinition:u}=ue(),{setTreeData:f,selectNode:m}=Re();return p.useEffect(()=>{let g=!1;async function _(){var h,y;try{n(!0),i(null),e.apiBaseUrl&&Of(e.apiBaseUrl),c(e),d(e.config.mode);const v=e.context.contentId??e.context.identifier??"";if(v){const{rootNode:b}=await If(v);g||(f(b?[b]:[]),b&&m(b.id));const x=e.config.primaryCategory??"Course",w=e.context.channel??"",C=e.config.categoryDefinitionApiVersion??"v1";try{const D=await AR(x,w,e.config.objectType??"Collection",C);if(!g){u(D);const j=((h=D.sourcingSettings)==null?void 0:h.collection)??{},k={};j.maxDepth&&!e.config.maxDepth&&(k.maxDepth=j.maxDepth),j.children&&!e.config.children&&(k.children=j.children),j.hierarchy&&!((y=e.config.hierarchy)!=null&&y.level1)&&(k.hierarchy={...e.config.hierarchy??{},...j.hierarchy}),Object.keys(k).length>0&&c({...e,config:{...e.config,...k}})}}catch{}}g||a(!0)}catch(v){if(!g){const b=v instanceof Error?v:new Error(String(v));i(b),t==null||t(b)}}finally{g||n(!1)}}return _(),()=>{g=!0}},[e.context.contentId,e.context.identifier]),{isLoading:r,error:s,isReady:o}}const MR="_root_qcpw6_1",LR="_loadingState_qcpw6_10",FR="_loadingSpinner_qcpw6_20",$R="_errorState_qcpw6_34",os={root:MR,loadingState:LR,loadingSpinner:FR,errorState:$R},BR=new xp({defaultOptions:{queries:{retry:1,refetchOnWindowFocus:!1}}});class UR extends p.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:os.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 VR(e){const{isLoading:t,error:r}=PR({config:e,onError:e.onError}),n=ue(s=>s.editorMode);return t?l.jsxs("div",{className:os.loadingState,children:[l.jsx("div",{className:os.loadingSpinner}),l.jsx("p",{children:"Loading editor..."})]}):r?l.jsxs("div",{className:os.errorState,children:[l.jsx("h3",{children:"Failed to load editor"}),l.jsx("p",{children:r.message})]}):l.jsx("div",{className:`sb-split-builder ${os.root}`,children:l.jsx(TR,{editorMode:n,onToolbarEvent:e.onToolbarEvent,onContentAdded:e.onContentAdded,onHierarchySaved:e.onHierarchySaved})})}const Gh=e=>l.jsx(UR,{onError:e.onError,children:l.jsxs(Cp,{client:BR,children:[l.jsx(VR,{...e}),l.jsx(Sg,{position:"top-right",toastOptions:{duration:3e3}})]})}),Pi=Symbol.for("r2wc.reactRender"),$u=Symbol.for("r2wc.shouldRender"),ti=Symbol.for("r2wc.root");function zR(e=""){return e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}function qR(e=""){return e.replace(/-([a-z0-9])/g,function(t){return t[1].toUpperCase()})}var Bu={expando:function(e,t,r){Object.defineProperty(e,t,{enumerable:!0,get:function(){return r},set:function(n){r=n,this[Pi]()}}),e[Pi]()}};function HR(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,m){return i&&(s[u]=!0),typeof u=="symbol"||s[u]||u in d?(e.propTypes&&u in e.propTypes&&Bu.expando(m,u,f),Reflect.set(d,u,f,m)):(Bu.expando(m,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[$u]=!0,this[Pi]()},a.disconnectedCallback=function(){typeof r.createRoot=="function"?this[ti].unmount():r.unmountComponentAtNode(this)},a[Pi]=function(){if(this[$u]===!0){var d={};Object.keys(this).forEach(function(m){s[m]!==!1&&(d[m]=this[m])},this),i=!0;const u=n.shadow?this.shadowRoot:this,f=t.createElement(e,d);typeof r.createRoot=="function"?(this[ti]||(this[ti]=r.createRoot(u)),this[ti].render(f)):r.render(f,u),i=!1}},e.propTypes&&(o.observedAttributes=n.dashStyleAttributes?Object.keys(e.propTypes).map(function(d){return zR(d)}):Object.keys(e.propTypes),a.attributeChangedCallback=function(d,u,f){var m=n.dashStyleAttributes?qR(d):d;this[m]=f}),o}var as={},ns=Rr;if(process.env.NODE_ENV==="production")as.createRoot=ns.createRoot,as.hydrateRoot=ns.hydrateRoot;else{var ri=ns.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;as.createRoot=function(e,t){ri.usingClientEntryPoint=!0;try{return ns.createRoot(e,t)}finally{ri.usingClientEntryPoint=!1}},as.hydrateRoot=function(e,t,r){ri.usingClientEntryPoint=!0;try{return ns.hydrateRoot(e,t,r)}finally{ri.usingClientEntryPoint=!1}}}function WR(){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 KR(e="sb-collection-editor"){if(WR(),typeof customElements>"u"||customElements.get(e))return;const t=HR(Gh,p,as,{});customElements.define(e,t)}exports.CollectionEditor=Gh;exports.registerCollectionEditor=KR;exports.setApiBaseUrl=Of;exports.useEditorStore=ue;exports.useLibraryStore=Kh;exports.useTreeStore=Re;
466
+ Use the data prop if you want to provide your own handlers.`);if(e.initialData){const[t,r]=C1(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=O1(e);return l.jsxs(g1,{treeProps:r,imperativeHandle:t,children:[l.jsx(y1,{children:l.jsx(v1,{})}),l.jsx(b1,{})]})}const D1=p.forwardRef(E1);function dl(){return Re(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 Re(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 gu={video:"#EA580C",pdf:"#DC2626",h5p:"#0D9488",scorm:"#7C3AED",audio:"#DB2777",quiz:"#16A34A",default:"#6B7280"},mu={video:"Video",pdf:"FileText",h5p:"Layers",scorm:"Package",audio:"Music",quiz:"HelpCircle",default:"File"},yu=["Course Assessment","eTextbook","Exam Question","Explanation Content","Learning Resource","Practice Question Set","SCORM Content","Teacher Resource"],N1=[{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 eo(e){const t=T1(e);return{key:t,color:gu[t]??gu.default,bgClass:`sbx-ct-sq--${t}`,badgeClass:`sbx-ct-badge--${t}`,tintClass:`sbx-ct-tint--${t}`,iconName:mu[t]??mu.default,label:t.charAt(0).toUpperCase()+t.slice(1)}}const j1="_row_i3qt2_1",R1="_grip_i3qt2_16",k1="_menuBtn_i3qt2_19",A1="_selected_i3qt2_23",P1="_title_i3qt2_28",M1="_dropTarget_i3qt2_33",L1="_toggle_i3qt2_50",F1="_ctIcon_i3qt2_65",$1="_folderIcon_i3qt2_77",B1="_renameInput_i3qt2_92",U1="_dropHere_i3qt2_101",V1="_menuWrap_i3qt2_111",z1="_menu_i3qt2_19",q1="_dangerItem_i3qt2_163",Ct={row:j1,grip:R1,menuBtn:k1,selected:A1,title:P1,dropTarget:M1,toggle:L1,ctIcon:F1,folderIcon:$1,renameInput:B1,dropHere:U1,menuWrap:V1,menu:z1,dangerItem:q1},H1={video:Qa,pdf:za,h5p:qa,scorm:Wa,audio:Ha,quiz:Va,default:Vn},W1=({node:e,style:t,dragHandle:r,editorMode:n})=>{const[s,i]=p.useState(!1),[o,a]=p.useState(!1),[c,d]=p.useState(e.data.name),u=p.useRef(null),f=n==="edit",m=dl(),g=eo(e.data),_=H1[g.key]??Vn,h=e.isSelected,y=e.level===0,v=e.data.isFolder??(e.children&&e.children.length>0),b=y?sy:v?cy:_;p.useEffect(()=>{if(!s)return;const C=D=>{var j;(j=u.current)!=null&&j.contains(D.target)||i(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[s]);const x=p.useCallback(()=>{c.trim()&&e.submit(c.trim()),a(!1)},[c,e]),w=p.useCallback(C=>{C.key==="Enter"&&x(),C.key==="Escape"&&(d(e.data.name),a(!1))},[x,e.data.name]);return l.jsxs("div",{className:[Ct.row,h?Ct.selected:"",e.state.isOver&&v?Ct.dropTarget:""].filter(Boolean).join(" "),style:t,onClick:()=>e.select(),"data-node-id":e.data.id,"data-droppable":v?"true":void 0,role:"treeitem","aria-selected":h,"aria-expanded":v?!e.isClosed:void 0,children:[f&&l.jsx("span",{ref:r,className:Ct.grip,"aria-hidden":"true",children:l.jsx(Hd,{size:14})}),l.jsx("button",{className:Ct.toggle,onClick:C=>{C.stopPropagation(),e.toggle()},"aria-label":e.isClosed?"Expand":"Collapse",style:{visibility:v?"visible":"hidden"},children:e.isClosed?l.jsx(Ud,{size:14}):l.jsx(ks,{size:14})}),l.jsx("span",{className:`${Ct.ctIcon} ${y||v?Ct.folderIcon:g.bgClass}`,"aria-hidden":"true",children:l.jsx(b,{size:12})}),o?l.jsx("input",{className:Ct.renameInput,value:c,autoFocus:!0,onChange:C=>d(C.target.value),onBlur:x,onKeyDown:w,onClick:C=>C.stopPropagation()}):l.jsx("span",{className:Ct.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&&v&&l.jsx("span",{className:Ct.dropHere,"aria-hidden":"true",children:"Drop here"}),f&&l.jsxs("div",{className:Ct.menuWrap,ref:u,children:[l.jsx("button",{className:Ct.menuBtn,onClick:C=>{C.stopPropagation(),i(D=>!D)},"aria-label":"Node options",children:l.jsx(zd,{size:14})}),s&&l.jsxs("div",{className:Ct.menu,role:"menu",children:[l.jsxs("button",{role:"menuitem",onClick:()=>{a(!0),i(!1)},children:[l.jsx(gy,{size:13})," Rename"]}),v&&m&&l.jsxs("button",{role:"menuitem",onClick:()=>{e.tree.create({parentId:e.id}),i(!1)},children:[l.jsx(qd,{size:13})," Add sub-unit"]}),e.data.parent&&m&&l.jsxs("button",{role:"menuitem",onClick:()=>{e.tree.create({parentId:e.data.parent}),i(!1)},children:[l.jsx(As,{size:13})," Add Sibling"]}),l.jsxs("button",{role:"menuitem",className:Ct.dangerItem,onClick:()=>{e.tree.delete(e.id),i(!1)},children:[l.jsx(Ka,{size:13})," Delete"]})]})]})]})};async function K1(e,t){var i,o;const n=((i=(await Me.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 Q1(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 G1(e,t){var a;const r=await K1(e,t.name),n=await Q1(r,t),s=new FormData;return s.append("fileUrl",n),s.append("mimeType",t.type||"text/csv"),{processId:(((a=(await Me.post(`/action/collection/v1/import/${e}`,s)).data)==null?void 0:a.result)??{}).processId??""}}async function Y1(e){var r;return((r=(await Me.get(`/action/collection/v1/import/status/${e}`)).data)==null?void 0:r.result)??{status:"PENDING"}}async function _h(e){var n,s,i;const r=(i=(s=(n=(await Me.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 X1(e){return _h(e)}const Z1="_container_jr3ij_1",J1="_header_jr3ij_13",eO="_title_jr3ij_22",tO="_closeBtn_jr3ij_29",rO="_body_jr3ij_45",nO="_dropZone_jr3ij_54",sO="_dragOver_jr3ij_67",iO="_hasFile_jr3ij_72",oO="_hiddenInput_jr3ij_78",aO="_fileInfo_jr3ij_82",lO="_fileIcon_jr3ij_89",cO="_fileName_jr3ij_93",uO="_fileSize_jr3ij_100",dO="_dropHint_jr3ij_105",fO="_dropIcon_jr3ij_112",hO="_dropText_jr3ij_117",pO="_dropSubtext_jr3ij_124",gO="_sampleLink_jr3ij_130",mO="_statusBar_jr3ij_145",yO="_status_uploading_jr3ij_154",vO="_status_processing_jr3ij_154",bO="_status_done_jr3ij_159",_O="_status_error_jr3ij_164",wO="_successDetail_jr3ij_170",xO="_spinner_jr3ij_175",SO="_spin_jr3ij_175",CO="_errorMsg_jr3ij_191",OO="_failedSection_jr3ij_197",EO="_failedTitle_jr3ij_203",DO="_tableWrap_jr3ij_213",IO="_failedTable_jr3ij_219",NO="_reasonCell_jr3ij_244",TO="_footer_jr3ij_248",Ee={container:Z1,header:J1,title:eO,closeBtn:tO,body:rO,dropZone:nO,dragOver:sO,hasFile:iO,hiddenInput:oO,fileInfo:aO,fileIcon:lO,fileName:cO,fileSize:uO,dropHint:dO,dropIcon:fO,dropText:hO,dropSubtext:pO,sampleLink:gO,statusBar:mO,status_uploading:yO,status_processing:vO,status_done:bO,status_error:_O,successDetail:wO,spinner:xO,spin:SO,errorMsg:CO,failedSection:OO,failedTitle:EO,tableWrap:DO,failedTable:IO,reasonCell:NO,footer:TO},jO=({contentId:e,onComplete:t,onClose:r,mode:n="create"})=>{const[s,i]=p.useState(null),[o,a]=p.useState(!1),[c,d]=p.useState("idle"),[u,f]=p.useState(""),[m,g]=p.useState([]),[_,h]=p.useState(null),y=p.useRef(null),v=p.useRef(null),b=p.useCallback(()=>{v.current!==null&&(clearInterval(v.current),v.current=null)},[]);p.useEffect(()=>()=>b(),[b]);const x=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=p.useCallback(N=>{f(""),g([]),h(null),d("idle"),x(N)&&i(N)},[]),C=p.useCallback(N=>{N.preventDefault(),a(!1);const A=N.dataTransfer.files[0];A&&w(A)},[w]),D=p.useCallback(N=>{var U;const A=(U=N.target.files)==null?void 0:U[0];A&&w(A),N.target.value=""},[w]),j=p.useCallback(async()=>{try{const N=await X1(e),A=document.createElement("a");A.href=N,A.download="sample_hierarchy.csv",A.target="_blank",A.click()}catch{f("Failed to download sample CSV.")}},[e]),k=p.useCallback(async()=>{if(s){d("uploading"),f(""),g([]);try{const{processId:N}=await G1(e,s);if(!N){d("done"),h(null),setTimeout(t,1500);return}d("processing"),v.current=setInterval(async()=>{try{const A=await Y1(N);A.status==="COMPLETED"?(b(),d("done"),h(A.successCount??null),A.failedRecords&&A.failedRecords.length>0?g(A.failedRecords):setTimeout(t,1500)):A.status==="FAILED"&&(b(),d("error"),f("Upload processing failed. Please check the error rows below."),A.failedRecords&&g(A.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]),$={idle:"",uploading:"Uploading...",processing:"Processing...",done:"Done!",error:"Error"};return l.jsxs("div",{className:Ee.container,children:[l.jsxs("div",{className:Ee.header,children:[l.jsx("h2",{className:Ee.title,children:n==="update"?"Update Folder Metadata via CSV":"Create Folders via CSV"}),l.jsx("button",{className:Ee.closeBtn,onClick:r,"aria-label":"Close",children:"✕"})]}),l.jsxs("div",{className:Ee.body,children:[l.jsxs("div",{className:`${Ee.dropZone} ${o?Ee.dragOver:""} ${s?Ee.hasFile:""}`,onDragEnter:N=>{N.preventDefault(),a(!0)},onDragOver:N=>{N.preventDefault(),a(!0)},onDragLeave:N=>{N.preventDefault(),a(!1)},onDrop:C,onClick:()=>{var N;return(N=y.current)==null?void 0:N.click()},role:"button",tabIndex:0,"aria-label":"Drop CSV file here or click to browse",onKeyDown:N=>{var A;return N.key==="Enter"&&((A=y.current)==null?void 0:A.click())},children:[l.jsx("input",{ref:y,type:"file",accept:".csv",className:Ee.hiddenInput,onChange:D,"aria-hidden":"true"}),s?l.jsxs("div",{className:Ee.fileInfo,children:[l.jsx("span",{className:Ee.fileIcon,children:"📄"}),l.jsx("span",{className:Ee.fileName,children:s.name}),l.jsxs("span",{className:Ee.fileSize,children:["(",(s.size/1024).toFixed(1)," KB)"]})]}):l.jsxs("div",{className:Ee.dropHint,children:[l.jsx("span",{className:Ee.dropIcon,children:"⬆️"}),l.jsx("p",{className:Ee.dropText,children:"Drag & drop your CSV here"}),l.jsx("p",{className:Ee.dropSubtext,children:"or click to browse"})]})]}),l.jsx("button",{className:Ee.sampleLink,onClick:j,type:"button",children:"Download Sample CSV"}),c!=="idle"&&l.jsxs("div",{className:`${Ee.statusBar} ${Ee[`status_${c}`]}`,role:"status","aria-live":"polite",children:[c==="processing"&&l.jsx("span",{className:Ee.spinner,"aria-hidden":"true"}),$[c],c==="done"&&_!==null&&l.jsxs("span",{className:Ee.successDetail,children:[" — ",_," item(s) imported"]})]}),u&&l.jsx("p",{className:Ee.errorMsg,role:"alert",children:u}),m.length>0&&l.jsxs("div",{className:Ee.failedSection,children:[l.jsxs("h4",{className:Ee.failedTitle,children:["Failed Rows (",m.length,")"]}),l.jsx("div",{className:Ee.tableWrap,children:l.jsxs("table",{className:Ee.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:m.map((N,A)=>l.jsxs("tr",{children:[l.jsx("td",{children:N.rowNumber??A+1}),l.jsx("td",{children:N.name??"—"}),l.jsx("td",{className:Ee.reasonCell,children:N.reason??"Unknown error"})]},A))})]})})]})]}),l.jsxs("div",{className:Ee.footer,children:[l.jsx(Ie,{variant:"ghost",onClick:r,disabled:c==="uploading"||c==="processing",children:"Cancel"}),l.jsx(Ie,{variant:"primary",isLoading:c==="uploading"||c==="processing",disabled:!s||c==="done",onClick:k,children:c==="done"?"Uploaded":"Upload"})]})]})},RO="_container_1y30m_1",kO="_header_1y30m_8",AO="_headerActions_1y30m_19",PO="_iconBtn_1y30m_25",MO="_menuWrap_1y30m_43",LO="_dropdownMenu_1y30m_47",FO="_treeWrapper_1y30m_79",$O="_csvModal_1y30m_95",BO="_footer_1y30m_105",er={container:RO,header:kO,headerActions:AO,iconBtn:PO,menuWrap:MO,dropdownMenu:LO,treeWrapper:FO,csvModal:$O,footer:BO},UO=({editorMode:e,collapsed:t=!1,onToggleCollapse:r})=>{var be;const n=p.useRef(null),s=p.useRef(null),i=p.useRef(null),[o,a]=p.useState(400),[c,d]=p.useState(!1),[u,f]=p.useState(!1),[m,g]=p.useState("create"),{treeData:_,selectedNodeId:h,selectNode:y,addNode:v,deleteNode:b,reorderChildren:x,moveNode:w,setTreeData:C}=Re(),D=e==="edit",j=dl(),k=D&&j,$=(((be=_[0])==null?void 0:be.children)??[]).some(K=>K.isFolder),N=ue(K=>{var M,G,P,Y;return((G=(M=K.editorConfig)==null?void 0:M.context)==null?void 0:G.contentId)??((Y=(P=K.editorConfig)==null?void 0:P.context)==null?void 0:Y.identifier)??""}),A=ue(K=>{var G,P;const M=(P=(G=K.categoryMeta)==null?void 0:G.sourcingSettings)==null?void 0:P.collection;return(M==null?void 0:M.enableBulkUpload)!==!1});p.useEffect(()=>{const K=s.current;if(!K)return;const M=new ResizeObserver(()=>{a(K.clientHeight||400)});return M.observe(K),a(K.clientHeight||400),()=>M.disconnect()},[]),p.useEffect(()=>{if(!c)return;const K=M=>{var G;(G=i.current)!=null&&G.contains(M.target)||d(!1)};return document.addEventListener("mousedown",K),()=>document.removeEventListener("mousedown",K)},[c]);const U=p.useCallback(K=>{K.length>0&&y(K[0].data.id)},[y]),R=p.useCallback(({parentId:K,index:M,dragIds:G})=>{if(!K)return;const P=G[0],Y=Oa(_,P);if(!Y)return;const W=Y.parent;if(W===K){const oe=Oa(_,K);if(!(oe!=null&&oe.children))return;const pe=oe.children.findIndex(Ne=>Ne.id===P);if(pe<0)return;x(K,pe,M>pe?M-1:M)}else w(P,W??"",K)},[_,x,w]),B=p.useCallback(({ids:K})=>{K.forEach(M=>b(M))},[b]),F=p.useCallback(({parentId:K})=>{var P;const M=K??((P=_[0])==null?void 0:P.id)??"";if(!M)return{id:crypto.randomUUID()};const G=v(M,"unit");return G?{id:G}:(Se.error("Maximum depth reached"),{id:crypto.randomUUID()})},[v,_]),J=p.useCallback(()=>{var M;const K=(M=_[0])==null?void 0:M.id;K&&(v(K,"unit")||Se.error("Maximum depth reached"))},[_,v]),ie=p.useCallback(()=>{h&&(v(h,"subunit")||Se.error("Maximum depth reached"))},[h,v]),me=p.useCallback(async()=>{if(d(!1),!!N)try{const K=await _h(N),M=await fetch(K).then(Y=>Y.blob()),G=URL.createObjectURL(M),P=document.createElement("a");P.href=G,P.download=`${N}-folders.csv`,P.style.display="none",document.body.appendChild(P),P.click(),document.body.removeChild(P),URL.revokeObjectURL(G)}catch{Se.error("Failed to download CSV")}},[N]),ve=p.useCallback(async()=>{if(f(!1),!!N)try{const{rootNode:K}=await If(N);C([K]),Se.success("Course outline refreshed.")}catch{Se.error("Outline could not be refreshed automatically. Please reload the page.")}},[N,C]);return l.jsxs("div",{className:er.container,children:[l.jsx("div",{className:er.header,children:l.jsxs("div",{className:er.headerActions,children:[D&&l.jsxs("div",{className:er.menuWrap,ref:i,children:[l.jsx("button",{type:"button",className:er.iconBtn,onClick:()=>d(K=>!K),"aria-label":"More options",title:"More options","aria-haspopup":"true","aria-expanded":c,children:l.jsx(zd,{size:15})}),c&&l.jsx("div",{className:er.dropdownMenu,role:"menu",children:A&&l.jsxs(l.Fragment,{children:[l.jsx("button",{role:"menuitem",type:"button",disabled:$,title:$?'Folders already exist — use "Update" instead':void 0,onClick:()=>{d(!1),g("create"),f(!0)},children:"Create folders using csv file"}),l.jsx("button",{role:"menuitem",type:"button",disabled:!$,title:$?void 0:'No folders yet — use "Create" first',onClick:me,children:"Download folders as csv file"}),l.jsx("button",{role:"menuitem",type:"button",disabled:!$,title:$?void 0:'No folders yet — use "Create" first',onClick:()=>{d(!1),g("update"),f(!0)},children:"Update folder metadata using csv file"})]})})]}),r&&l.jsx("button",{type:"button",className:er.iconBtn,onClick:r,"aria-label":t?"Expand outline":"Collapse outline",title:t?"Expand outline":"Collapse outline",children:t?l.jsx(hy,{size:15}):l.jsx(fy,{size:15})})]})}),l.jsx("div",{className:er.treeWrapper,ref:s,children:l.jsx(D1,{ref:n,data:_,idAccessor:"id",childrenAccessor:"children",onSelect:U,onMove:D?R:void 0,onDelete:D?B:void 0,onCreate:D?F:void 0,disableEdit:!D,disableDrop:!D,selection:h??void 0,rowHeight:40,indent:20,paddingBottom:16,height:o,width:"100%",children:K=>l.jsx(W1,{...K,editorMode:e})})}),D&&l.jsxs("div",{className:er.footer,children:[l.jsxs(Ie,{variant:"ghost",size:"sm",onClick:J,disabled:!k,children:[l.jsx(As,{size:14})," Add Unit"]}),l.jsxs(Ie,{variant:"ghost",size:"sm",onClick:ie,disabled:!k||!h,children:[l.jsx(qd,{size:14})," Add Sub-unit"]})]}),u&&l.jsx("div",{className:er.csvModal,children:l.jsx(jO,{contentId:N,mode:m,onComplete:ve,onClose:()=>f(!1)})})]})};function Oa(e,t){for(const r of e){if(r.id===t)return r;if(r.children){const n=Oa(r.children,t);if(n)return n}}}const VO="_breadcrumb_zd1aj_1",zO="_crumb_zd1aj_10",qO="_sep_zd1aj_26",HO="_current_zd1aj_31",Zn={breadcrumb:VO,crumb:zO,sep:qO,current:HO},WO=({crumbs:e})=>{const t=Re(r=>r.selectNode);return e.length?l.jsxs("nav",{className:Zn.breadcrumb,"aria-label":"Node path",children:[l.jsx("button",{className:Zn.crumb,onClick:()=>t(e[0].id),"aria-label":"Home",children:l.jsx(uy,{size:13})}),e.map((r,n)=>l.jsxs(p.Fragment,{children:[l.jsx(Ud,{size:13,className:Zn.sep}),n<e.length-1?l.jsx("button",{className:Zn.crumb,onClick:()=>t(r.id),children:r.name}):l.jsx("span",{className:Zn.current,children:r.name})]},r.id))]}):null},KO="_tabBar_qhks1_1",QO="_tab_qhks1_1",GO="_active_qhks1_29",YO="_error_qhks1_35",XO="_errorDot_qhks1_39",Jn={tabBar:KO,tab:QO,active:GO,error:YO,errorDot:XO},vu=[{id:"details",label:"Details"},{id:"audience",label:"Audience & Curriculum"},{id:"licensing",label:"Licensing"}],ZO=({activeTab:e,onChange:t,errorTabs:r=[],visibleTabs:n})=>{const s=n?vu.filter(i=>n.includes(i.id)):vu;return l.jsx("div",{className:Jn.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:[Jn.tab,e===i.id?Jn.active:"",r.includes(i.id)?Jn.error:""].join(" "),onClick:()=>t(i.id),children:[i.label,r.includes(i.id)&&l.jsx("span",{className:Jn.errorDot,"aria-label":"Has errors"})]},i.id))})};var $s=e=>e.type==="checkbox",zr=e=>e instanceof Date,st=e=>e==null;const wh=e=>typeof e=="object";var Be=e=>!st(e)&&!Array.isArray(e)&&wh(e)&&!zr(e),Ea=e=>Be(e)&&e.target?$s(e.target)?e.target.checked:e.target.value:e,xh=(e,t)=>t.split(".").some((r,n,s)=>!isNaN(Number(r))&&e.has(s.slice(0,n).join("."))),Sh=e=>{const t=e.constructor&&e.constructor.prototype;return Be(t)&&t.hasOwnProperty("isPrototypeOf")},to=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function Ue(e){if(e instanceof Date)return new Date(e);const t=typeof FileList<"u"&&e instanceof FileList;if(to&&(e instanceof Blob||t))return e;const r=Array.isArray(e);if(!r&&!(Be(e)&&Sh(e)))return e;const n=r?[]:Object.create(Object.getPrototypeOf(e));for(const s in e)Object.prototype.hasOwnProperty.call(e,s)&&(n[s]=Ue(e[s]));return n}const Sr={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change",SUBMIT:"submit",TRIGGER:"trigger",VALID:"valid"},Wt={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},qt={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"},Ao="form",Ch="root",Oh=["__proto__","constructor","prototype"];var Bs=e=>/^\w*$/.test(e),Ae=e=>e===void 0,ro=e=>e.split(/[.[\]'"]/g).filter(Boolean),H=(e,t,r)=>{if(!t||!Be(e))return r;const n=Bs(t)?[t]:ro(t);if(n.some(i=>Oh.includes(i)))return r;const s=n.reduce((i,o)=>st(i)?void 0:i[o],e);return Ae(s)||s===e?Ae(e[t])?r:e[t]:s},kt=e=>typeof e=="boolean",gt=e=>typeof e=="function",je=(e,t,r)=>{let n=-1;const s=Bs(t)?[t]:ro(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=Be(d)||Array.isArray(d)?d:isNaN(+s[n+1])?{}:[]}if(Oh.includes(a))return;e[a]=c,e=e[a]}};const fl=p.createContext(null);fl.displayName="HookFormControlContext";const hl=()=>p.useContext(fl);var Eh=(e,t,r,n=!0)=>{const s={};for(const i in e)Object.defineProperty(s,i,{get:()=>{const o=i;return t._proxyFormState[o]!==Wt.all&&(t._proxyFormState[o]=!n||Wt.all),r&&(r[o]=!0),e[o]}});return s};const pl=to?p.useLayoutEffect:p.useEffect;function JO(e){const t=hl(),{control:r=t,disabled:n,name:s,exact:i}=e||{},[o,a]=p.useState(()=>({...r._formState,defaultValues:r._defaultValues})),c=p.useRef({isDirty:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,validatingFields:!1,isValidating:!1,isValid:!1,errors:!1});return pl(()=>r._subscribe({name:s,formState:c.current,exact:i,callback:d=>{!n&&a({...r._formState,...d,defaultValues:r._defaultValues})}}),[s,n,i]),p.useEffect(()=>{c.current.isValid&&r._setValid(!0)},[r]),p.useMemo(()=>Eh(o,r,c.current,!1),[o,r])}var mt=e=>typeof e=="string",Da=(e,t,r,n,s)=>mt(e)?(n&&t.watch.add(e),H(r,e,s)):Array.isArray(e)?e.map(i=>(n&&t.watch.add(i),H(r,i))):(n&&(t.watchAll=!0),r),Ia=e=>st(e)||!wh(e);const bu=(e,t)=>t.length===0&&!Array.isArray(e)&&!Sh(e);function At(e,t,r=new WeakMap){if(e===t)return!0;if(Ia(e)||Ia(t))return Object.is(e,t);if(zr(e)&&zr(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(bu(e,n)||bu(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(zr(a)&&zr(c)||(Be(a)||Array.isArray(a))&&(Be(c)||Array.isArray(c))?!At(a,c,r):!Object.is(a,c))return!1}}return!0}function eE(e){const t=hl(),{control:r=t,name:n,defaultValue:s,disabled:i,exact:o,compute:a}=e||{},c=p.useRef(s),d=p.useRef(a),u=p.useRef(void 0),f=p.useRef(r),m=p.useRef(n);d.current=a;const[g,_]=p.useState(()=>{const w=r._getWatch(n,c.current);return d.current?d.current(w):w}),h=p.useCallback(w=>{const C=Da(n,r._names,w||r._formValues,!1,c.current);return d.current?d.current(C):C},[r._formValues,r._names,n]),y=p.useCallback(w=>{if(!i){const C=Da(n,r._names,w||r._formValues,!1,c.current);if(d.current){const D=d.current(C);At(D,u.current)||(_(D),u.current=D)}else _(C)}},[r._formValues,r._names,i,n]);pl(()=>((f.current!==r||!At(m.current,n))&&(f.current=r,m.current=n,y()),r._subscribe({name:n,formState:{values:!0},exact:o,callback:w=>{y(w.values)}})),[r,o,n,y]),p.useEffect(()=>r._removeUnmounted());const v=f.current!==r,b=m.current,x=p.useMemo(()=>{if(i)return null;const w=!v&&!At(b,n);return v||w?h():null},[i,v,n,b,h]);return x!==null?x:g}function no(e){const t=hl(),{name:r,disabled:n,control:s=t,shouldUnregister:i,defaultValue:o,exact:a=!0}=e,c=xh(s._names.array,r),d=p.useMemo(()=>H(s._formValues,r,H(s._defaultValues,r,o)),[s,r,o]),u=eE({control:s,name:r,defaultValue:d,exact:a}),f=JO({control:s,name:r,exact:a}),m=p.useRef(e),g=p.useRef(null),_=p.useRef(s.register(r,{...e.rules,value:u,...kt(e.disabled)?{disabled:e.disabled}:{}}));m.current=e;const h=p.useMemo(()=>Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!H(f.errors,r)},isDirty:{enumerable:!0,get:()=>!!H(f.dirtyFields,r)},isTouched:{enumerable:!0,get:()=>!!H(f.touchedFields,r)},isValidating:{enumerable:!0,get:()=>!!H(f.validatingFields,r)},error:{enumerable:!0,get:()=>H(f.errors,r)}}),[f,r]),y=p.useCallback(w=>{const C=Ea(w);return H(s._fields,r)||(_.current=s.register(r,{...m.current.rules,value:C})),_.current.onChange({target:{value:Ea(w),name:r},type:Sr.CHANGE})},[r,s]),v=p.useCallback(()=>_.current.onBlur({target:{value:H(s._formValues,r),name:r},type:Sr.BLUR}),[r,s._formValues]),b=p.useCallback(w=>{w&&(g.current={focus:()=>gt(w.focus)&&w.focus(),select:()=>gt(w.select)&&w.select(),setCustomValidity:D=>gt(w.setCustomValidity)&&w.setCustomValidity(D),reportValidity:()=>gt(w.reportValidity)&&w.reportValidity()});const C=H(s._fields,r);C&&C._f&&w&&(C._f.ref=g.current)},[s._fields,r]),x=p.useMemo(()=>({name:r,value:u,...kt(n)||f.disabled?{disabled:f.disabled||n}:{},onChange:y,onBlur:v,ref:b}),[r,n,f.disabled,y,v,b,u]);return p.useEffect(()=>{const w=s._options.shouldUnregister||i;s.register(r,{...m.current.rules,...kt(m.current.disabled)?{disabled:m.current.disabled}:{}});const C=(D,j)=>{const k=H(s._fields,D);k&&k._f&&(k._f.mount=j)};if(C(r,!0),w){const D=Ue(H(i?s._defaultValues:s._options.values||s._defaultValues,r,H(s._options.defaultValues,r,m.current.defaultValue)));je(s._defaultValues,r,D),Ae(H(s._formValues,r))&&je(s._formValues,r,D)}if(!c&&s.register(r),g.current){const D=H(s._fields,r);D&&D._f&&(D._f.ref=g.current)}return()=>{(c?w&&!s._state.action:w)?s.unregister(r):C(r,!1)}},[r,s,c,i]),p.useEffect(()=>{s._setDisabledField({disabled:n,name:r})},[n,r,s]),p.useMemo(()=>({field:x,formState:f,fieldState:h}),[x,f,h])}const gl=p.createContext(null);gl.displayName="HookFormContext";const Yt=()=>p.useContext(gl),tE=({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:m,unregister:g,control:_,register:h,setFocus:y,subscribe:v})=>{const b=p.useMemo(()=>({watch:t,getValues:r,getFieldState:n,setError:s,clearErrors:i,setValue:o,setValues:a,trigger:c,formState:d,resetField:u,reset:f,handleSubmit:m,unregister:g,control:_,register:h,setFocus:y,subscribe:v}),[i,_,d,n,r,m,h,f,u,s,y,o,a,v,c,g,t]);return p.createElement(gl.Provider,{value:b},p.createElement(fl.Provider,{value:b.control},e))};var rE=(e,t,r,n,s)=>t?{...r[e],types:{...r[e]&&r[e].types?r[e].types:{},[n]:s||!0}}:{},Dh=e=>Array.isArray(e)?e.filter(Boolean):[],vi=e=>Array.isArray(e)?e:[e],_u=()=>{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 Ih(e,t){const r={};for(const n in e)if(e.hasOwnProperty(n)){const s=e[n],i=t[n];if(s&&Be(s)&&i){const o=Ih(s,i);Be(o)&&(r[n]=o)}else e[n]&&(r[n]=i)}return r}var Je=e=>Be(e)&&!Object.keys(e).length,ml=e=>e.type==="file",Ri=e=>{if(!to)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},Nh=e=>e.type==="select-multiple",yl=e=>e.type==="radio",nE=e=>yl(e)||$s(e),Po=e=>Ri(e)&&e.isConnected;function sE(e,t){const r=t.slice(0,-1).length;let n=0;for(;n<r;){if(st(e)){e=void 0;break}e=e[t[n]],n++}return e}function iE(e){for(const t in e)if(e.hasOwnProperty(t)&&!Ae(e[t]))return!1;return!0}function Ke(e,t){if(mt(t)&&Object.prototype.hasOwnProperty.call(e,t))return delete e[t],e;const r=Array.isArray(t)?t:Bs(t)?[t]:ro(t),n=r.length===1?e:sE(e,r),s=r.length-1,i=r[s];return n&&delete n[i],s!==0&&(Be(n)&&Je(n)||Array.isArray(n)&&iE(n))&&Ke(e,r.slice(0,-1)),e}var oE=e=>{for(const t in e)if(gt(e[t]))return!0;return!1};function Th(e){return Array.isArray(e)||Be(e)&&!oE(e)}function Na(e,t={}){for(const r in e){const n=e[r];Th(n)?(t[r]=Array.isArray(n)?[]:{},Na(n,t[r])):Ae(n)||(t[r]=!0)}return t}function Ta(e){if(e!==!1){if(e===!0)return!0;if(Array.isArray(e)){const t=e.map(r=>Ta(r));return t.some(r=>r!==void 0)?t:void 0}if(Be(e)){const t={};for(const r in e){const n=Ta(e[r]);Ae(n)||(t[r]=n)}return Object.keys(t).length?t:void 0}}}function $r(e,t,r){r||(r=Na(t));for(const n in e){const s=e[n];if(Th(s))Ae(t)||Ia(r[n])?r[n]=Na(s,Array.isArray(s)?[]:{}):$r(s,st(t)?{}:t[n],r[n]);else{const i=t[n];r[n]=!At(s,i)}}return Ta(r)||{}}const wu={value:!1,isValid:!1},xu={value:!0,isValid:!0};var jh=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&&!Ae(e[0].attributes.value)?Ae(e[0].value)||e[0].value===""?xu:{value:e[0].value,isValid:!0}:xu:wu}return wu},Rh=(e,{valueAsNumber:t,valueAsDate:r,setValueAs:n})=>Ae(e)?e:t?e===""?NaN:e&&+e:r&&mt(e)?new Date(e):n?n(e):e;const Su={isValid:!1,value:null};var kh=e=>Array.isArray(e)?e.reduce((t,r)=>r&&r.checked&&!r.disabled?{isValid:!0,value:r.value}:t,Su):Su;function Cu(e){const t=e.ref;return ml(t)?t.files:yl(t)?kh(e.refs).value:Nh(t)?[...t.selectedOptions].map(({value:r})=>r):$s(t)?jh(e.refs).value:Rh(Ae(t.value)?e.ref.value:t.value,e)}var aE=(e,t,r,n)=>{const s={};for(const i of e){const o=H(t,i);o&&je(s,i,o._f)}return{criteriaMode:r,names:[...e],fields:s,shouldUseNativeValidation:n}},ki=e=>e instanceof RegExp,es=e=>Ae(e)?e:ki(e)?e.source:Be(e)?ki(e.value)?e.value.source:e.value:e,Ou=e=>({isOnSubmit:!e||e===Wt.onSubmit,isOnBlur:e===Wt.onBlur,isOnChange:e===Wt.onChange,isOnAll:e===Wt.all,isOnTouch:e===Wt.onTouched});const Eu="AsyncFunction";var lE=e=>!!e&&!!e.validate&&!!(gt(e.validate)&&e.validate.constructor.name===Eu||Be(e.validate)&&Object.values(e.validate).find(t=>t.constructor.name===Eu)),cE=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate),Mo=(e,t,r)=>!r&&(t.watchAll||t.watch.has(e)||[...t.watch].some(n=>e.startsWith(`${n}.`)));const fs=(e,t,r,n)=>{for(const s of r||Object.keys(e)){const i=H(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(fs(a,t))break}else if(Be(a)&&fs(a,t))break}}};function Du(e,t,r){const n=H(e,r);if(n||Bs(r))return{error:n,name:r};const s=r.split(".");for(;s.length;){const i=s.join("."),o=H(t,i),a=H(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 uE=(e,t,r,n)=>{r(e);const{name:s,...i}=e;return Je(i)||n&&Object.keys(i).length>=Object.keys(t).length||Object.keys(i).find(o=>t[o]===(!n||Wt.all))},dE=(e,t,r)=>!e||!t||e===t||vi(e).some(n=>n&&(r?n===t:n.startsWith(t)||t.startsWith(n))),fE=(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,hE=(e,t)=>!Dh(H(e,t)).length&&Ke(e,t),Iu=(e,t,r)=>{const n=H(e,r),s=Array.isArray(n)?n:[];return je(s,Ch,t[r]),je(e,r,s),e};function Nu(e,t,r="validate"){if(mt(e)||Array.isArray(e)&&e.every(mt)||kt(e)&&!e)return{type:r,message:mt(e)?e:"",ref:t}}var mn=e=>Be(e)&&!ki(e)?e:{value:e,message:""},Tu=async(e,t,r,n,s,i)=>{const{ref:o,refs:a,required:c,maxLength:d,minLength:u,min:f,max:m,pattern:g,validate:_,name:h,valueAsNumber:y,mount:v}=e._f,b=H(r,h);if(!v||t.has(h))return{};const x=a?a[0]:o,w=U=>{if(s&&x.reportValidity){const R=kt(U)?"":U||"";a?a.forEach(B=>B.setCustomValidity(R)):x.setCustomValidity(R),x.reportValidity()}},C={},D=yl(o),j=$s(o),k=D||j,$=(y||ml(o))&&Ae(o.value)&&Ae(b)||Ri(o)&&o.value===""||b===""||Array.isArray(b)&&!b.length,N=rE.bind(null,h,n,C),A=(U,R,B,F=qt.maxLength,J=qt.minLength)=>{const ie=U?R:B;C[h]={type:U?F:J,message:ie,ref:o,...N(U?F:J,ie)}};if(i?!Array.isArray(b)||!b.length:c&&(!k&&($||st(b))||kt(b)&&!b||j&&!jh(a).isValid||D&&!kh(a).isValid)){const{value:U,message:R}=mt(c)?{value:!!c,message:c}:mn(c);if(U&&(C[h]={type:qt.required,message:R,ref:x,...N(qt.required,R)},!n))return w(R),C}if(!$&&(!st(f)||!st(m))){let U,R;const B=mn(m),F=mn(f);if(!st(b)&&!isNaN(b)){const J=o.valueAsNumber||b&&+b;st(B.value)||(U=J>B.value),st(F.value)||(R=J<F.value)}else{const J=o.valueAsDate||new Date(b),ie=be=>new Date(new Date().toDateString()+" "+be),me=o.type=="time",ve=o.type=="week";mt(B.value)&&b&&(U=me?ie(b)>ie(B.value):ve?b>B.value:J>new Date(B.value)),mt(F.value)&&b&&(R=me?ie(b)<ie(F.value):ve?b<F.value:J<new Date(F.value))}if((U||R)&&(A(!!U,B.message,F.message,qt.max,qt.min),!n))return w(C[h].message),C}if((d||u)&&!$&&(mt(b)||i&&Array.isArray(b))){const U=mn(d),R=mn(u),B=!st(U.value)&&b.length>+U.value,F=!st(R.value)&&b.length<+R.value;if((B||F)&&(A(B,U.message,R.message),!n))return w(C[h].message),C}if(g&&!$&&mt(b)){const{value:U,message:R}=mn(g);if(ki(U)&&!b.match(U)&&(C[h]={type:qt.pattern,message:R,ref:o,...N(qt.pattern,R)},!n))return w(R),C}if(_){if(gt(_)){const U=await _(b,r),R=Nu(U,x);if(R&&(C[h]={...R,...N(qt.validate,R.message)},!n))return w(R.message),C}else if(Be(_)){let U={};for(const R in _){if(!Je(U)&&!n)break;const B=Nu(await _[R](b,r),x,R);B&&(U={...B,...N(R,B.message)},w(B.message),n&&(C[h]=U))}if(!Je(U)&&(C[h]={ref:x,...U},!n))return C}}return w(!0),C};const pE={mode:Wt.onSubmit,reValidateMode:Wt.onChange,shouldFocusError:!0},Ah={submitCount:0,isDirty:!1,isReady:!1,isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{}};function gE(e={}){let t={...pE,...e},r={...Ue(Ah),isLoading:gt(t.defaultValues),errors:t.errors||{},disabled:t.disabled||!1},n={},s=Be(t.defaultValues)||Be(t.values)?Ue(t.defaultValues||t.values)||{}:{},i=t.shouldUnregister?{}:Ue(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 m={...f};const g={array:_u(),state:_u()},_=t.criteriaMode===Wt.all,h=S=>I=>{clearTimeout(d),d=setTimeout(S,I)},y=async S=>{if(!o.keepIsValid&&!t.disabled&&(f.isValid||m.isValid||S)){let I;t.resolver?(I=Je((await N()).errors),v()):I=await R({fields:n,onlyCheckValid:!0,eventType:Sr.VALID}),I!==r.isValid&&g.state.next({isValid:I})}},v=(S,I)=>{!t.disabled&&(f.isValidating||f.validatingFields||m.isValidating||m.validatingFields)&&((S||Array.from(a.mount)).forEach(T=>{T&&(I?je(r.validatingFields,T,I):Ke(r.validatingFields,T))}),g.state.next({validatingFields:r.validatingFields,isValidating:!Je(r.validatingFields)}))},b=()=>{r.dirtyFields=$r(s,i)},x=(S,I=[],T,V,z=!0,Q=!0)=>{if(V&&T&&!t.disabled){if(o.action=!0,Q&&Array.isArray(H(n,S))){const q=T(H(n,S),V.argA,V.argB);z&&je(n,S,q)}if(Q&&Array.isArray(H(r.errors,S))){const q=T(H(r.errors,S),V.argA,V.argB);z&&je(r.errors,S,q),hE(r.errors,S)}if((f.touchedFields||m.touchedFields)&&Q&&Array.isArray(H(r.touchedFields,S))){const q=T(H(r.touchedFields,S),V.argA,V.argB);z&&je(r.touchedFields,S,q)}(f.dirtyFields||m.dirtyFields)&&b(),g.state.next({name:S,isDirty:F(S,I),dirtyFields:r.dirtyFields,errors:r.errors,isValid:r.isValid})}else je(i,S,I)},w=(S,I)=>{je(r.errors,S,I),r.errors={...r.errors},g.state.next({errors:r.errors})},C=S=>{r.errors=S,g.state.next({errors:r.errors,isValid:!1})},D=S=>{const I=Bs(S)?[S]:ro(S);let T=i,V=s;for(let z=0;z<I.length-1;z++){const Q=I[z];if(T=st(T)?T:T[Q],V=st(V)?V:V[Q],T===null&&V!==null)return!0}return!1},j=(S,I,T,V)=>{const z=H(n,S);if(z){if(D(S))return;const Q=Ae(H(i,S)),q=H(i,S,Ae(T)?H(s,S):T);Ae(q)||V&&V.defaultChecked||I?je(i,S,I?q:Cu(z._f)):me(S,q),o.mount&&!o.action&&(y(),Q&&r.isDirty&&(f.isDirty||m.isDirty)&&(F()||(r.isDirty=!1,g.state.next({...r}))),e.shouldUnregister&&Q&&!Ae(H(i,S))&&Mo(S,a)&&(o.watch=!0))}},k=(S,I,T,V,z)=>{let Q=!1,q=!1;const ee={name:S};if(!t.disabled){if(!T||V){(f.isDirty||m.isDirty)&&(q=r.isDirty,r.isDirty=ee.isDirty=F(),Q=q!==ee.isDirty);const he=At(H(s,S),I);q=!!H(r.dirtyFields,S),he!==r.isDirty?r.dirtyFields=$r(s,i):he?Ke(r.dirtyFields,S):je(r.dirtyFields,S,!0),ee.dirtyFields=r.dirtyFields,Q=Q||(f.dirtyFields||m.dirtyFields)&&q!==!he}if(T){const he=H(r.touchedFields,S);he||(je(r.touchedFields,S,T),ee.touchedFields=r.touchedFields,Q=Q||(f.touchedFields||m.touchedFields)&&he!==T)}Q&&z&&g.state.next(ee)}return Q?ee:{}},$=(S,I,T,V)=>{const z=H(r.errors,S),Q=(f.isValid||m.isValid)&&kt(I)&&r.isValid!==I;if(t.delayError&&T?(c=h(()=>w(S,T)),c(t.delayError)):(clearTimeout(d),c=null,T?je(r.errors,S,T):Ke(r.errors,S),r.errors={...r.errors}),(T?!At(z,T):z)||!Je(V)||Q){const q={...V,...Q&&kt(I)?{isValid:I}:{},errors:r.errors,name:S};r={...r,...q},g.state.next(q)}},N=async S=>(v(S,!0),await t.resolver(i,t.context,aE(S||a.mount,n,t.criteriaMode,t.shouldUseNativeValidation))),A=async S=>{const{errors:I}=await N(S);if(v(S),S){for(const T of S){const V=H(I,T);V?a.array.has(T)&&Be(V)&&!Object.keys(V).some(z=>!Number.isNaN(Number(z)))?Iu(r.errors,{[T]:V},T):je(r.errors,T,V):Ke(r.errors,T)}r.errors={...r.errors}}else r.errors=I;return I},U=async({name:S,eventType:I})=>{if(e.validate){const T=await e.validate({formValues:i,formState:r,name:S,eventType:I});if(Be(T))for(const V in T){const z=T[V];z&&Ne(`${Ao}.${V}`,{message:mt(z.message)?z.message:"",type:z.type||qt.validate})}else mt(T)||!T?Ne(Ao,{message:T||"",type:qt.validate}):pe(Ao);return T}return!0},R=async({fields:S,onlyCheckValid:I,name:T,eventType:V,context:z={valid:!0,runRootValidation:!1}})=>{if(e.validate&&(z.runRootValidation=!0,!await U({name:T,eventType:V})&&(z.valid=!1,I)))return z.valid;for(const Q in S){const q=S[Q];if(q){const{_f:ee,...he}=q;if(ee){const Fe=a.array.has(ee.name),xt=q._f&&lE(q._f),St=f.validatingFields||f.isValidating||m.validatingFields||m.isValidating;xt&&St&&v([ee.name],!0);const lr=await Tu(q,a.disabled,i,_,t.shouldUseNativeValidation&&!I,Fe);if(xt&&St&&v([ee.name]),lr[ee.name]&&(z.valid=!1,I)||(!I&&(H(lr,ee.name)?Fe?Iu(r.errors,lr,ee.name):je(r.errors,ee.name,lr[ee.name]):Ke(r.errors,ee.name)),e.shouldUseNativeValidation&&lr[ee.name]))break}!Je(he)&&await R({context:z,onlyCheckValid:I,fields:he,name:Q,eventType:V})}}return z.valid},B=()=>{for(const S of a.unMount){const I=H(n,S);I&&(I._f.refs?I._f.refs.every(T=>!Po(T)):!Po(I._f.ref))&&Le(S)}a.unMount=new Set},F=(S,I)=>!t.disabled&&(S&&I&&je(i,S,I),!At(W(),s)),J=(S,I,T)=>Da(S,a,{...o.mount?i:Ae(I)?s:mt(S)?{[S]:I}:I},T,I),ie=S=>Dh(H(o.mount?i:s,S,t.shouldUnregister?H(s,S,[]):[])),me=(S,I,T={},V=!1)=>{const z=H(n,S);let Q=I;if(z){const q=z._f;q&&(!q.disabled&&je(i,S,Rh(I,q)),Q=Ri(q.ref)&&st(I)?"":I,Nh(q.ref)?[...q.ref.options].forEach(ee=>ee.selected=Q.includes(ee.value)):q.refs?$s(q.ref)?q.refs.forEach(ee=>{(!ee.defaultChecked||!ee.disabled)&&(Array.isArray(Q)?ee.checked=!!Q.find(he=>he===ee.value):ee.checked=Q===ee.value||!!Q)}):q.refs.forEach(ee=>ee.checked=ee.value===Q):ml(q.ref)?q.ref.value="":(q.ref.value=Q,q.ref.type||g.state.next({name:S,values:V?i:Ue(i)})))}(T.shouldDirty||T.shouldTouch)&&k(S,Q,T.shouldTouch,T.shouldDirty,!0),T.shouldValidate&&Y(S)},ve=(S,I,T,V=!1)=>{for(const z in I){if(!I.hasOwnProperty(z))return;const Q=I[z],q=S+"."+z,ee=H(n,q);(a.array.has(S)||Be(Q)||ee&&!ee._f)&&!zr(Q)?ve(q,Q,T,V):me(q,Q,T,V)}},be=(S,I,T,V)=>{const z=H(n,S),Q=a.array.has(S),q=V?I:Ue(I),ee=H(i,S),he=At(ee,q);if(he||je(i,S,q),Q)g.array.next({name:S,values:V?i:Ue(i)}),(f.isDirty||f.dirtyFields||m.isDirty||m.dirtyFields)&&T.shouldDirty&&(b(),g.state.next({name:S,dirtyFields:r.dirtyFields,isDirty:F(S,q)}));else{const Fe=Array.isArray(q)&&!q.length||Je(q);!z||z._f||st(q)||Fe?me(S,q,T,V):ve(S,q,T,V)}if(!he){const Fe=Mo(S,a),xt=V?i:Ue(i);g.state.next({...Fe&&r,name:o.mount||Fe?S:void 0,values:xt})}},K=(S,I,T={})=>be(S,I,T,!1),M=(S,I={})=>{const T=gt(S)?S(i):S;if(!At(i,T)){i={...i,...T};for(const V of a.mount)be(V,H(T,V),I,!0);g.state.next({...r,name:void 0,type:void 0,values:i}),I.shouldValidate&&y()}},G=async S=>{o.mount=!0;const I=S.target;let T=I.name,V=!0;const z=H(n,T),Q=he=>{V=Number.isNaN(he)||zr(he)&&isNaN(he.getTime())||At(he,H(i,T,he))},q=Ou(t.mode),ee=Ou(t.reValidateMode);if(z){let he,Fe;const xt=I.type?Cu(z._f):Ea(S),St=S.type===Sr.BLUR||S.type===Sr.FOCUS_OUT,lr=!cE(z._f)&&!e.validate&&!t.resolver&&!H(r.errors,T)&&!z._f.deps||fE(St,H(r.touchedFields,T),r.isSubmitted,ee,q),Hn=Mo(T,a,St);je(i,T,xt),St?(!I||!I.readOnly)&&(z._f.onBlur&&z._f.onBlur(S),c&&c(0)):z._f.onChange&&z._f.onChange(S);const Mr=k(T,xt,St),Xe=!Je(Mr)||Hn;if(!St&&g.state.next({name:T,type:S.type,values:Ue(i)}),lr)return(f.isValid||m.isValid)&&(t.mode==="onBlur"?St&&y():St||y()),Xe&&g.state.next({name:T,...Hn?{}:Mr});if(!t.resolver&&e.validate&&await U({name:T,eventType:S.type}),!St&&Hn&&g.state.next({...r}),t.resolver){const{errors:ct}=await N([T]);if(v([T]),Q(xt),!V){!Je(Mr)&&g.state.next(Mr);return}const bt=Du(r.errors,n,T),Vt=Du(ct,n,bt.name||T);he=Vt.error,T=Vt.name,Fe=Je(ct)}else v([T],!0),he=(await Tu(z,a.disabled,i,_,t.shouldUseNativeValidation))[T],v([T]),Q(xt),V&&(he?Fe=!1:(f.isValid||m.isValid)&&(Fe=await R({fields:n,onlyCheckValid:!0,name:T,eventType:S.type})));V&&(z._f.deps&&(!Array.isArray(z._f.deps)||z._f.deps.length>0)&&Y(z._f.deps),$(T,Fe,he,Mr))}},P=(S,I)=>{if(H(r.errors,I)&&S.focus)return S.focus(),1},Y=async(S,I={})=>{let T,V;const z=vi(S);if(t.resolver){const Q=await A(Ae(S)?S:z);T=Je(Q),V=S?!z.some(q=>H(Q,q)):T}else S?(V=(await Promise.all(z.map(async Q=>{const q=H(n,Q);return await R({fields:q&&q._f?{[Q]:q}:q,eventType:Sr.TRIGGER})}))).every(Boolean),!(!V&&!r.isValid)&&y()):V=T=await R({fields:n,name:S,eventType:Sr.TRIGGER});return g.state.next({...!mt(S)||(f.isValid||m.isValid)&&T!==r.isValid?{}:{name:S},...t.resolver||!S?{isValid:T}:{},errors:r.errors}),I.shouldFocus&&!V&&fs(n,P,S?z:a.mount),V},W=(S,I)=>{let T={...o.mount?i:s};return I&&(T=Ih(I.dirtyFields?r.dirtyFields:r.touchedFields,T)),Ae(S)?T:mt(S)?H(T,S):S.map(V=>H(T,V))},oe=(S,I)=>({invalid:!!H((I||r).errors,S),isDirty:!!H((I||r).dirtyFields,S),error:H((I||r).errors,S),isValidating:!!H(r.validatingFields,S),isTouched:!!H((I||r).touchedFields,S)}),pe=S=>{const I=S?vi(S):void 0;I==null||I.forEach(T=>Ke(r.errors,T)),I?I.forEach(T=>{g.state.next({name:T,errors:r.errors})}):g.state.next({errors:{}})},Ne=(S,I,T)=>{const V=(H(n,S,{_f:{}})._f||{}).ref,z=H(r.errors,S)||{},{ref:Q,message:q,type:ee,...he}=z;je(r.errors,S,{...he,...I,ref:V}),g.state.next({name:S,errors:r.errors,isValid:!1}),T&&T.shouldFocus&&V&&V.focus&&V.focus()},re=(S,I)=>gt(S)?g.state.subscribe({next:T=>"values"in T&&S(T.values||J(void 0,I),T)}):J(S,I,!0),se=S=>g.state.subscribe({next:I=>{if(dE(S.name,I.name,S.exact)&&uE(I,S.formState||f,Us,S.reRenderRoot)){const T={...i};S.callback({values:T,...r,...I,defaultValues:s})}}}).unsubscribe,le=S=>(o.mount=!0,m={...m,...S.formState},se({...S,formState:{...u,...S.formState}})),Le=(S,I={})=>{for(const T of S?vi(S):a.mount)a.mount.delete(T),a.array.delete(T),I.keepValue||(Ke(n,T),Ke(i,T)),!I.keepError&&Ke(r.errors,T),!I.keepDirty&&Ke(r.dirtyFields,T),!I.keepTouched&&Ke(r.touchedFields,T),!I.keepIsValidating&&Ke(r.validatingFields,T),!t.shouldUnregister&&!I.keepDefaultValue&&Ke(s,T);g.state.next({values:Ue(i)}),g.state.next({...r,...I.keepDirty?{isDirty:F()}:{}}),!I.keepIsValid&&y()},ze=({disabled:S,name:I})=>{if(kt(S)&&o.mount||S||a.disabled.has(I)){const z=a.disabled.has(I)!==!!S;S?a.disabled.add(I):a.disabled.delete(I),z&&o.mount&&!o.action&&y()}},Te=(S,I={})=>{let T=H(n,S);const V=kt(I.disabled)||kt(t.disabled),z=!a.registerName.has(S)&&T&&T._f&&!T._f.mount;return je(n,S,{...T||{},_f:{...T&&T._f?T._f:{ref:{name:S}},name:S,mount:!0,...I}}),a.mount.add(S),T&&!z?ze({disabled:kt(I.disabled)?I.disabled:t.disabled,name:S}):j(S,!0,I.value),{...V?{disabled:I.disabled||t.disabled}:{},...t.progressive?{required:!!I.required,min:es(I.min),max:es(I.max),minLength:es(I.minLength),maxLength:es(I.maxLength),pattern:es(I.pattern)}:{},name:S,onChange:G,onBlur:G,ref:Q=>{if(Q){a.registerName.add(S),Te(S,I),a.registerName.delete(S),T=H(n,S);const q=Ae(Q.value)&&Q.querySelectorAll&&Q.querySelectorAll("input,select,textarea")[0]||Q,ee=nE(q),he=T._f.refs||[];if(ee?he.find(Fe=>Fe===q):q===T._f.ref)return;je(n,S,{_f:{...T._f,...ee?{refs:[...he.filter(Po),q,...Array.isArray(H(s,S))?[{}]:[]],ref:{type:q.type,name:S}}:{ref:q}}}),j(S,!1,void 0,q)}else T=H(n,S,{}),T._f&&(T._f.mount=!1),(t.shouldUnregister||I.shouldUnregister)&&!(xh(a.array,S)&&o.action)&&a.unMount.add(S)}}},te=()=>t.shouldFocusError&&!t.shouldUseNativeValidation&&fs(n,P,a.mount),We=S=>{kt(S)&&(g.state.next({disabled:S}),fs(n,(I,T)=>{const V=H(n,T);V&&(I.disabled=V._f.disabled||S,Array.isArray(V._f.refs)&&V._f.refs.forEach(z=>{z.disabled=V._f.disabled||S}))},0,!1))},at=(S,I)=>async T=>{let V;T&&(T.preventDefault&&T.preventDefault(),T.persist&&T.persist());let z=Ue(i);if(g.state.next({isSubmitting:!0}),t.resolver){const{errors:Q,values:q}=await N();v(),r.errors=Q,z=Ue(q)}else await R({fields:n,eventType:Sr.SUBMIT});if(a.disabled.size)for(const Q of a.disabled)Ke(z,Q);if(Ke(r.errors,Ch),Je(r.errors)){g.state.next({errors:{}});try{await S(z,T)}catch(Q){V=Q}}else I&&await I({...r.errors},T),te(),setTimeout(te);if(g.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:Je(r.errors)&&!V,submitCount:r.submitCount+1,errors:r.errors}),V)throw V},vt=(S,I={})=>{H(n,S)&&(Ae(I.defaultValue)?K(S,Ue(H(s,S))):(K(S,I.defaultValue),je(s,S,Ue(I.defaultValue))),I.keepTouched||Ke(r.touchedFields,S),I.keepDirty||(Ke(r.dirtyFields,S),r.isDirty=I.defaultValue?F(S,Ue(H(s,S))):F()),I.keepError||(Ke(r.errors,S),f.isValid&&y()),g.state.next({...r}))},qe=(S,I={})=>{const T=S?Ue(S):s,V=Ue(T),z=Je(S),Q=V;if(I.keepDefaultValues||(s=T),!I.keepValues){if(I.keepDirtyValues){const q=new Set([...a.mount,...Object.keys($r(s,i))]);for(const ee of Array.from(q)){const he=H(r.dirtyFields,ee),Fe=H(i,ee),xt=H(Q,ee);he&&!Ae(Fe)?je(Q,ee,Fe):!he&&!Ae(xt)&&K(ee,xt)}}else{if(to&&Ae(S))for(const q of a.mount){const ee=H(n,q);if(ee&&ee._f){const he=Array.isArray(ee._f.refs)?ee._f.refs[0]:ee._f.ref;if(Ri(he)){const Fe=he.closest("form");if(Fe){Fe.reset();break}}}}if(I.keepFieldsRef)for(const q of a.mount)K(q,H(Q,q));else n={}}if(t.shouldUnregister){if(i=I.keepDefaultValues?Ue(s):{},I.keepFieldsRef)for(const q of a.mount)je(i,q,H(Q,q))}else i=Ue(Q);g.array.next({values:{...Q}}),g.state.next({values:{...Q}})}a={mount:I.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||!!I.keepIsValid||!!I.keepDirtyValues||!t.shouldUnregister&&!Je(Q),o.watch=!!t.shouldUnregister,o.keepIsValid=!!I.keepIsValid,o.action=!1,I.keepErrors||(r.errors={}),g.state.next({submitCount:I.keepSubmitCount?r.submitCount:0,isDirty:z?!1:I.keepDirty?r.isDirty:I.keepValues?F():!!(I.keepDefaultValues&&!At(S,s)),isSubmitted:I.keepIsSubmitted?r.isSubmitted:!1,dirtyFields:z?{}:I.keepDirtyValues?I.keepDefaultValues&&i?$r(s,i):r.dirtyFields:I.keepDefaultValues&&S?$r(s,S):I.keepDirty?r.dirtyFields:{},touchedFields:I.keepTouched?r.touchedFields:{},errors:I.keepErrors?r.errors:{},isSubmitSuccessful:I.keepIsSubmitSuccessful?r.isSubmitSuccessful:!1,isSubmitting:!1,defaultValues:s})},Ye=(S,I)=>qe(gt(S)?S(i):S,{...t.resetOptions,...I}),lt=(S,I={})=>{const T=H(n,S),V=T&&T._f;if(V){const z=V.refs?V.refs[0]:V.ref;z.focus&&setTimeout(()=>{z.focus(),I.shouldSelect&&gt(z.select)&&z.select()})}},Us=S=>{r={...r,...S}},Vs={control:{register:Te,unregister:Le,getFieldState:oe,handleSubmit:at,setError:Ne,_subscribe:se,_runSchema:N,_updateIsValidating:v,_focusError:te,_getWatch:J,_getDirty:F,_setValid:y,_setFieldArray:x,_setDisabledField:ze,_setErrors:C,_getFieldArray:ie,_reset:qe,_resetDefaultValues:()=>gt(t.defaultValues)&&t.defaultValues().then(S=>{Ye(S,t.resetOptions),g.state.next({isLoading:!1})}),_removeUnmounted:B,_disableForm:We,_subjects:g,_proxyFormState:f,get _fields(){return n},get _formValues(){return i},get _state(){return o},set _state(S){o=S},get _defaultValues(){return s},get _names(){return a},set _names(S){a=S},get _formState(){return r},get _options(){return t},set _options(S){t={...t,...S}}},subscribe:le,trigger:Y,register:Te,handleSubmit:at,watch:re,setValue:K,setValues:M,getValues:W,reset:Ye,resetField:vt,resetDefaultValues:(S,I={})=>{if(s=Ue(S),!I.keepDirty){const T=$r(s,i);r.dirtyFields=T,r.isDirty=!Je(T)}I.keepIsValid||y(),g.state.next({...r,defaultValues:s})},clearErrors:pe,unregister:Le,setError:Ne,setFocus:lt,getFieldState:oe};return{...Vs,formControl:Vs}}function mE(e={}){const t=p.useRef(void 0),r=p.useRef(void 0),n=p.useRef(e.formControl),[s,i]=p.useState(()=>({...Ue(Ah),isLoading:gt(e.defaultValues),errors:e.errors||{},disabled:e.disabled||!1,defaultValues:gt(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&&!gt(e.defaultValues)&&e.formControl.reset(e.defaultValues,e.resetOptions);else{const{formControl:a,...c}=gE(e);t.current={...c,formState:s}}const o=t.current.control;return o._options=e,pl(()=>{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]),p.useEffect(()=>o._disableForm(e.disabled),[o,e.disabled]),p.useEffect(()=>{e.mode&&(o._options.mode=e.mode),e.reValidateMode&&(o._options.reValidateMode=e.reValidateMode)},[o,e.mode,e.reValidateMode]),p.useEffect(()=>{e.errors&&(o._setErrors(e.errors),o._focusError())},[o,e.errors]),p.useEffect(()=>{e.shouldUnregister&&o._subjects.state.next({values:o._getWatch()})},[o,e.shouldUnregister]),p.useEffect(()=>{if(o._proxyFormState.isDirty){const a=o._getDirty();a!==s.isDirty&&o._subjects.state.next({isDirty:a})}},[o,s.isDirty]),p.useEffect(()=>{var a;e.values&&!At(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]),p.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=p.useMemo(()=>Eh(s,o),[o,s]),t.current}async function ju(e){var r,n;return(n=(r=(await Me.get(`/api/framework/v1/read/${e}`)).data)==null?void 0:r.result)==null?void 0:n.framework}function Ph(e,t){const r=ea({queryKey:["framework",e],queryFn:()=>ju(e),enabled:!!e,staleTime:3e5}),n=t==null?void 0:t[0],s=ea({queryKey:["framework",n],queryFn:()=>ju(n),enabled:!!n,staleTime:5*60*1e3}),i=s.data?[s.data]:[];return{organisationFramework:r.data,targetFrameworks:i,isLoading:r.isLoading||s.isLoading}}async function yE(e){var r,n;return(n=(r=(await Me.get(`/api/channel/v1/read/${e}`)).data)==null?void 0:r.result)==null?void 0:n.channel}function vE(e){var r,n,s,i,o,a;const t=ea({queryKey:["channel",e],queryFn:()=>yE(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 bE={"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."}},Zs={"First Section":"details","Second Section":"details","Third Section":"details","Organisation Framework Terms":"details","Target Framework Terms":"audience","Fourth Section":"licensing","Sixth Section":"licensing"},_E={Categorisation:"Second Section","Basic Information":"First Section","Licensing & Attribution":"Fourth Section",Curriculum:"Organisation Framework Terms","Target Audience":"Target Framework Terms"},wE={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"},Mh={board:"board",boardIds:"board",medium:"medium",gradeLevel:"gradeLevel",subject:"subject",subjectIds:"subject",topicsIds:"topic",topic:"topic",targetBoardIds:"board",targetMediumIds:"medium",targetGradeLevelIds:"gradeLevel",targetSubjectIds:"subject"},Ru=new Set(["targetBoardIds","targetMediumIds","targetGradeLevelIds","targetSubjectIds"]);function xE(e,t,r,n){if(!(e!=null&&e.length))return IE(t,n,r);const s=new Set;return e.filter(i=>{if(n&&(i.code==="dialCode"||i.code==="dialcode")||i.visible===!1)return!1;const o=i.code;return s.has(o)?!1:(s.add(o),!0)}).map(i=>{const o=i.code??"",a=EE(i),c=DE(i,r,t),d=t[o],u=Lh(d,a),f={code:o,label:i.label??o,inputType:a,required:!!(i.required===!0||Array.isArray(i.validations)&&i.validations.some(m=>m.type==="required")),editable:i.editable!==!1,placeholder:i.placeholder,maxLength:i.maxLength,options:CE(c,u,a,r),depends:i.depends,tab:OE(i),section:i.section,defaultValue:i.defaultValue??i.default,currentValue:u};if(o==="dialcodes"){const m=t.dialcodeRequired==="Yes";return{...f,required:m,visible:m}}return f})}function SE(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 CE(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=SE(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 OE(e){const t=e.section;if(t){if(Zs[t])return Zs[t];const n=_E[t];if(n&&Zs[n])return Zs[n]}const r=e.code??"";return wE[r]??"details"}function Lh(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 EE(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 DE(e,t,r){var a;const n=e.range;if(Array.isArray(n)&&n.length)return typeof n[0]=="string"?n.map(c=>({label:c,value:c})):n.map(c=>({label:c.name,value:c.identifier}));const s=e.enum;if(s!=null&&s.length)return s.map(c=>({label:c,value:c}));const i=e.code??"";if(i==="framework")return t.orgFrameworks;if(i==="additionalCategories")return(a=t.channelAdditionalCategories)==null?void 0:a.map(c=>({label:c,value:c}));const o=e.sourceCategory??Mh[i];if(o)return Fh(i,o,e,t,r)}function Fh(e,t,r,n,s){var f,m,g,_,h;const i=Ru.has(e)||r.output==="identifier"||typeof r.section=="string"&&r.section.includes("Target"),o=y=>({label:y.name,value:i?y.identifier:y.name}),a=(m=(f=n.organisationFramework)==null?void 0:f.categories)==null?void 0:m.find(y=>y.code===t),c=(h=(_=(g=n.targetFrameworks)==null?void 0:g[0])==null?void 0:_.categories)==null?void 0:h.find(y=>y.code===t);let d=(Ru.has(e)?c==null?void 0:c.terms:a==null?void 0:a.terms)??(c==null?void 0:c.terms)??(a==null?void 0:a.terms)??[];const u=r.depends;if(u!=null&&u.length){const y=u.flatMap(v=>{const b=s[v];return Array.isArray(b)?b:b!=null&&b!==""?[b]:[]}).map(String);if(y.length){const v=d.filter(b=>{const x=b.associations;return!x||!x.length?!0:x.some(w=>y.includes(w.identifier)||y.includes(w.code)||y.includes(w.name))});v.length&&(d=v)}}return d.map(o)}function ts(e,t){const r=Mh[e];if(r)return Fh(e,r,{},t,{})}function nt(e,t,r){return Lh(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:nt(e,"name","text")},{code:"description",label:"Description",inputType:"textarea",editable:!0,tab:"details",section:"First Section",maxLength:2e3,currentValue:nt(e,"description","textarea")},{code:"keywords",label:"Keywords",inputType:"chips",editable:!0,tab:"details",section:"First Section",currentValue:nt(e,"keywords","chips")}];return t&&(n.push({code:"primaryCategory",label:"Category",inputType:"select",editable:!1,tab:"details",section:"Second Section",currentValue:nt(e,"primaryCategory","select")},{code:"additionalCategories",label:"Additional Category",inputType:"multiselect",editable:!0,tab:"details",section:"Second Section",currentValue:nt(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:nt(e,"framework","select")},{code:"subjectIds",label:"Subjects covered",inputType:"multiselect",required:!0,editable:!0,tab:"details",section:"Organisation Framework Terms",options:ts("subjectIds",r),currentValue:nt(e,"subjectIds","multiselect")}),n.push({code:"audience",label:"Audience Type",inputType:"multiselect",editable:!0,tab:"audience",section:"Target Framework Terms",currentValue:nt(e,"audience","multiselect")},{code:"targetBoardIds",label:"Board/Syllabus of the audience",inputType:"select",required:!0,editable:!0,tab:"audience",section:"Target Framework Terms",options:ts("targetBoardIds",r),currentValue:nt(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:ts("targetMediumIds",r),currentValue:nt(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:ts("targetGradeLevelIds",r),currentValue:nt(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:ts("targetSubjectIds",r),currentValue:nt(e,"targetSubjectIds","multiselect")}),n.push({code:"creator",label:"Author",inputType:"text",editable:!0,tab:"licensing",section:"Fourth Section",currentValue:nt(e,"creator","text")},{code:"attributions",label:"Attributions",inputType:"text",editable:!0,tab:"licensing",section:"Fourth Section",currentValue:nt(e,"attributions","text")},{code:"copyright",label:"Copyright",inputType:"text",required:!0,editable:!0,tab:"licensing",section:"Fourth Section",currentValue:nt(e,"copyright","text")},{code:"copyrightYear",label:"Copyright Year",inputType:"text",required:!0,editable:!0,tab:"licensing",section:"Fourth Section",currentValue:nt(e,"copyrightYear","text")},{code:"license",label:"License",inputType:"select",required:!0,editable:!0,tab:"licensing",section:"Fourth Section",currentValue:nt(e,"license","select")})),n}function NE(e,t){const{watch:r,setValue:n}=e;p.useEffect(()=>{const s=r((i,{name:o})=>{o&&t.forEach(a=>{var c;(c=a.depends)!=null&&c.includes(o)&&n(a.code,a.inputType==="multiselect"||a.inputType==="chips"?[]:"",{shouldDirty:!0})})});return()=>s.unsubscribe()},[r,n,t])}const TE="_section_ylgu8_1",jE="_header_ylgu8_11",RE="_title_ylgu8_17",kE="_description_ylgu8_24",AE="_divider_ylgu8_30",PE="_fields_ylgu8_36",yn={section:TE,header:jE,title:RE,description:kE,divider:AE,fields:PE},ME=({title:e,description:t,children:r})=>l.jsxs("div",{className:yn.section,children:[l.jsxs("div",{className:yn.header,children:[l.jsx("h3",{className:yn.title,children:e}),t&&l.jsx("p",{className:yn.description,children:t})]}),l.jsx("hr",{className:yn.divider}),l.jsx("div",{className:yn.fields,children:r})]}),LE="_field_1s288_1",FE="_fullWidth_1s288_7",$E="_label_1s288_11",BE="_required_1s288_19",UE="_input_1s288_24",VE="_textarea_1s288_45",zE="_inputError_1s288_50",qE="_error_1s288_54",HE="_selectBtn_1s288_59",WE="_selectOpen_1s288_83",KE="_placeholder_1s288_87",QE="_selectedVal_1s288_91",GE="_chevronUp_1s288_95",YE="_dropdown_1s288_100",XE="_option_1s288_116",ZE="_optionSelected_1s288_134",JE="_noOpts_1s288_139",eD="_chipGroup_1s288_146",tD="_chipInput_1s288_158",rD="_addChipBtn_1s288_167",nD="_radioGroup_1s288_184",sD="_radioLabel_1s288_191",iD="_iconWrap_1s288_199",oD="_iconPreview_1s288_214",aD="_iconPlaceholder_1s288_220",lD="_removeIconBtn_1s288_233",cD="_tagChip_1s288_252",uD="_tagChipRemove_1s288_264",dD="_nestedSelectRow_1s288_278",fD="_dialcodeRow_1s288_287",hD="_validateBtn_1s288_293",pD="_dialcodeValid_1s288_315",gD="_dialcodeSpinner_1s288_325",L={field:LE,fullWidth:FE,label:$E,required:BE,input:UE,textarea:VE,inputError:zE,error:qE,selectBtn:HE,selectOpen:WE,placeholder:KE,selectedVal:QE,chevronUp:GE,dropdown:YE,option:XE,optionSelected:ZE,noOpts:JE,chipGroup:eD,chipInput:tD,addChipBtn:rD,radioGroup:nD,radioLabel:sD,iconWrap:iD,iconPreview:oD,iconPlaceholder:aD,removeIconBtn:lD,tagChip:cD,tagChipRemove:uD,nestedSelectRow:dD,dialcodeRow:fD,validateBtn:hD,dialcodeValid:pD,dialcodeSpinner:gD},ku=({name:e,label:t,required:r,disabled:n,multiline:s,maxLength:i,placeholder:o})=>{const{register:a,formState:{errors:c}}=Yt(),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)})]})},mD=({name:e,label:t,options:r,required:n,disabled:s})=>{var h;const[i,o]=p.useState(!1),a=p.useRef(null),{register:c,watch:d,setValue:u,formState:{errors:f}}=Yt(),m=d(e),g=((h=r.find(y=>y.value===m))==null?void 0:h.label)??"Select…",_=f[e];return p.useEffect(()=>{if(!i)return;const y=v=>{var b;(b=a.current)!=null&&b.contains(v.target)||o(!1)};return document.addEventListener("mousedown",y),()=>document.removeEventListener("mousedown",y)},[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(y=>!y),children:[l.jsx("span",{className:m?L.selectedVal:L.placeholder,children:g}),l.jsx(ks,{size:14,className:i?L.chevronUp:""})]}),i&&l.jsxs("div",{className:L.dropdown,children:[r.map(y=>l.jsxs("button",{type:"button",className:[L.option,m===y.value?L.optionSelected:""].join(" "),onClick:()=>{u(e,y.value,{shouldDirty:!0,shouldValidate:!0}),o(!1)},children:[l.jsx("span",{children:y.label}),m===y.value&&l.jsx(Un,{size:13})]},y.value)),!r.length&&l.jsx("span",{className:L.noOpts,children:"No options"})]}),_&&l.jsx("span",{className:L.error,children:String(_.message)})]})},yD=({name:e,label:t,options:r,required:n,disabled:s})=>{const[i,o]=p.useState(!1),a=p.useRef(null),{register:c,watch:d,setValue:u,formState:{errors:f}}=Yt(),m=d(e)??[],g=f[e],_=m.length?`${m.length} selected`:"Select…";p.useEffect(()=>{if(!i)return;const y=v=>{var b;(b=a.current)!=null&&b.contains(v.target)||o(!1)};return document.addEventListener("mousedown",y),()=>document.removeEventListener("mousedown",y)},[i]);const h=y=>{const v=m.includes(y)?m.filter(b=>b!==y):[...m,y];u(e,v,{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,g?L.inputError:"",i?L.selectOpen:""].join(" "),onClick:()=>o(y=>!y),children:[l.jsx("span",{className:m.length?L.selectedVal:L.placeholder,children:_}),l.jsx(ks,{size:14,className:i?L.chevronUp:""})]}),i&&l.jsxs("div",{className:L.dropdown,children:[r.map(y=>l.jsxs("button",{type:"button",className:[L.option,m.includes(y.value)?L.optionSelected:""].join(" "),onClick:()=>h(y.value),children:[l.jsx(Un,{size:13,style:{opacity:m.includes(y.value)?1:0}}),l.jsx("span",{children:y.label})]},y.value)),!r.length&&l.jsx("span",{className:L.noOpts,children:"No options"})]}),g&&l.jsx("span",{className:L.error,children:String(g.message)})]})},vD=({name:e,label:t,required:r,disabled:n,placeholder:s="Add…"})=>{const[i,o]=p.useState(""),[a,c]=p.useState(!1),d=p.useRef(null),{watch:u,setValue:f,formState:{errors:m}}=Yt(),g=u(e)??[],_=m[e],h=()=>{const v=i.trim();v&&!g.includes(v)&&f(e,[...g,v],{shouldDirty:!0}),o(""),c(!1)},y=v=>f(e,g.filter(b=>b!==v),{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:[g.map(v=>l.jsxs("span",{className:"sbx-chip filled",children:[v,!n&&l.jsx("button",{type:"button",className:"sbx-chip-remove",onClick:()=>y(v),"aria-label":`Remove ${v}`,children:"×"})]},v)),!n&&(a?l.jsx("input",{ref:d,autoFocus:!0,className:L.chipInput,value:i,onChange:v=>o(v.target.value),onKeyDown:v=>{v.key==="Enter"&&(v.preventDefault(),h()),v.key==="Escape"&&(o(""),c(!1))},onBlur:h,placeholder:s}):l.jsxs("button",{type:"button",className:L.addChipBtn,onClick:()=>{c(!0),setTimeout(()=>{var v;return(v=d.current)==null?void 0:v.focus()},50)},children:[l.jsx(As,{size:12})," Add"]}))]}),_&&l.jsx("span",{className:L.error,children:String(_.message)})]})},bD=({name:e,label:t,options:r,required:n,disabled:s})=>{const{register:i,formState:{errors:o}}=Yt(),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 _D(e,t,r,n){var o,a;const i=(a=(o=(await Me.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 wD(e,t){var s,i;const n=(i=(s=(await Me.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 xD(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 SD(e,t,r){var o,a;const n=new FormData;n.append("fileUrl",t),n.append("mimeType",r);const i=(a=(o=(await Me.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 CD="_overlay_ga6eh_1",OD="_modal_ga6eh_12",ED="_header_ga6eh_24",DD="_title_ga6eh_33",ID="_closeBtn_ga6eh_39",ND="_tabs_ga6eh_57",TD="_tab_ga6eh_57",jD="_activeTab_ga6eh_83",RD="_body_ga6eh_88",kD="_searchWrap_ga6eh_99",AD="_searchIcon_ga6eh_104",PD="_searchInput_ga6eh_113",MD="_grid_ga6eh_132",LD="_imgCell_ga6eh_148",FD="_imgCellSelected_ga6eh_166",$D="_thumb_ga6eh_171",BD="_noThumb_ga6eh_177",UD="_checkBadge_ga6eh_183",VD="_loadMoreBtn_ga6eh_198",zD="_loadingRow_ga6eh_220",qD="_empty_ga6eh_230",HD="_spinner_ga6eh_237",WD="_uploadArea_ga6eh_247",KD="_dropZone_ga6eh_256",QD="_uploadIcon_ga6eh_277",GD="_dropText_ga6eh_281",YD="_dropSubtext_ga6eh_288",XD="_uploadPreview_ga6eh_294",ZD="_hiddenInput_ga6eh_301",JD="_fileName_ga6eh_305",eI="_errorText_ga6eh_311",tI="_footer_ga6eh_318",rI="_cancelBtn_ga6eh_328",nI="_confirmBtn_ga6eh_345",fe={overlay:CD,modal:OD,header:ED,title:DD,closeBtn:ID,tabs:ND,tab:TD,activeTab:jD,body:RD,searchWrap:kD,searchIcon:AD,searchInput:PD,grid:MD,imgCell:LD,imgCellSelected:FD,thumb:$D,noThumb:BD,checkBadge:UD,loadMoreBtn:VD,loadingRow:zD,empty:qD,spinner:HD,uploadArea:WD,dropZone:KD,uploadIcon:QD,dropText:GD,dropSubtext:YD,uploadPreview:XD,hiddenInput:ZD,fileName:JD,errorText:eI,footer:tI,cancelBtn:rI,confirmBtn:nI},Au=18,$h=({nodeId:e,currentValue:t,onSelect:r,onClose:n})=>{const[s,i]=p.useState("my"),[o,a]=p.useState(""),[c,d]=p.useState([]),[u,f]=p.useState(0),[m,g]=p.useState(!1),[_,h]=p.useState(null),[y,v]=p.useState(0),[b,x]=p.useState(null),[w,C]=p.useState(""),[D,j]=p.useState(!1),[k,$]=p.useState(""),N=p.useRef(null),A=ue(P=>{var Y,W;return((W=(Y=P.editorConfig)==null?void 0:Y.context)==null?void 0:W.channel)??""}),U=ue(P=>{var Y,W;return((W=(Y=P.editorConfig)==null?void 0:Y.context)==null?void 0:W.uid)??""}),R=ue(P=>{var Y,W,oe;return((oe=(W=(Y=P.editorConfig)==null?void 0:Y.context)==null?void 0:W.cloudStorage)==null?void 0:oe.presigned_headers)??{}}),B=ue(P=>{var Y,W,oe;return((oe=(W=(Y=P.editorConfig)==null?void 0:Y.config)==null?void 0:W.assetConfig)==null?void 0:oe.size)??1*1024*1024}),F=ue(P=>{var Y,W,oe;return((oe=(W=(Y=P.editorConfig)==null?void 0:Y.config)==null?void 0:W.assetConfig)==null?void 0:oe.accepted)??"image/png,image/jpeg"}),J=p.useCallback(async(P,Y,W=!1)=>{var oe;g(!0);try{const pe={status:["Live"],mediaType:["image"],mimeType:["image/png","image/jpeg","image/jpg","image/gif","image/svg+xml"]};s==="my"&&U&&(pe.createdBy=U),A&&(pe.channel=A);const re=((oe=(await Me.post("/action/composite/v3/search",{request:{filters:pe,query:P,limit:Au,offset:Y,sort_by:{createdOn:"desc"},fields:["identifier","name","appIcon","artifactUrl","downloadUrl"]}},{headers:{"X-Source":"web"}})).data)==null?void 0:oe.result)??{},se=re.content??[];f(re.count??0),d(le=>W?[...le,...se]:se)}catch{}finally{g(!1)}},[s,U,A]);p.useEffect(()=>{s!=="upload"&&(d([]),v(0),J(o,0))},[s]);const ie=p.useRef(),me=P=>{a(P),clearTimeout(ie.current),ie.current=setTimeout(()=>{d([]),v(0),J(P,0)},400)},ve=()=>{const P=y+Au;v(P),J(o,P,!0)},be=()=>{const P=(_==null?void 0:_.artifactUrl)??(_==null?void 0:_.appIcon)??(_==null?void 0:_.downloadUrl)??"";P&&r(P)};p.useEffect(()=>()=>{w&&URL.revokeObjectURL(w)},[w]);const K=P=>{var oe;const Y=(oe=P.target.files)==null?void 0:oe[0];if(P.target.value="",!Y)return;const W=F.split(",").map(pe=>pe.trim());if(!W.includes(Y.type)){const pe=W.map(Ne=>Ne.replace("image/","").toUpperCase()).join(", ");$(`Only ${pe} files are accepted.`);return}if(Y.size>B){const pe=(B/1048576).toFixed(0);$(`Image must be under ${pe} MB.`);return}w&&URL.revokeObjectURL(w),x(Y),C(URL.createObjectURL(Y)),$("")},M=async()=>{if(b){j(!0),$("");try{const P=await _D(b.name.split(".").slice(0,-1).join(".")||b.name,b.type,U,A),Y=await wD(P,b.name);await xD(Y,b,R);const W=Y.split("?")[0],oe=await SD(P,W,b.type);r(oe)}catch(P){$(P instanceof Error?P.message:"Upload failed.")}finally{j(!1)}}},G=c.length<u;return l.jsx("div",{className:fe.overlay,role:"dialog","aria-modal":"true","aria-label":"Select App Icon",children:l.jsxs("div",{className:fe.modal,children:[l.jsxs("div",{className:fe.header,children:[l.jsx("span",{className:fe.title,children:"Select App Icon"}),l.jsx("button",{className:fe.closeBtn,onClick:n,"aria-label":"Close",children:l.jsx(on,{size:18})})]}),l.jsxs("div",{className:fe.tabs,role:"tablist",children:[l.jsx("button",{role:"tab","aria-selected":s==="my",className:`${fe.tab} ${s==="my"?fe.activeTab:""}`,onClick:()=>i("my"),children:"My Images"}),l.jsx("button",{role:"tab","aria-selected":s==="all",className:`${fe.tab} ${s==="all"?fe.activeTab:""}`,onClick:()=>i("all"),children:"All Images"}),l.jsxs("button",{role:"tab","aria-selected":s==="upload",className:`${fe.tab} ${s==="upload"?fe.activeTab:""}`,onClick:()=>i("upload"),children:[l.jsx(Wl,{size:13,style:{marginRight:4}}),"Upload"]})]}),l.jsx("div",{className:fe.body,children:s!=="upload"?l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:fe.searchWrap,children:[l.jsx(la,{size:14,className:fe.searchIcon}),l.jsx("input",{type:"search",className:fe.searchInput,placeholder:"Search images…",value:o,onChange:P=>me(P.target.value)})]}),m&&c.length===0?l.jsxs("div",{className:fe.loadingRow,children:[l.jsx(ii,{size:20,className:fe.spinner}),l.jsx("span",{children:"Loading…"})]}):c.length===0?l.jsx("div",{className:fe.empty,children:"No images found"}):l.jsx("div",{className:fe.grid,children:c.map(P=>{const Y=P.appIcon??P.artifactUrl??P.downloadUrl??"",W=(_==null?void 0:_.identifier)===P.identifier;return l.jsxs("button",{type:"button",className:`${fe.imgCell} ${W?fe.imgCellSelected:""}`,onClick:()=>h(P),title:P.name,children:[Y?l.jsx("img",{src:Y,alt:P.name,className:fe.thumb}):l.jsx("div",{className:fe.noThumb,children:"IMG"}),W&&l.jsx("div",{className:fe.checkBadge,children:l.jsx(Un,{size:12})})]},P.identifier)})}),G&&!m&&l.jsx("button",{className:fe.loadMoreBtn,onClick:ve,children:"Load More"}),m&&c.length>0&&l.jsx("div",{className:fe.loadingRow,children:l.jsx(ii,{size:16,className:fe.spinner})})]}):l.jsxs("div",{className:fe.uploadArea,children:[l.jsx("div",{className:fe.dropZone,onClick:()=>{var P;return(P=N.current)==null?void 0:P.click()},onDragOver:P=>P.preventDefault(),onDrop:P=>{P.preventDefault();const Y=P.dataTransfer.files[0];Y&&K({target:{files:[Y],value:""}})},children:w?l.jsx("img",{src:w,alt:"Preview",className:fe.uploadPreview}):l.jsxs(l.Fragment,{children:[l.jsx(Wl,{size:32,className:fe.uploadIcon}),l.jsx("p",{className:fe.dropText,children:"Drag & drop or click to browse"}),l.jsxs("p",{className:fe.dropSubtext,children:[F.split(",").map(P=>P.replace("image/","").toUpperCase()).join(", ")," · max ",(B/(1024*1024)).toFixed(0)," MB"]})]})}),l.jsx("input",{ref:N,type:"file",accept:F,className:fe.hiddenInput,onChange:K}),b&&l.jsx("p",{className:fe.fileName,children:b.name}),k&&l.jsx("p",{className:fe.errorText,children:k})]})}),l.jsxs("div",{className:fe.footer,children:[l.jsx("button",{className:fe.cancelBtn,onClick:n,children:"Cancel"}),s==="upload"?l.jsx("button",{className:fe.confirmBtn,disabled:!b||D,onClick:M,children:D?l.jsxs(l.Fragment,{children:[l.jsx(ii,{size:14,className:fe.spinner})," Uploading…"]}):"Upload & Use"}):l.jsx("button",{className:fe.confirmBtn,disabled:!_,onClick:be,children:"Use Selected"})]})]})})},sI=({name:e,label:t,nodeId:r,required:n,disabled:s})=>{const[i,o]=p.useState(!1),{watch:a,setValue:c,register:d,formState:{errors:u}}=Yt(),f=a(e),m=u[e],g=h=>{c(e,h,{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:h=>{(h.key==="Enter"||h.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(Wd,{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(Ka,{size:13}),l.jsx("span",{children:"Remove"})]}),m&&l.jsx("span",{className:L.error,children:String(m.message)}),i&&l.jsx($h,{nodeId:r,currentValue:f,onSelect:g,onClose:()=>o(!1)})]})},iI=({name:e,label:t,required:r,disabled:n})=>{const{control:s}=Yt(),{field:i,fieldState:{error:o}}=no({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)})]})},oI=({name:e,label:t,required:r,disabled:n})=>{const{control:s}=Yt(),{field:i,fieldState:{error:o}}=no({name:e,control:s,rules:{required:r?`${t} is required`:!1},defaultValue:[]}),[a,c]=p.useState(""),d=p.useRef(null),u=i.value??[],f=h=>{const y=h.trim();!y||u.includes(y)||i.onChange([...u,y])},m=h=>{i.onChange(u.filter(y=>y!==h))},g=h=>{h.key==="Enter"||h.key===","?(h.preventDefault(),f(a),c("")):h.key==="Backspace"&&a===""&&u.length>0&&m(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 h;return!n&&((h=d.current)==null?void 0:h.focus())},style:{cursor:n?"not-allowed":"text"},children:[u.map(h=>l.jsxs("span",{className:L.tagChip,children:[h,!n&&l.jsx("button",{type:"button",className:L.tagChipRemove,onClick:y=>{y.stopPropagation(),m(h)},"aria-label":`Remove ${h}`,children:l.jsx(on,{size:11})})]},h)),!n&&l.jsx("input",{ref:d,className:L.chipInput,value:a,onChange:h=>c(h.target.value),onKeyDown:g,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)})]})},aI=({name:e,label:t,levels:r,required:n,disabled:s})=>{const{control:i}=Yt(),{field:o,fieldState:{error:a}}=no({name:e,control:i,rules:{required:n?`${t} is required`:!1},defaultValue:{}}),c=o.value??{},d=(u,f,m)=>{const g={};for(let _=0;_<f;_++)g[r[_].code]=c[r[_].code]??"";g[u]=m;for(let _=f+1;_<r.length;_++)g[r[_].code]="";o.onChange(g)};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 m=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||m,value:c[u.code]??"",onChange:g=>d(u.code,f,g.target.value),onBlur:o.onBlur,children:[l.jsx("option",{value:"",children:"Select…"}),u.options.map(g=>l.jsx("option",{value:g.value,children:g.label},g.value))]})]},u.code)})}),a&&l.jsx("span",{className:L.error,children:String(a.message)})]})},Pu=[{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"}],lI=({name:e,label:t,required:r,disabled:n})=>{const[s,i]=p.useState(!1),o=p.useRef(null),{register:a,watch:c,setValue:d,formState:{errors:u}}=Yt(),f=c(e),m=Pu.find(h=>h.value===f),g=(m==null?void 0:m.label)??"Select license…",_=u[e];return p.useEffect(()=>{if(!s)return;const h=y=>{var v;(v=o.current)!=null&&v.contains(y.target)||i(!1)};return document.addEventListener("mousedown",h),()=>document.removeEventListener("mousedown",h)},[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(h=>!h),"aria-haspopup":"listbox","aria-expanded":s,children:[l.jsx("span",{className:f?L.selectedVal:L.placeholder,children:g}),l.jsx(ks,{size:14,className:s?L.chevronUp:""})]}),s&&l.jsx("div",{className:L.dropdown,role:"listbox",children:Pu.map(h=>l.jsxs("button",{type:"button",role:"option","aria-selected":f===h.value,className:[L.option,f===h.value?L.optionSelected:""].join(" "),onClick:()=>{d(e,h.value,{shouldDirty:!0,shouldValidate:!0}),i(!1)},children:[l.jsx("span",{children:h.label}),f===h.value&&l.jsx(Un,{size:13})]},h.value))}),_&&l.jsx("span",{className:L.error,children:String(_.message)})]})},cI=({name:e,label:t,required:r,disabled:n})=>{const{control:s}=Yt(),{field:i,fieldState:{error:o}}=no({name:e,control:s,rules:{required:r?`${t} is required`:!1},defaultValue:""}),[a,c]=p.useState("idle"),[d,u]=p.useState(""),f=async()=>{const g=(i.value??"").trim();if(!g){c("invalid"),u("Enter a dial code to validate.");return}c("loading"),u("");try{const _=await L_(g),h=_==null?void 0:_.result,y=h==null?void 0:h.dialcodes;Array.isArray(y)&&y.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.")}},m=()=>a==="loading"?l.jsx(ii,{size:16,className:L.dialcodeSpinner}):a==="valid"?l.jsx(Vd,{size:16,color:"var(--sbx-success, #2e7d32)"}):a==="invalid"?l.jsx(aa,{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:g=>{i.onChange(g),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"}),m()]}),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})]})},uI="_form_szqex_1",dI="_ungrouped_szqex_7",fI="_noFields_szqex_18",Lo={form:uI,ungrouped:dI,noFields:fI},hI=({nodeMetadata:e,activeTab:t,isRoot:r,isFolder:n,editorMode:s,onFormValueChange:i,onFormStatusChange:o})=>{var me,ve,be,K;const a=ue(M=>M.editorConfig),c=ue(M=>M.rootFormConfig),d=ue(M=>M.unitFormConfig),{organisationFramework:u,targetFrameworks:f,isLoading:m}=Ph((me=a==null?void 0:a.context)==null?void 0:me.framework,(ve=a==null?void 0:a.context)==null?void 0:ve.targetFWIds),{frameworks:g,collectionAdditionalCategories:_}=vE((be=a==null?void 0:a.context)==null?void 0:be.channel),h=g==null?void 0:g.map(M=>({label:M.name,value:M.identifier})),y={organisationFramework:u,targetFrameworks:f,orgFrameworks:h,channelAdditionalCategories:_},v=Re(M=>M.selectedNodeId),b=Re(M=>M.treeCache),x=v?b[v]??{}:{},w={...e,...x},C=r?c:d,D=C||(((K=a==null?void 0:a.config.hierarchy)==null?void 0:K.formConfig)??[]),j=xE(D,w,y,r),k=j.filter(M=>M.tab===t&&M.inputType!=="appIcon"&&M.visible!==!1),$=mE({mode:"onChange",defaultValues:Object.fromEntries(j.map(M=>{const G=["multiselect","chips","keywords","tagsinput"],P=["nestedselect"];return G.includes(M.inputType)?[M.code,M.currentValue??M.defaultValue??[]]:P.includes(M.inputType)?[M.code,M.currentValue??M.defaultValue??{}]:[M.code,M.currentValue??M.defaultValue??""]}))});NE($,j);const{updateNode:N}=Re(),A=p.useRef(j);A.current=j;const U=p.useRef(v);U.current=v;const R=p.useRef(i);R.current=i;const B=p.useRef(o);B.current=o,p.useEffect(()=>{const M=U.current;if(M){const G=Object.fromEntries(A.current.filter(P=>P.currentValue!==void 0&&P.currentValue!==null).map(P=>[P.code,P.currentValue]));Object.keys(G).length>0&&N(M,G)}$.trigger().then(()=>{const G=$.formState.errors,P=A.current,Y=Array.from(new Set(Object.keys(G).map(W=>{var oe;return(oe=P.find(pe=>pe.code===W))==null?void 0:oe.tab}).filter(Boolean)));B.current(Object.keys(G).length===0,Y)})},[]),p.useEffect(()=>{const M=$.watch((G,{name:P})=>{const Y=U.current;if(!Y)return;const W=A.current,oe=new Set(W.map(re=>re.code));if(P&&oe.has(P)){let re=$.getValues(P);P==="dialcodes"&&(re=Array.isArray(re)?re:re?[re]:[]),N(Y,{[P]:re}),R.current({[P]:re})}else if(!P){const re=$.getValues(),se=Object.fromEntries(Object.entries(re).filter(([le])=>oe.has(le)));Object.keys(se).length>0&&(N(Y,se),R.current(se))}const pe=$.formState.errors,Ne=Array.from(new Set(Object.keys(pe).map(re=>{var se;return(se=W.find(le=>le.code===re))==null?void 0:se.tab}).filter(Boolean)));B.current(Object.keys(pe).length===0,Ne)});return()=>M.unsubscribe()},[$]);const F=s!=="edit",J=k.reduce((M,G)=>{const P=M[M.length-1];return P&&P.section===G.section?P.fields.push(G):M.push({section:G.section,fields:[G]}),M},[]),ie=M=>{const G={key:M.code,name:M.code,label:M.label,required:M.required,disabled:F||M.editable===!1};switch(M.inputType){case"textarea":return l.jsx(ku,{...G,multiline:!0,maxLength:M.maxLength});case"select":return l.jsx(mD,{...G,options:M.options??[]});case"multiselect":return l.jsx(yD,{...G,options:M.options??[]});case"chips":return l.jsx(vD,{...G});case"radio":return l.jsx(bD,{...G,options:M.options??[]});case"appIcon":return l.jsx(sI,{...G,nodeId:v??""});case"datepicker":case"datetime":return l.jsx(iI,{...G});case"keywords":case"tagsinput":return l.jsx(oI,{...G});case"nestedselect":return l.jsx(aI,{...G,levels:M.levels??[]});case"license":return l.jsx(lI,{...G});case"dialcode":return l.jsx(cI,{...G});default:return l.jsx(ku,{...G,maxLength:M.maxLength})}};return l.jsx(tE,{...$,children:l.jsxs("div",{className:Lo.form,children:[J.map((M,G)=>{const P=M.section?bE[M.section]:void 0;return P?l.jsx(ME,{title:P.title,description:P.description,children:M.fields.map(ie)},M.section??G):l.jsx("div",{className:Lo.ungrouped,children:M.fields.map(ie)},G)}),k.length===0&&!m&&l.jsx("p",{className:Lo.noFields,children:"No fields configured for this tab."})]})})};function Bh(e,t,r){const n=e.slice();return n.splice(r<0?n.length+r:r,0,n.splice(t,1)[0]),n}function pI(e,t){return e.reduce((r,n,s)=>{const i=t.get(n);return i&&(r[s]=i),r},Array(e.length))}function Js(e){return e!==null&&e>=0}function gI(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 mI(e){return typeof e=="boolean"?{draggable:e,droppable:e}:e}const Uh=e=>{let{rects:t,activeIndex:r,overIndex:n,index:s}=e;const i=Bh(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}},ei={scaleX:1,scaleY:1},yI=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,...ei}:null}const c=vI(i,s,r);return s>r&&s<=o?{x:0,y:-a.height-c,...ei}:s<r&&s>=o?{x:0,y:a.height+c,...ei}:{x:0,y:0,...ei}};function vI(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 Vh="Sortable",zh=p.createContext({activeIndex:-1,containerId:Vh,disableTransforms:!1,items:[],overIndex:-1,useDragOverlay:!1,sortedRects:[],strategy:Uh,disabled:{draggable:!1,droppable:!1}});function bI(e){let{children:t,id:r,items:n,strategy:s=Uh,disabled:i=!1}=e;const{active:o,dragOverlay:a,droppableRects:c,over:d,measureDroppableContainers:u}=$d(),f=js(Vh,r),m=a.rect!==null,g=p.useMemo(()=>n.map(D=>typeof D=="object"&&"id"in D?D.id:D),[n]),_=o!=null,h=o?g.indexOf(o.id):-1,y=d?g.indexOf(d.id):-1,v=p.useRef(g),b=!gI(g,v.current),x=y!==-1&&h===-1||b,w=mI(i);Kt(()=>{b&&_&&u(g)},[b,g,_,u]),p.useEffect(()=>{v.current=g},[g]);const C=p.useMemo(()=>({activeIndex:h,containerId:f,disabled:w,disableTransforms:x,items:g,overIndex:y,useDragOverlay:m,sortedRects:pI(g,c),strategy:s}),[h,f,w.draggable,w.droppable,x,g,y,c,m,s]);return p.createElement(zh.Provider,{value:C},t)}const _I=e=>{let{id:t,items:r,activeIndex:n,overIndex:s}=e;return Bh(r,n,s).indexOf(t)},wI=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},xI={duration:200,easing:"ease"},qh="transform",SI=Ar.Transition.toString({property:qh,duration:0,easing:"linear"}),CI={roleDescription:"sortable"};function OI(e){let{disabled:t,index:r,node:n,rect:s}=e;const[i,o]=p.useState(null),a=p.useRef(r);return Kt(()=>{if(!t&&r!==a.current&&n.current){const c=s.current;if(c){const d=Bn(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]),p.useEffect(()=>{i&&o(null)},[i]),i}function EI(e){let{animateLayoutChanges:t=wI,attributes:r,disabled:n,data:s,getNewIndex:i=_I,id:o,strategy:a,resizeObserverConfig:c,transition:d=xI}=e;const{items:u,containerId:f,activeIndex:m,disabled:g,disableTransforms:_,sortedRects:h,overIndex:y,useDragOverlay:v,strategy:b}=p.useContext(zh),x=DI(n,g),w=u.indexOf(o),C=p.useMemo(()=>({sortable:{containerId:f,index:w,items:u},...s}),[f,s,w,u]),D=p.useMemo(()=>u.slice(u.indexOf(o)),[u,o]),{rect:j,node:k,isOver:$,setNodeRef:N}=$m({id:o,data:C,disabled:x.droppable,resizeObserverConfig:{updateMeasurementsFor:D,...c}}),{active:A,activatorEvent:U,activeNodeRect:R,attributes:B,setNodeRef:F,listeners:J,isDragging:ie,over:me,setActivatorNodeRef:ve,transform:be}=Fd({id:o,data:C,attributes:{...CI,...r},disabled:x.draggable}),K=Cg(N,F),M=!!A,G=M&&!_&&Js(m)&&Js(y),P=!v&&ie,Y=P&&G?be:null,oe=G?Y??(a??b)({rects:h,activeNodeRect:R,activeIndex:m,overIndex:y,index:w}):null,pe=Js(m)&&Js(y)?i({id:o,items:u,activeIndex:m,overIndex:y}):w,Ne=A==null?void 0:A.id,re=p.useRef({activeId:Ne,items:u,newIndex:pe,containerId:f}),se=u!==re.current.items,le=t({active:A,containerId:f,isDragging:ie,isSorting:M,id:o,index:w,items:u,newIndex:re.current.newIndex,previousItems:re.current.items,previousContainerId:re.current.containerId,transition:d,wasDragging:re.current.activeId!=null}),Le=OI({disabled:!le,index:w,node:k,rect:j});return p.useEffect(()=>{M&&re.current.newIndex!==pe&&(re.current.newIndex=pe),f!==re.current.containerId&&(re.current.containerId=f),u!==re.current.items&&(re.current.items=u)},[M,pe,f,u]),p.useEffect(()=>{if(Ne===re.current.activeId)return;if(Ne&&!re.current.activeId){re.current.activeId=Ne;return}const Te=setTimeout(()=>{re.current.activeId=Ne},50);return()=>clearTimeout(Te)},[Ne]),{active:A,activeIndex:m,attributes:B,data:C,rect:j,index:w,newIndex:pe,items:u,isOver:$,isSorting:M,isDragging:ie,listeners:J,node:k,overIndex:y,over:me,setNodeRef:K,setActivatorNodeRef:ve,setDroppableNodeRef:N,setDraggableNodeRef:F,transform:Le??oe,transition:ze()};function ze(){if(Le||se&&re.current.newIndex===w)return SI;if(!(P&&!Bi(U)||!d)&&(M||le))return Ar.Transition.toString({...d,property:qh})}}function DI(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 Ai(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 II=[we.Down,we.Right,we.Up,we.Left],NI=(e,t)=>{let{context:{active:r,collisionRect:n,droppableRects:s,droppableContainers:i,over:o,scrollableAncestors:a}}=t;if(II.includes(e.code)){if(e.preventDefault(),!r||!n)return;const c=[];i.getEnabled().forEach(f=>{if(!f||f!=null&&f.disabled)return;const m=s.get(f.id);if(m)switch(e.code){case we.Down:n.top<m.top&&c.push(f);break;case we.Up:n.top>m.top&&c.push(f);break;case we.Left:n.left>m.left&&c.push(f);break;case we.Right:n.left<m.left&&c.push(f);break}});const d=Ug({collisionRect:n,droppableRects:s,droppableContainers:c});let u=wd(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),m=i.get(u),g=m?s.get(m.id):null,_=m==null?void 0:m.node.current;if(_&&g&&f&&m){const y=Ui(_).some((D,j)=>a[j]!==D),v=Hh(f,m),b=TI(f,m),x=y||!v?{x:0,y:0}:{x:b?n.width-g.width:0,y:b?n.height-g.height:0},w={x:g.left,y:g.top};return x.x&&x.y?w:ys(w,x)}}}};function Hh(e,t){return!Ai(e)||!Ai(t)?!1:e.data.current.sortable.containerId===t.data.current.sortable.containerId}function TI(e,t){return!Ai(e)||!Ai(t)||!Hh(e,t)?!1:e.data.current.sortable.index<t.data.current.sortable.index}const jI="_row_11nth_1",RI="_removeBtn_11nth_14",kI="_grip_11nth_17",AI="_ctIcon_11nth_34",PI="_info_11nth_38",MI="_name_11nth_46",LI="_meta_11nth_55",Lr={row:jI,removeBtn:RI,grip:kI,ctIcon:AI,info:PI,name:MI,meta:LI},FI={video:Qa,pdf:za,h5p:qa,scorm:Wa,audio:Ha,quiz:Va,default:Vn},$I=({item:e,onRemove:t,isEditable:r})=>{const n=eo(e),s=FI[n.key]??Vn,{attributes:i,listeners:o,setNodeRef:a,transform:c,transition:d,isDragging:u}=EI({id:e.id,disabled:!r}),f={transform:Ar.Transform.toString(c),transition:d,opacity:u?.5:1};return l.jsxs("div",{ref:a,style:f,className:Lr.row,role:"listitem",children:[r&&l.jsx("span",{className:Lr.grip,...i,...o,"aria-label":"Drag to reorder",children:l.jsx(Hd,{size:15})}),l.jsx("span",{className:[`sbx-ct-sq--${n.key}`,Lr.ctIcon].join(" "),"aria-hidden":"true",children:l.jsx(s,{size:14})}),l.jsxs("div",{className:Lr.info,children:[l.jsx("span",{className:Lr.name,title:e.name,children:e.name}),l.jsx("span",{className:Lr.meta,children:n.label})]}),l.jsx("span",{className:`sbx-ct-badge--${n.key}`,children:n.label}),r&&l.jsx("button",{type:"button",className:Lr.removeBtn,onClick:()=>t(e.id),"aria-label":`Remove ${e.name}`,children:l.jsx(on,{size:14})})]})},BI="_container_lzvke_1",UI="_header_lzvke_7",VI="_heading_lzvke_13",zI="_count_lzvke_21",qI="_list_lzvke_30",HI="_emptyState_lzvke_36",WI="_addRow_lzvke_52",Fr={container:BI,header:UI,heading:VI,count:zI,list:qI,emptyState:HI,addRow:WI},KI=({editorMode:e})=>{const{selectedNodeId:t,getChildrenOf:r,reorderChildren:n,deleteNode:s}=Re(),i=t?r(t):[],o=e==="edit",a=vd(na(Vi,{activationConstraint:{distance:5}}),na($a,{coordinateGetter:NI})),c=p.useCallback(u=>{const{active:f,over:m}=u;if(!m||f.id===m.id||!t)return;const g=Re.getState().getChildrenOf(t),_=g.findIndex(y=>y.id===f.id),h=g.findIndex(y=>y.id===m.id);_<0||h<0||n(t,_,h)},[t,n]),d=p.useCallback(u=>{window.confirm("Remove this content from the unit?")&&s(u)},[s]);return t?l.jsxs("div",{className:Fr.container,children:[l.jsxs("div",{className:Fr.header,children:[l.jsx("span",{className:Fr.heading,children:"Content in this unit"}),l.jsx("span",{className:Fr.count,children:i.length})]}),i.length>0?l.jsx(Ld,{sensors:a,collisionDetection:Bg,onDragEnd:c,children:l.jsx(bI,{items:i.map(u=>u.id),strategy:yI,children:l.jsx("div",{className:Fr.list,role:"list",children:i.map(u=>l.jsx($I,{item:u,onRemove:d,isEditable:o},u.id))})})}):l.jsxs("div",{className:Fr.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:Fr.addRow,type:"button","aria-label":"Add content to unit",children:[l.jsx(As,{size:14})," Add content"]})]}):null},QI="_dropZone_ijo5w_1",GI="_active_ijo5w_14",Mu={dropZone:QI,active:GI},YI=({isActive:e,label:t="Drop here",nodeId:r,className:n})=>l.jsx("div",{className:`${Mu.dropZone} ${e?Mu.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 XI(e){var o;const t={status:["Live"],...e.filters??{}};e.channel&&(t.channel=e.channel);const n=((o=(await Me.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 ZI(e){var r,n;return(n=(r=(await Me.get(`/action/content/v3/read/${e}`)).data)==null?void 0:r.result)==null?void 0:n.content}const JI="_contentPlayerRoot_ryh6z_1",eN="_stage_ryh6z_9",tN="_playerHeader_ryh6z_19",rN="_playerHeaderThumb_ryh6z_33",nN="_playerHeaderTitle_ryh6z_43",sN="_typeBadge_ryh6z_53",iN="_typeDot_ryh6z_92",oN="_aspectRatio_ryh6z_99",aN="_playerFrame_ryh6z_112",lN="_coverOverlay_ryh6z_120",cN="_coverHidden_ryh6z_132",uN="_coverThumb_ryh6z_137",dN="_coverPlayRing_ryh6z_146",fN="_coverPlayIcon_ryh6z_159",hN="_coverLabel_ryh6z_168",pN="_coverSkeleton_ryh6z_174",gN="_playerWrapper_ryh6z_200",mN="_infoStrip_ryh6z_210",yN="_infoChip_ryh6z_226",vN="_infoChipLabel_ryh6z_245",bN="_infoChipIcon_ryh6z_254",_N="_playerError_ryh6z_260",wN="_playerErrorIcon_ryh6z_274",xN="_playerErrorMsg_ryh6z_279",SN="_qumlRoot_ryh6z_286",Pe={contentPlayerRoot:JI,stage:eN,playerHeader:tN,playerHeaderThumb:rN,playerHeaderTitle:nN,typeBadge:sN,typeDot:iN,aspectRatio:oN,playerFrame:aN,coverOverlay:lN,coverHidden:cN,coverThumb:uN,coverPlayRing:dN,coverPlayIcon:fN,coverLabel:hN,coverSkeleton:pN,playerWrapper:gN,infoStrip:mN,infoChip:yN,infoChipLabel:vN,infoChipIcon:bN,playerError:_N,playerErrorIcon:wN,playerErrorMsg:xN,qumlRoot:SN},CN=[{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 ON(e){return CN.find(t=>t.mimes.includes(e))??{key:"other",label:"Content",icon:"📱"}}const EN={"pdf-player":["application/pdf"],"video-player":["video/mp4","video/webm"],"epub-player":["application/epub"]},DN={"pdf-player":"/assets/sunbird-pdf-player.js","video-player":"/assets/sunbird-video-player.js","epub-player":"/assets/sunbird-epub-player.js"},IN={"pdf-player":"sunbird-pdf-player","video-player":"sunbird-video-player","epub-player":"sunbird-epub-player"},NN="/content/preview/preview.html?webview=true&build_number=2.8.0.e552fcd";function Fo(e){for(const[t,r]of Object.entries(EN))if(r.includes(e))return t;return"default-player"}function TN(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 jN(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 RN(e,t,r=100){await jN(DN[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 kN=[{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 AN({node:e}){const t=e.metadata??{},r=kN.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:Pe.infoStrip,children:r.map(n=>l.jsxs("div",{className:Pe.infoChip,children:[n.icon&&l.jsx("span",{className:Pe.infoChipIcon,children:n.icon}),l.jsx("span",{className:Pe.infoChipLabel,children:n.label}),n.val]},n.key))}):null}function PN({node:e,hidden:t}){var n;const r=e.appIcon??((n=e.metadata)==null?void 0:n.appIcon);return l.jsx("div",{className:`${Pe.coverOverlay} ${t?Pe.coverHidden:""}`,children:r?l.jsxs(l.Fragment,{children:[l.jsx("img",{src:r,alt:e.name,className:Pe.coverThumb}),l.jsx("div",{className:Pe.coverPlayRing,children:l.jsx("div",{className:Pe.coverPlayIcon})}),l.jsx("span",{className:Pe.coverLabel,children:"Loading preview…"})]}):l.jsx("div",{className:Pe.coverSkeleton})})}function MN({message:e}){return l.jsxs("div",{className:Pe.playerError,children:[l.jsx("span",{className:Pe.playerErrorIcon,children:"⚠"}),l.jsx("span",{className:Pe.playerErrorMsg,children:e})]})}function LN({mimeType:e}){const t=ON(e);return l.jsxs("span",{className:Pe.typeBadge,"data-type":t.key,children:[l.jsx("span",{className:Pe.typeDot}),t.label]})}const ja=({node:e,editorMode:t,type:r})=>{var s;if(r==="quml")return l.jsx($N,{node:e,editorMode:t});const n=e.appIcon??((s=e.metadata)==null?void 0:s.appIcon);return l.jsxs("div",{className:Pe.contentPlayerRoot,children:[l.jsxs("div",{className:Pe.stage,children:[l.jsxs("div",{className:Pe.playerHeader,children:[n&&l.jsx("img",{src:n,alt:"",className:Pe.playerHeaderThumb}),l.jsx("span",{className:Pe.playerHeaderTitle,children:e.name}),l.jsx(LN,{mimeType:e.mimeType??""})]}),l.jsx(FN,{node:e})]}),l.jsx(AN,{node:e})]})};function FN({node:e}){var y;const t=ue(v=>v.editorConfig),[r,n]=p.useState(()=>Fo(e.mimeType??"")),[s,i]=p.useState(!1),[o,a]=p.useState(null),[c,d]=p.useState(e.metadata??{}),[u,f]=p.useState(!1),m=p.useRef(null),g=p.useRef(null),_=((y=t==null?void 0:t.config)==null?void 0:y.previewCdnUrl)??NN;p.useEffect(()=>{let v=!1;return f(!1),i(!1),a(null),d(e.metadata??{}),n(Fo(e.mimeType??"")),ZI(e.identifier).then(b=>{if(v)return;const x={...e.metadata??{},...b};d(x);const w=b.mimeType??e.mimeType??"";n(Fo(w)),f(!0)}).catch(()=>{v||f(!0)}),()=>{v=!0}},[e.identifier]);const h=TN(e,c,t);return p.useEffect(()=>{if(!u||r!=="default-player")return;const v=m.current;if(!v)return;v.src=_;const b=()=>{try{const w=v.contentWindow;if(typeof(w==null?void 0:w.initializePreview)!="function"){a("Preview player unavailable. Check that /content/preview is reachable.");return}w.initializePreview(h),setTimeout(()=>i(!0),300)}catch(w){console.error("[ContentPlayer] initializePreview failed",w),a("Failed to initialize the content player.")}},x=()=>a("Preview player could not be loaded.");return v.addEventListener("load",b),v.addEventListener("error",x),()=>{v.removeEventListener("load",b),v.removeEventListener("error",x),v.src=""}},[e.identifier,r,_,u]),p.useEffect(()=>{if(!u||r==="default-player")return;const v=g.current;if(!v)return;const b=IN[r];if(!b)return;const x=h;RN(b,r).then(()=>{if(!g.current)return;if(!customElements.get(b)){n("default-player");return}const w=document.createElement(b);w.setAttribute("player-config",JSON.stringify(x)),w.addEventListener("playerEvent",()=>{}),w.addEventListener("telemetryEvent",()=>{}),v.innerHTML="",v.appendChild(w),setTimeout(()=>{try{w.playerConfig=x}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:Pe.aspectRatio,children:[o?l.jsx(MN,{message:o}):l.jsx(PN,{node:e,hidden:s}),r==="default-player"?l.jsx("iframe",{ref:m,id:"contentPlayer",title:e.name,className:Pe.playerFrame,name:"contentPlayer",allowFullScreen:!0}):l.jsx("div",{ref:g,className:Pe.playerFrame})]})}function $N({node:e,editorMode:t}){const r=ue(s=>s.editorConfig),n=p.useRef(null);return p.useEffect(()=>{var a;if(!n.current)return;const s=r==null?void 0:r.context,i={context:{mode:t==="edit"?"edit":"play",pdata:{id:((a=s==null?void 0:s.pdata)==null?void 0:a.id)??"sunbird.portal",ver:"1.0",pid:"sunbird-portal"},contentId:e.identifier,sid:(s==null?void 0:s.sid)??"",uid:(s==null?void 0:s.uid)??"",channel:(s==null?void 0:s.channel)??"",did:(s==null?void 0:s.did)??""},config:{enable:!1,showShare:!1,showDownload:!1,showReplay:!0,showExit:!1},metadata:e.metadata??{},data:{}},o=document.createElement("sunbird-quml-player");o.setAttribute("player-config",JSON.stringify(i)),n.current.innerHTML="",n.current.appendChild(o)},[e.identifier,t]),l.jsx("div",{className:Pe.qumlRoot,children:l.jsx("div",{ref:n,className:Pe.playerWrapper})})}const BN="_overlay_ifddx_1",UN="_modal_ifddx_11",VN="_header_ifddx_21",zN="_body_ifddx_37",qN="_hint_ifddx_43",HN="_list_ifddx_49",WN="_item_ifddx_55",KN="_selected_ifddx_68",QN="_empty_ifddx_73",GN="_footer_ifddx_79",YN="_cancelBtn_ifddx_87",XN="_moveBtn_ifddx_95",Ft={overlay:BN,modal:UN,header:VN,body:zN,hint:qN,list:HN,item:WN,selected:KN,empty:QN,footer:GN,cancelBtn:YN,moveBtn:XN};function ZN(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 JN=({resourceId:e,resourceName:t,currentUnitId:r,onClose:n})=>{var u;const{treeData:s,moveNode:i}=Re(),o=ZN(s,((u=s[0])==null?void 0:u.id)??"",r),[a,c]=p.useState(null),d=()=>{a&&(i(e,r,a),n())};return l.jsx("div",{className:Ft.overlay,role:"dialog","aria-label":"Move resource",children:l.jsxs("div",{className:Ft.modal,children:[l.jsxs("div",{className:Ft.header,children:[l.jsxs("span",{children:['Move "',t,'"']}),l.jsx("button",{onClick:n,"aria-label":"Close",children:l.jsx(on,{size:16})})]}),l.jsxs("div",{className:Ft.body,children:[l.jsx("p",{className:Ft.hint,children:"Select a unit to move this content to:"}),l.jsxs("ul",{className:Ft.list,children:[o.map(f=>l.jsxs("li",{className:`${Ft.item} ${a===f.id?Ft.selected:""}`,onClick:()=>c(f.id),children:[l.jsx(ly,{size:14}),l.jsx("span",{children:f.name})]},f.id)),o.length===0&&l.jsx("li",{className:Ft.empty,children:"No other units available"})]})]}),l.jsxs("div",{className:Ft.footer,children:[l.jsx("button",{className:Ft.cancelBtn,onClick:n,children:"Cancel"}),l.jsx("button",{className:Ft.moveBtn,onClick:d,disabled:!a,children:"Move here"})]})]})})},eT="_overlay_16at9_1",tT="_modal_16at9_11",rT="_header_16at9_21",nT="_body_16at9_37",sT="_table_16at9_43",iT="_pageInput_16at9_61",oT="_empty_16at9_68",aT="_footer_16at9_74",lT="_cancelBtn_16at9_82",cT="_saveBtn_16at9_90",tr={overlay:eT,modal:tT,header:rT,body:nT,table:sT,pageInput:iT,empty:oT,footer:aT,cancelBtn:lT,saveBtn:cT};function uT(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 dT=({onClose:e})=>{const{treeData:t,updateNode:r}=Re(),n=uT(t),[s,i]=p.useState(()=>Object.fromEntries(n.map(a=>{var c;return[a.id,String(((c=a.metadata)==null?void 0:c.pageNumber)??"")]}))),o=p.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:tr.overlay,role:"dialog","aria-label":"Assign Page Numbers",children:l.jsxs("div",{className:tr.modal,children:[l.jsxs("div",{className:tr.header,children:[l.jsx("span",{children:"Assign Page Numbers"}),l.jsx("button",{onClick:e,"aria-label":"Close",children:l.jsx(on,{size:16})})]}),l.jsx("div",{className:tr.body,children:n.length===0?l.jsx("p",{className:tr.empty,children:"No content items found in this collection."}):l.jsxs("table",{className:tr.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:tr.pageInput})})]},a.id))})]})}),l.jsxs("div",{className:tr.footer,children:[l.jsx("button",{className:tr.cancelBtn,onClick:e,children:"Cancel"}),l.jsxs("button",{className:tr.saveBtn,onClick:o,children:[l.jsx(yy,{size:14})," Save"]})]})]})})},fT="_container_1a7t2_1",hT="_panelHeader_1a7t2_10",pT="_panelHeaderLeft_1a7t2_19",gT="_panelCollapseBtn_1a7t2_27",mT="_titleRow_1a7t2_46",yT="_field_1a7t2_47",vT="_moveBtn_1a7t2_64",bT="_icon_1a7t2_84",_T="_nameInput_1a7t2_93",wT="_fieldHeader_1a7t2_118",xT="_label_1a7t2_124",ST="_fieldCount_1a7t2_133",CT="_chips_1a7t2_170",OT="_chip_1a7t2_170",ET="_chipRemove_1a7t2_188",DT="_keywordInput_1a7t2_202",IT="_input_1a7t2_207",NT="_addBtn_1a7t2_220",TT="_radioGroup_1a7t2_234",jT="_radioLabel_1a7t2_239",$e={container:fT,panelHeader:hT,panelHeaderLeft:pT,panelCollapseBtn:gT,titleRow:mT,field:yT,moveBtn:vT,icon:bT,nameInput:_T,fieldHeader:wT,label:xT,fieldCount:ST,chips:CT,chip:OT,chipRemove:ET,keywordInput:DT,input:IT,addBtn:NT,radioGroup:TT,radioLabel:jT},RT=({node:e,editorMode:t,onMoveClick:r,reorderDialog:n})=>{var A,U;const{updateNode:s,markDirty:i}=Re(),o=t==="edit",a=eo(e),c=ue(R=>R.relationalFormConfig),d=R=>c==null?void 0:c.find(B=>B.code===R),u=R=>!c||!!d(R),f=(R,B)=>{var F;return((F=d(R))==null?void 0:F.label)||B},[m,g]=p.useState(!0),_=((A=e.metadata)==null?void 0:A.relationalMetadata)??{},[h,y]=p.useState(_.name??e.name??""),[v,b]=p.useState(""),[x,w]=p.useState(Array.isArray(_.keywords)?_.keywords:Array.isArray((U=e.metadata)==null?void 0:U.keywords)?e.metadata.keywords:[]),[C,D]=p.useState(!!_.optional);p.useEffect(()=>{var B,F;const R=((B=e.metadata)==null?void 0:B.relationalMetadata)??{};y(R.name??e.name??""),w(Array.isArray(R.keywords)?R.keywords:Array.isArray((F=e.metadata)==null?void 0:F.keywords)?e.metadata.keywords:[]),D(!!R.optional)},[e.id]);const j=()=>{h.trim()&&h!==e.name&&(s(e.id,{name:h.trim()}),i())},k=()=>{const R=v.trim();if(R&&!x.includes(R)){const B=[...x,R];w(B),s(e.id,{keywords:B}),i()}b("")},$=R=>{const B=x.filter(F=>F!==R);w(B),s(e.id,{keywords:B}),i()},N=R=>{D(R),s(e.id,{optional:R}),i()};return l.jsxs("div",{className:$e.container,children:[l.jsxs("div",{className:$e.panelHeader,children:[l.jsxs("div",{className:$e.panelHeaderLeft,children:[l.jsx("span",{className:`sbx-ct-badge--${a.key}`,children:a.label}),o&&l.jsx("button",{type:"button",className:$e.moveBtn,onClick:r,children:"Move to another unit"})]}),l.jsx("button",{type:"button",className:$e.panelCollapseBtn,onClick:()=>g(R=>!R),"aria-expanded":m,"aria-label":m?"Collapse metadata panel":"Expand metadata panel",title:m?"Collapse":"Expand",children:m?l.jsx(ks,{size:15}):l.jsx(iy,{size:15})})]}),m&&l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:$e.titleRow,children:[e.appIcon&&l.jsx("img",{src:e.appIcon,alt:"icon",className:$e.icon}),l.jsx("input",{type:"text",className:$e.nameInput,value:h,disabled:!o,onChange:R=>y(R.target.value),onBlur:j,placeholder:"Content name"})]}),u("keywords")&&l.jsxs("div",{className:$e.field,children:[l.jsx("div",{className:$e.fieldHeader,children:l.jsxs("label",{className:$e.label,children:[f("keywords","Keywords"),x.length>0&&l.jsx("span",{className:$e.fieldCount,children:x.length})]})}),x.length>0&&l.jsx("div",{className:$e.chips,children:x.map(R=>l.jsxs("span",{className:$e.chip,children:[R,o&&l.jsx("button",{type:"button",className:$e.chipRemove,onClick:()=>$(R),children:"×"})]},R))}),o&&l.jsxs("div",{className:$e.keywordInput,children:[l.jsx("input",{type:"text",className:$e.input,value:v,placeholder:"Add keyword and press Enter",onChange:R=>b(R.target.value),onKeyDown:R=>{R.key==="Enter"&&(R.preventDefault(),k())}}),l.jsx("button",{type:"button",className:$e.addBtn,onClick:k,children:"Add"})]})]}),u("optional")&&l.jsxs("div",{className:$e.field,children:[l.jsx("label",{className:$e.label,children:f("optional","Optional in Collection")}),l.jsxs("div",{className:$e.radioGroup,children:[l.jsxs("label",{className:$e.radioLabel,children:[l.jsx("input",{type:"radio",name:`optional-${e.id}`,checked:C===!0,onChange:()=>N(!0),disabled:!o}),"Yes"]}),l.jsxs("label",{className:$e.radioLabel,children:[l.jsx("input",{type:"radio",name:`optional-${e.id}`,checked:C===!1,onChange:()=>N(!1),disabled:!o}),"No"]})]})]})]}),n]})},kT="_iconBtn_vl14u_1",AT="_editable_vl14u_14",PT="_iconImg_vl14u_26",MT="_placeholder_vl14u_34",LT="_removeBtn_vl14u_41",rs={iconBtn:kT,editable:AT,iconImg:PT,placeholder:MT,removeBtn:LT},FT=({nodeId:e,value:t,editable:r})=>{const[n,s]=p.useState(!1),{updateNode:i,markDirty:o}=Re(),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:[rs.iconBtn,r?rs.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:rs.iconImg}):l.jsx("div",{className:rs.placeholder,children:l.jsx(Wd,{size:18})}),t&&r&&l.jsx("button",{type:"button",className:rs.removeBtn,onClick:c,"aria-label":"Remove icon",children:l.jsx(Ka,{size:11})})]}),n&&l.jsx($h,{nodeId:e,currentValue:t,onSelect:a,onClose:()=>s(!1)})]})},$T="_leafContentLayout_1osey_1",BT="_container_1osey_17",UT="_emptyState_1osey_26",VT="_titleRow_1osey_36",zT="_nodeTitle_1osey_52",qT="_formArea_1osey_74",HT="_contentListArea_1osey_78",WT="_dropZone_1osey_83",KT="_reviewComment_1osey_90",QT="_reviewCommentLabel_1osey_103",GT="_reviewCommentText_1osey_109",zt={leafContentLayout:$T,container:BT,emptyState:UT,titleRow:VT,nodeTitle:zT,formArea:qT,contentListArea:HT,dropZone:WT,reviewComment:KT,reviewCommentLabel:QT,reviewCommentText:GT},YT=["application/vnd.sunbird.questionset"],XT=({editorMode:e,onToolbarEvent:t})=>{var A,U,R,B;const[r,n]=p.useState("details"),[s,i]=p.useState([]),[o,a]=p.useState(null),[c,d]=p.useState(!1),u=p.useRef(null),f=p.useRef(),{selectedNodeId:m,breadcrumb:g,activeNodeMeta:_,updateNode:h,treeData:y}=Re(),v=ue(F=>{var J,ie,me,ve;return((ie=(J=F.editorConfig)==null?void 0:J.context)==null?void 0:ie.contentId)??((ve=(me=F.editorConfig)==null?void 0:me.context)==null?void 0:ve.identifier)??""}),b=m?Wh(y,m):null,x=!!b&&!b.parent,w=!!(b!=null&&b.isFolder),C=b&&YT.includes(b.mimeType??""),D=b&&!b.isFolder&&!C&&!x,j=((A=b==null?void 0:b.metadata)==null?void 0:A.rejectComment)??(x?(R=(U=y[0])==null?void 0:U.metadata)==null?void 0:R.rejectComment:void 0),k=p.useCallback(()=>{const F=u.current;if(!F||!m)return;const J=F.innerText.trim();clearTimeout(f.current),f.current=setTimeout(()=>{h(m,{name:J})},600)},[m,h]),$=p.useCallback(F=>{t({action:"onFormValueChange",data:F})},[t]),N=p.useCallback((F,J)=>{i(J),t({action:"onFormStatusChange",data:{isValid:F,nodeId:m}})},[t,m]);return b?C?l.jsx(ja,{node:b,editorMode:e,type:"quml"}):D?l.jsxs("div",{className:zt.leafContentLayout,children:[l.jsx(ja,{node:b,editorMode:e,type:"content"}),l.jsx(RT,{node:b,editorMode:e,onMoveClick:()=>a(b.identifier),reorderDialog:o?l.jsx(JN,{resourceId:o,resourceName:b.name,currentUnitId:b.parent??"",onClose:()=>a(null)}):null})]}):l.jsxs("div",{className:zt.container,children:[l.jsx(WO,{crumbs:g}),j&&l.jsxs("div",{className:zt.reviewComment,role:"alert",children:[l.jsx("span",{className:zt.reviewCommentLabel,children:"Reviewer comment:"}),l.jsx("span",{className:zt.reviewCommentText,children:j})]}),l.jsxs("div",{className:zt.titleRow,children:[x&&m&&l.jsx(FT,{nodeId:m,value:String(b.appIcon??((B=b.metadata)==null?void 0:B.appIcon)??""),editable:e==="edit"}),l.jsx("div",{ref:u,className:zt.nodeTitle,contentEditable:e==="edit",suppressContentEditableWarning:!0,onInput:k,onBlur:k,"data-placeholder":"Untitled","aria-label":"Node title",children:b.name})]}),l.jsx(ZO,{activeTab:r,onChange:F=>n(F),errorTabs:s,visibleTabs:x?void 0:["details"]}),l.jsx("div",{className:zt.formArea,children:l.jsx(hI,{nodeMetadata:_,activeTab:r,isRoot:x,isFolder:w,editorMode:e,onFormValueChange:$,onFormStatusChange:N},`${m??"none"}:${x?"root":"node"}`)}),(w||x)&&r==="details"&&l.jsx("div",{className:zt.contentListArea,children:l.jsx(KI,{editorMode:e})}),l.jsx(YI,{isActive:!1,label:"Drop to add content to this unit",nodeId:m??void 0,className:zt.dropZone}),c&&l.jsx(dT,{contentId:v,onClose:()=>d(!1)})]}):l.jsx("div",{className:zt.emptyState,children:l.jsx("p",{children:"Select a unit from the outline to edit its details"})})};function Wh(e,t){for(const r of e){if(r.id===t)return r;if(r.children){const n=Wh(r.children,t);if(n)return n}}}const Kh=Hi((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})}})),ZT=20;function Qh(){var d;const e=ue(u=>u.editorConfig),t=Re(u=>u.selectedNodeId),r=Re(u=>u.treeData),n=p.useCallback(()=>{if(!t||!r.length)return 0;function u(f,m,g=0){var _;for(const h of f){if(h.id===m)return g;if((_=h.children)!=null&&_.length){const y=u(h.children,m,g+1);if(y>=0)return y}}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[...yu];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:[...yu]}function JT(){const e=Kh(),t=ue(f=>{var m,g;return((g=(m=f.editorConfig)==null?void 0:m.context)==null?void 0:g.channel)??""}),r=Qh(),n=p.useRef(),s=p.useCallback(async(f="",m="all",g={},_=!0,h=!1)=>{var y,v,b,x,w;e.setLoading(!0);try{const C={status:["Live"],primaryCategory:m&&m!=="all"?[m]:r};(y=g==null?void 0:g.board)!=null&&y.length&&(C.board=g.board),(v=g==null?void 0:g.medium)!=null&&v.length&&(C.medium=g.medium),(b=g==null?void 0:g.gradeLevel)!=null&&b.length&&(C.gradeLevel=g.gradeLevel),(x=g==null?void 0:g.subject)!=null&&x.length&&(C.subject=g.subject),(w=g==null?void 0:g.primaryCategory)!=null&&w.length&&(C.primaryCategory=g.primaryCategory);const D=_?0:e.offset,{content:j,count:k}=await XI({filters:C,query:f,limit:f?50:ZT,offset:D,channel:t||void 0,sortBy:h?{name:"asc"}:{lastUpdatedOn:"desc"}});_?e.setContent(j,k):e.appendContent(j,k)}catch(C){console.error("[useLibrary] load error:",C)}finally{e.setLoading(!1)}},[r,t]);p.useEffect(()=>{s()},[t]);const i=p.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=p.useCallback(f=>{e.setFilter(f),s(e.searchQuery,f,e.advancedFilters,!0,e.sortAZ)},[e.searchQuery,e.advancedFilters,e.sortAZ,s]),a=p.useCallback(f=>{e.setAdvancedFilters(f),s(e.searchQuery,e.activeFilter,f,!0,e.sortAZ)},[e.searchQuery,e.activeFilter,e.sortAZ,s]),c=p.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=p.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 ej="_card_jzciw_1",tj="_addBtn_jzciw_17",rj="_dragging_jzciw_24",nj="_ctIcon_jzciw_29",sj="_info_jzciw_33",ij="_name_jzciw_41",oj="_meta_jzciw_50",aj="_addBtnMuted_jzciw_78",lj="_added_jzciw_87",cj="_addedBadge_jzciw_96",rr={card:ej,addBtn:tj,dragging:rj,ctIcon:nj,info:sj,name:ij,meta:oj,addBtnMuted:aj,added:lj,addedBadge:cj},uj={video:Qa,pdf:za,h5p:qa,scorm:Wa,audio:Ha,quiz:Va,default:Vn},dj=({item:e,onAdd:t,onPreview:r,isDraggable:n,isAdded:s})=>{var h,y;const i=eo(e),o=uj[i.key]??Vn,a=dl(),c=I1(),d=a&&!s&&c,{attributes:u,listeners:f,setNodeRef:m,isDragging:g}=Fd({id:e.identifier,disabled:!n||!a||!c,data:{type:"library-item",item:e}}),_=()=>{r&&r(e)};return l.jsxs("div",{ref:m,className:[rr.card,g?rr.dragging:"",s?rr.added:""].join(" "),"aria-label":e.name,...n?{...u,...f}:{},role:"listitem",onClick:_,children:[l.jsx("span",{className:[`sbx-ct-sq--${i.key}`,rr.ctIcon].join(" "),"aria-hidden":"true",children:l.jsx(o,{size:14})}),l.jsxs("div",{className:rr.info,children:[l.jsx("span",{className:rr.name,title:e.name,children:e.name}),l.jsxs("span",{className:rr.meta,children:[((h=e.organisation)==null?void 0:h[0])??e.channel??"",(y=e.organisation)!=null&&y[0]&&e.primaryCategory?" · ":"",e.primaryCategory??""]})]}),s&&l.jsx("span",{className:rr.addedBadge,"aria-label":"Already added",title:"Already added to this collection",children:l.jsx(Un,{size:12})}),!s&&l.jsx("button",{type:"button",className:[rr.addBtn,!d&&a?rr.addBtnMuted:""].join(" "),onClick:v=>{v.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(As,{size:14})})]})},fj="_chips_xhhaq_1",hj="_chip_xhhaq_1",Lu={chips:fj,chip:hj},pj=({filters:e,active:t,onChange:r})=>l.jsx("div",{className:Lu.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",Lu.chip].join(" "),onClick:()=>r(n.value),children:n.label},n.value))}),gj="_panel_1cl11_1",mj="_header_1cl11_10",yj="_headerTitle_1cl11_19",vj="_closeBtn_1cl11_25",bj="_body_1cl11_43",_j="_section_1cl11_59",wj="_sectionLabel_1cl11_65",xj="_chips_1cl11_73",Sj="_chip_1cl11_73",Cj="_active_1cl11_96",Oj="_footer_1cl11_102",Ej="_resetBtn_1cl11_112",Dj="_applyBtn_1cl11_129",et={panel:gj,header:mj,headerTitle:yj,closeBtn:vj,body:bj,section:_j,sectionLabel:wj,chips:xj,chip:Sj,active:Cj,footer:Oj,resetBtn:Ej,applyBtn:Dj},Ij=[{key:"board",label:"Board"},{key:"medium",label:"Medium"},{key:"gradeLevel",label:"Class"},{key:"subject",label:"Subject"}],Nj=new Set(["board","medium","gradeLevel","subject","topic"]),Tj=({local:e,toggle:t})=>{const r=Qh();return r.length?l.jsxs("div",{className:et.section,children:[l.jsx("div",{className:et.sectionLabel,children:"Primary Category"}),l.jsx("div",{className:et.chips,children:r.map(n=>l.jsx("button",{type:"button",className:[et.chip,(e.primaryCategory??[]).includes(n)?et.active:""].join(" "),onClick:()=>t("primaryCategory",n),children:n},n))})]}):null},jj=({isOpen:e,filters:t,onApply:r,onClose:n})=>{var g,_;const s=ue(h=>h.editorConfig),i=ue(h=>h.searchFormConfig),{organisationFramework:o}=Ph((g=s==null?void 0:s.context)==null?void 0:g.framework,(_=s==null?void 0:s.context)==null?void 0:_.targetFWIds),[a,c]=p.useState(t),d=i!=null&&i.length?i.filter(h=>Nj.has(h.code)).map(h=>({key:h.code,label:h.label||h.code})):Ij;p.useEffect(()=>{c(t)},[t]);const u=(h,y)=>{c(v=>{const b=v[h]??[],x=b.includes(y)?b.filter(w=>w!==y):[...b,y];return{...v,[h]:x}})},f=(o==null?void 0:o.categories)??[],m=h=>{var y;return((y=f.find(v=>v.code===h))==null?void 0:y.terms)??[]};return e?l.jsxs("div",{className:et.panel,role:"dialog","aria-label":"Filter library","aria-modal":"true",children:[l.jsxs("div",{className:et.header,children:[l.jsx("span",{className:et.headerTitle,children:"Filters"}),l.jsx("button",{type:"button",className:et.closeBtn,onClick:n,"aria-label":"Close filters",children:l.jsx(on,{size:16})})]}),l.jsxs("div",{className:et.body,children:[d.map(({key:h,label:y})=>{const v=m(h);return v.length?l.jsxs("div",{className:et.section,children:[l.jsx("div",{className:et.sectionLabel,children:y}),l.jsx("div",{className:et.chips,children:v.slice(0,20).map(b=>l.jsx("button",{type:"button",className:[et.chip,(a[h]??[]).includes(b.name)?et.active:""].join(" "),onClick:()=>u(h,b.name),children:b.name},b.identifier))})]},h):null}),l.jsx(Tj,{local:a,toggle:u})]}),l.jsxs("div",{className:et.footer,children:[l.jsx("button",{type:"button",className:et.resetBtn,onClick:()=>c({}),children:"Reset"}),l.jsx("button",{type:"button",className:et.applyBtn,onClick:()=>{r(a),n()},children:"Apply"})]})]}):null},Rj="_header_6qdpu_10",kj="_title_6qdpu_20",Aj="_headerActions_6qdpu_31",Pj="_iconBtn_6qdpu_38",Mj="_playerArea_6qdpu_56",Lj="_footer_6qdpu_64",Fj="_addBtn_6qdpu_73",$j="_modalOverlay_6qdpu_92",Bj="_modalPanel_6qdpu_103",ur={header:Rj,title:kj,headerActions:Aj,iconBtn:Pj,playerArea:Mj,footer:Lj,addBtn:Fj,modalOverlay:$j,modalPanel:Bj},Uj=({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 Rr.createPortal(l.jsx("div",{className:ur.modalOverlay,role:"dialog","aria-modal":"true","aria-label":"Content preview",onClick:r,children:l.jsxs("div",{className:ur.modalPanel,onClick:s=>s.stopPropagation(),children:[l.jsxs("div",{className:ur.header,children:[l.jsx("span",{className:ur.title,title:e.name,children:e.name}),l.jsx("div",{className:ur.headerActions,children:l.jsx("button",{type:"button",className:ur.iconBtn,onClick:r,"aria-label":"Close preview",children:l.jsx(on,{size:16})})})]}),l.jsx("div",{className:ur.playerArea,children:l.jsx(ja,{node:n,editorMode:"read",type:"content"})}),l.jsx("div",{className:ur.footer,children:l.jsx("button",{type:"button",className:ur.addBtn,onClick:()=>t(e),children:"+ Add to Unit"})})]})}),document.body)},Vj="_dock_1lpg0_1",zj="_header_1lpg0_8",qj="_headerLeft_1lpg0_17",Hj="_headerTitle_1lpg0_24",Wj="_count_1lpg0_30",Kj="_searchRow_1lpg0_39",Qj="_searchWrap_1lpg0_47",Gj="_searchIcon_1lpg0_53",Yj="_searchInput_1lpg0_62",Xj="_filterToggleBtn_1lpg0_80",Zj="_filterToggleBtnActive_1lpg0_99",Jj="_filterBadge_1lpg0_105",eR="_filters_1lpg0_124",tR="_mainArea_1lpg0_134",rR="_sidePanelOverlay_1lpg0_143",nR="_cardList_1lpg0_152",sR="_skeleton_1lpg0_168",iR="_skeletonIcon_1lpg0_178",oR="_skeletonText_1lpg0_186",aR="_skeletonLine_1lpg0_193",lR="_skeletonLineSm_1lpg0_200",cR="_loadMoreBtn_1lpg0_215",uR="_emptyState_1lpg0_240",dR="_collapseBtn_1lpg0_260",ke={dock:Vj,header:zj,headerLeft:qj,headerTitle:Hj,count:Wj,searchRow:Kj,searchWrap:Qj,searchIcon:Gj,searchInput:Yj,filterToggleBtn:Xj,filterToggleBtnActive:Zj,filterBadge:Jj,filters:eR,mainArea:tR,sidePanelOverlay:rR,cardList:nR,skeleton:sR,skeletonIcon:iR,skeletonText:oR,skeletonLine:aR,skeletonLineSm:lR,loadMoreBtn:cR,emptyState:uR,collapseBtn:dR};function fR(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 hR=({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:m,toggleSort:g,loadMore:_}=JT(),{addResource:h,selectedNodeId:y,treeData:v}=Re(),b=e==="edit",[x,w]=p.useState(!1),[C,D]=p.useState({}),[j,k]=p.useState(null),$=p.useMemo(()=>fR(v),[v]),N=p.useCallback(F=>{var me;if(!y){Se.error("Select a unit first");return}const J=(me=v[0])==null?void 0:me.id;if(y===J){Se("Select a unit from the outline to add content — resources cannot be added directly to the course.",{icon:"ℹ️",duration:4e3});return}if(h(F,y)===!1){Se.error(`"${F.name}" is already in this collection`);return}Se.success(`Added "${F.name}"`)},[y,h,v]),A=p.useCallback(F=>{D(F),m(F)},[m]),U=p.useCallback(F=>{k(F)},[]),R=p.useCallback(F=>{N(F),k(null)},[N]),B=p.useMemo(()=>Object.values(C).reduce((F,J)=>F+((J==null?void 0:J.length)??0),0),[C]);return l.jsxs("div",{className:ke.dock,children:[l.jsx("div",{className:ke.header,children:l.jsxs("div",{className:ke.headerLeft,children:[l.jsx("button",{type:"button",className:ke.collapseBtn,onClick:r,"aria-label":"Collapse library panel",title:"Collapse library",children:l.jsx(py,{size:15})}),l.jsx(dy,{size:16}),l.jsx("span",{className:ke.headerTitle,children:"Library"}),i>0&&l.jsx("span",{className:ke.count,children:i})]})}),l.jsxs("div",{className:ke.searchRow,children:[l.jsxs("div",{className:ke.searchWrap,children:[l.jsx(la,{size:14,className:ke.searchIcon}),l.jsx("input",{type:"search",className:ke.searchInput,placeholder:"Search content…",value:a,onChange:F=>u(F.target.value),"aria-label":"Search library"})]}),l.jsx("button",{type:"button",className:[ke.filterToggleBtn,c?ke.filterToggleBtnActive:""].join(" "),onClick:g,"aria-label":c?"Sort: A–Z (click for Recent)":"Sort: Recent (click for A–Z)",title:c?"A–Z":"Recent",children:c?l.jsx(ny,{size:15}):l.jsx(oy,{size:15})}),l.jsxs("button",{type:"button",className:[ke.filterToggleBtn,x?ke.filterToggleBtnActive:""].join(" "),onClick:()=>w(F=>!F),"aria-label":"Toggle advanced filters","aria-pressed":x,title:"Advanced filters",children:[l.jsx(_y,{size:15}),B>0&&l.jsx("span",{className:ke.filterBadge,children:B})]})]}),l.jsx("div",{className:ke.filters,children:l.jsx(pj,{filters:N1,active:o,onChange:f})}),l.jsxs("div",{className:ke.mainArea,children:[l.jsx("div",{className:ke.cardList,role:"list","aria-label":"Library content",children:s&&n.length===0?Array.from({length:4}).map((F,J)=>l.jsxs("div",{className:ke.skeleton,"aria-hidden":"true",children:[l.jsx("div",{className:ke.skeletonIcon}),l.jsxs("div",{className:ke.skeletonText,children:[l.jsx("div",{className:ke.skeletonLine}),l.jsx("div",{className:ke.skeletonLineSm})]})]},J)):n.length>0?l.jsxs(l.Fragment,{children:[n.map(F=>l.jsx(dj,{item:F,onAdd:N,onPreview:U,isDraggable:b,isAdded:$.has(F.identifier)},F.identifier)),d&&l.jsx("button",{type:"button",className:ke.loadMoreBtn,onClick:_,disabled:s,"aria-label":"Load more content",children:s?"Loading…":"Load More"})]}):l.jsxs("div",{className:ke.emptyState,children:[l.jsx(la,{size:24}),l.jsx("p",{children:"No content found"}),l.jsx("span",{children:"Try a different search or filter"})]})}),x&&l.jsx("div",{className:ke.sidePanelOverlay,children:l.jsx(jj,{isOpen:x,filters:C,onApply:A,onClose:()=>w(!1)})}),j&&l.jsx(Uj,{content:j,onAdd:R,onClose:()=>k(null)})]})]})};function pR(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","targetBoardIds","targetMediumIds","targetGradeLevelIds","targetSubjectIds","medium","gradeLevel","subject","additionalCategories","keywords","language"]),c=new Set(["copyrightYear","compatibilityLevel","version"]);function d(m,g=!1){const _={};for(const[h,y]of Object.entries(m))if(!i.has(h)&&!(g&&o.has(h)))if(a.has(h))Array.isArray(y)?_[h]=y:y!=null&&y!==""?_[h]=[y]:_[h]=[];else if(c.has(h)){const v=Number(y);isNaN(v)||(_[h]=v)}else _[h]=y;return _}function u(m){var _;const g={};for(const h of m.children??[]){if(h.isFolder)continue;const y=t[h.identifier];if(!y)continue;const{isNew:v,...b}=y;if(Object.keys(b).length===0)continue;const x=((_=h.metadata)==null?void 0:_.relationalMetadata)??{};g[h.identifier]={name:h.name,...x,...b}}return g}function f(m,g){var x,w;const _=m.identifier,h=t[_],y=_.startsWith("temp-")||!!(h!=null&&h.isNew),v=!m.isFolder&&!g;if(g||y||h&&!v){let C;if(y)C={mimeType:"application/vnd.ekstep.content-collection",code:_,contentType:((x=m.metadata)==null?void 0:x.contentType)??"CourseUnit",primaryCategory:((w=m.metadata)==null?void 0:w.primaryCategory)??"Course Unit",name:m.name,visibility:"Parent",channel:r,...d(m.metadata??{})};else if(g){const{isNew:D,...j}=h??{};C={...d(m.metadata??{},!0),...d(j,!1),name:m.name}}else{const{isNew:D,...j}=h??{};C={name:m.name,visibility:"Parent",...d(j,!0)}}n[_]={metadata:C,objectType:m.objectType||(m.isFolder?"Collection":"Content"),root:g,isNew:y}}const b=m.isFolder?u(m):{};s[_]={name:m.name,children:(m.children??[]).map(C=>C.identifier),...Object.keys(b).length>0?{relationalMetadata:b}:{},root:g},(m.children??[]).forEach(C=>f(C,!1))}return e.forEach((m,g)=>f(m,g===0)),{nodesModified:n,hierarchy:s}}function gR(){const[e,t]=p.useState(!1),r=Re(u=>u.treeCache),n=Re(u=>u.treeData),s=ue(u=>u.isDirty),i=ue(u=>u.lastSaved),{setIsDirty:o,setLastSaved:a}=ue(),c=ue(u=>u.editorConfig);return{save:p.useCallback(async()=>{if(!c||e)return;const u=c.context.contentId??c.context.identifier??"";if(!u)return;const f=c.context.channel??"",m=c.context.userId??c.context.uid??"";t(!0);try{const{nodesModified:g,hierarchy:_}=pR(n,r,f),{identifiers:h}=await n_(u,g,_,m);h&&Object.keys(h).length>0&&Re.getState().replaceNodeIds(h);const y=new Date().toISOString();a(y),o(!1)}catch(g){console.error("[useSaveHierarchy] save failed:",g),Se.error("Failed to save. Please try again.")}finally{t(!1)}},[c,e,n,r,o,a]),isSaving:e,isDirty:s,lastSaved:i}}function mR(e){const t=ue(o=>o.editorConfig),r=ue(o=>o.setButtonLoader),n=ue(o=>o.validateAllForms),s=Re(o=>o.treeData);return{runAction:p.useCallback(async(o,a)=>{var u,f,m,g;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 Se.error("No content identifier found."),!1;const d=((m=t==null?void 0:t.context)==null?void 0:m.userId)??((g=t==null?void 0:t.context)==null?void 0:g.uid)??"";try{switch(o){case"sendForReview":return n(s)?(r("saveCollection",!0),await e(),await o_(c),Se.success("Content sent for review"),!0):(Se.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 a_(c,_),Se.success("Content rejected and sent back to the author"),!0}case"publish":return n(s)?(r("publishCollection",!0),await e(),await s_(c,d),Se.success("Content published successfully"),!0):(Se.error("Some units have missing required fields. Please fill them before publishing."),!1);default:return!1}}catch(_){console.error(`[useToolbarActions] ${o} failed`,_);const h=o==="sendForReview"?"send for review":o==="reject"?"reject":"publish";return Se.error(`Failed to ${h}. Please try again.`),!1}finally{r("saveCollection",!1),r("rejectCollection",!1),r("publishCollection",!1)}},[t,e,r])}}const yR="_shell_90fon_1",vR="_workspace_90fon_8",bR="_sidebarCollapsed_90fon_16",_R="_dockCollapsed_90fon_19",wR="_dock_90fon_19",xR="_outline_90fon_40",SR="_reopenTab_90fon_45",CR="_outlineHidden_90fon_79",OR="_editor_90fon_86",ER="_dockHidden_90fon_101",DR="_dockReopenTab_90fon_108",IR="_dragChip_90fon_133",NR="_dragChipLabel_90fon_148",Tt={shell:yR,workspace:vR,sidebarCollapsed:bR,dockCollapsed:_R,dock:wR,outline:xR,reopenTab:SR,outlineHidden:CR,editor:OR,dockHidden:ER,dockReopenTab:DR,dragChip:IR,dragChipLabel:NR},TR=({editorMode:e,onToolbarEvent:t,onContentAdded:r,onHierarchySaved:n})=>{const[s,i]=p.useState(null),[o,a]=p.useState(!1),[c,d]=p.useState(!1),[u,f]=p.useState(!1),{addResource:m,treeData:g}=Re(),_=ue(R=>R.setFormStatus),[h,y]=p.useState(!0),v=Re(R=>R.selectedNodeId),{save:b,isSaving:x,isDirty:w,lastSaved:C}=gR(),{runAction:D}=mR(b);p.useEffect(()=>{if(!w)return;const R=B=>{B.preventDefault(),B.returnValue=""};return window.addEventListener("beforeunload",R),()=>window.removeEventListener("beforeunload",R)},[w]);const j=vd(na(Vi,{activationConstraint:{distance:8}})),k=p.useCallback(R=>{var F;const B=(F=R.active.data.current)==null?void 0:F.item;B&&i(B)},[]),$=p.useCallback(R=>{var ve,be;i(null);const B=(ve=R.active.data.current)==null?void 0:ve.item;if(!B)return;const F=R.over,J=(F==null?void 0:F.id)??v??void 0;if(!J){Se.error("Drop onto a unit to add content");return}const ie=(be=g[0])==null?void 0:be.id;if(J===ie){Se.error("Drop content onto a unit, not directly on the course.");return}if(!m(B,J)){Se.error(`"${B.name}" is already in this collection`);return}r==null||r(B,J),Se.success(`Added "${B.name}" to unit`)},[v,m,r]),N=p.useCallback(async R=>{if(R.action==="onFormStatusChange"){const{isValid:B,nodeId:F}=R.data??{},J=B!==!1;y(J),F&&_(F,J);return}if(R.action==="back"&&w){f(!0);return}if(R.action==="saveCollection"){if(!h){Se.error("Please fill the required metadata");return}await b(),n==null||n(g),t==null||t(R);return}if(R.action==="sendForReview"||R.action==="reject"||R.action==="publish"){await D(R.action,R.data)&&(t==null||t(R));return}t==null||t(R)},[b,D,t,n,g,w,h]),A=p.useCallback(async()=>{await b(),f(!1),n==null||n(g),t==null||t({action:"back"})},[b,n,t,g]),U=p.useCallback(()=>{f(!1),t==null||t({action:"back"})},[t]);return l.jsxs(Ld,{sensors:j,onDragStart:k,onDragEnd:$,children:[l.jsxs("div",{className:Tt.shell,children:[l.jsx(gw,{editorMode:e,isSaving:x,isDirty:w,lastSaved:C,isFormValid:h,onToolbarEvent:N}),l.jsxs("div",{className:[Tt.workspace,o?Tt.sidebarCollapsed:"",c?Tt.dockCollapsed:""].filter(Boolean).join(" "),children:[l.jsx("aside",{className:[Tt.outline,o?Tt.outlineHidden:""].join(" "),"aria-label":"Course outline","aria-hidden":o,children:l.jsx(UO,{editorMode:e,collapsed:o,onToggleCollapse:()=>a(R=>!R)})}),o&&l.jsx("button",{className:Tt.reopenTab,onClick:()=>a(!1),title:"Show outline",type:"button",children:"›"}),l.jsx("main",{className:Tt.editor,role:"main","aria-label":"Content editor",children:l.jsx(XT,{editorMode:e,onToolbarEvent:N})}),l.jsx("aside",{className:[Tt.dock,c?Tt.dockHidden:""].filter(Boolean).join(" "),"aria-label":"Content library","aria-hidden":c,children:l.jsx(hR,{editorMode:e,collapsed:c,onToggleCollapse:()=>d(R=>!R)})}),c&&l.jsx("button",{className:Tt.dockReopenTab,onClick:()=>d(!1),title:"Show library",type:"button",children:"‹"})]})]}),l.jsx(Zm,{dropAnimation:null,children:s?l.jsx("div",{className:Tt.dragChip,children:l.jsx("span",{className:Tt.dragChipLabel,children:s.name})}):null}),u&&l.jsx(mw,{onSave:A,onDiscard:U,onCancel:()=>f(!1),isSaving:x})]})},jR="v1";function RR(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 Fu(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:RR(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 br(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(Fu(o,s))}else n.code&&r.push(Fu(n));return r}function kR(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 AR(e,t,r="Collection",n=jR){var d,u;const i=(u=(d=(await Me.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:br(o.create),unitForm:br(o.unitMetadata),childForm:br(o.childMetadata),searchForm:br(o.search??o.searchConfig),relationalForm:br(o.relationalMetadata),publishChecklist:br(o.publishchecklist),reviewChecklist:br(o.review),rfcChecklist:br(o.requestforchangeschecklist),schemaDefaults:kR(a.schema),frameworkMetadata:c.frameworkMetadata??{},sourcingSettings:c.sourcingSettings??{}}}function PR({config:e,onError:t}){const[r,n]=p.useState(!0),[s,i]=p.useState(null),[o,a]=p.useState(!1),{setEditorConfig:c,setEditorMode:d,setCategoryDefinition:u}=ue(),{setTreeData:f,selectNode:m}=Re();return p.useEffect(()=>{let g=!1;async function _(){var h,y;try{n(!0),i(null),e.apiBaseUrl&&Of(e.apiBaseUrl),c(e),d(e.config.mode);const v=e.context.contentId??e.context.identifier??"";if(v){const{rootNode:b}=await If(v);g||(f(b?[b]:[]),b&&m(b.id));const x=e.config.primaryCategory??"Course",w=e.context.channel??"",C=e.config.categoryDefinitionApiVersion??"v1";try{const D=await AR(x,w,e.config.objectType??"Collection",C);if(!g){u(D);const j=((h=D.sourcingSettings)==null?void 0:h.collection)??{},k={};j.maxDepth&&!e.config.maxDepth&&(k.maxDepth=j.maxDepth),j.children&&!e.config.children&&(k.children=j.children),j.hierarchy&&!((y=e.config.hierarchy)!=null&&y.level1)&&(k.hierarchy={...e.config.hierarchy??{},...j.hierarchy}),Object.keys(k).length>0&&c({...e,config:{...e.config,...k}})}}catch{}}g||a(!0)}catch(v){if(!g){const b=v instanceof Error?v:new Error(String(v));i(b),t==null||t(b)}}finally{g||n(!1)}}return _(),()=>{g=!0}},[e.context.contentId,e.context.identifier]),{isLoading:r,error:s,isReady:o}}const MR="_root_qcpw6_1",LR="_loadingState_qcpw6_10",FR="_loadingSpinner_qcpw6_20",$R="_errorState_qcpw6_34",os={root:MR,loadingState:LR,loadingSpinner:FR,errorState:$R},BR=new xp({defaultOptions:{queries:{retry:1,refetchOnWindowFocus:!1}}});class UR extends p.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:os.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 VR(e){const{isLoading:t,error:r}=PR({config:e,onError:e.onError}),n=ue(s=>s.editorMode);return t?l.jsxs("div",{className:os.loadingState,children:[l.jsx("div",{className:os.loadingSpinner}),l.jsx("p",{children:"Loading editor..."})]}):r?l.jsxs("div",{className:os.errorState,children:[l.jsx("h3",{children:"Failed to load editor"}),l.jsx("p",{children:r.message})]}):l.jsx("div",{className:`sb-split-builder ${os.root}`,children:l.jsx(TR,{editorMode:n,onToolbarEvent:e.onToolbarEvent,onContentAdded:e.onContentAdded,onHierarchySaved:e.onHierarchySaved})})}const Gh=e=>l.jsx(UR,{onError:e.onError,children:l.jsxs(Cp,{client:BR,children:[l.jsx(VR,{...e}),l.jsx(Sg,{position:"top-right",toastOptions:{duration:3e3}})]})}),Pi=Symbol.for("r2wc.reactRender"),$u=Symbol.for("r2wc.shouldRender"),ti=Symbol.for("r2wc.root");function zR(e=""){return e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}function qR(e=""){return e.replace(/-([a-z0-9])/g,function(t){return t[1].toUpperCase()})}var Bu={expando:function(e,t,r){Object.defineProperty(e,t,{enumerable:!0,get:function(){return r},set:function(n){r=n,this[Pi]()}}),e[Pi]()}};function HR(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,m){return i&&(s[u]=!0),typeof u=="symbol"||s[u]||u in d?(e.propTypes&&u in e.propTypes&&Bu.expando(m,u,f),Reflect.set(d,u,f,m)):(Bu.expando(m,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[$u]=!0,this[Pi]()},a.disconnectedCallback=function(){typeof r.createRoot=="function"?this[ti].unmount():r.unmountComponentAtNode(this)},a[Pi]=function(){if(this[$u]===!0){var d={};Object.keys(this).forEach(function(m){s[m]!==!1&&(d[m]=this[m])},this),i=!0;const u=n.shadow?this.shadowRoot:this,f=t.createElement(e,d);typeof r.createRoot=="function"?(this[ti]||(this[ti]=r.createRoot(u)),this[ti].render(f)):r.render(f,u),i=!1}},e.propTypes&&(o.observedAttributes=n.dashStyleAttributes?Object.keys(e.propTypes).map(function(d){return zR(d)}):Object.keys(e.propTypes),a.attributeChangedCallback=function(d,u,f){var m=n.dashStyleAttributes?qR(d):d;this[m]=f}),o}var as={},ns=Rr;if(process.env.NODE_ENV==="production")as.createRoot=ns.createRoot,as.hydrateRoot=ns.hydrateRoot;else{var ri=ns.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;as.createRoot=function(e,t){ri.usingClientEntryPoint=!0;try{return ns.createRoot(e,t)}finally{ri.usingClientEntryPoint=!1}},as.hydrateRoot=function(e,t,r){ri.usingClientEntryPoint=!0;try{return ns.hydrateRoot(e,t,r)}finally{ri.usingClientEntryPoint=!1}}}function WR(){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 KR(e="sb-collection-editor"){if(WR(),typeof customElements>"u"||customElements.get(e))return;const t=HR(Gh,p,as,{});customElements.define(e,t)}exports.CollectionEditor=Gh;exports.registerCollectionEditor=KR;exports.setApiBaseUrl=Of;exports.useEditorStore=ue;exports.useLibraryStore=Kh;exports.useTreeStore=Re;