@ws-ui/roles-editor 1.14.4 → 1.14.5

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.
@@ -1,7 +1,7 @@
1
1
  import { FC } from 'react';
2
2
  import { IContainerProps } from '../Container';
3
3
  import { TabType } from '../types';
4
- import { THistoryControls } from '../adapter';
4
+ import { THistoryControls, TEditorHost } from '../adapter';
5
5
  interface IStandaloneProps extends IContainerProps {
6
6
  initialValue?: string;
7
7
  catalog?: datasources.ICatalog;
@@ -13,6 +13,7 @@ interface IStandaloneProps extends IContainerProps {
13
13
  onSelectRole?: (role: string | null) => void;
14
14
  selectedPrivilege?: string | null;
15
15
  onSelectPrivilege?: (id: string | null) => void;
16
+ host?: TEditorHost;
16
17
  }
17
18
  declare const StandaloneWithReducerAdapter: FC<IStandaloneProps>;
18
19
  export { StandaloneWithReducerAdapter as Standalone };
package/dist/index.cjs.js CHANGED
@@ -91,7 +91,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
91
91
  */var lM;function Gae(){return lM||(lM=1,(function(e){(function(){var t={}.hasOwnProperty;function r(){for(var o="",a=0;a<arguments.length;a++){var s=arguments[a];s&&(o=i(o,n(s)))}return o}function n(o){if(typeof o=="string"||typeof o=="number")return o;if(typeof o!="object")return"";if(Array.isArray(o))return r.apply(null,o);if(o.toString!==Object.prototype.toString&&!o.toString.toString().includes("[native code]"))return o.toString();var a="";for(var s in o)t.call(o,s)&&o[s]&&(a=i(a,s));return a}function i(o,a){return a?o?o+" "+a:o+a:o}e.exports?(r.default=r,e.exports=r):window.classNames=r})()})(j0)),j0.exports}var Kae=Gae();const an=Qi(Kae),q0=({child:e,parent:t,status:r})=>{const n=yr(),i=n.getPrivileges();function o(){const s=pe.addPrivilegeIn(t.id,e.id,i);n.actions.updatePrivileges(s)}function a(){const s=pe.removePrivilegeFrom(t.id,e.id,i);n.actions.updatePrivileges(s)}return C.jsxs(vu,{color:r==="included"?"primary":"dark",onClick:r==="included"?a:o,disabled:r==="disabled",children:[e.privilege,C.jsx(ja,{className:an("transform transition-transform",{"rotate-45":r==="included"})})]})},Yae=({selectedPrivilege:e,privileges:t,onSelect:r,setShowIncluded:n,showIncluded:i})=>{const o=Object.values(t),a=pe.getPrivilegeById(e.id,t);let s=a?pe.populateShallow(a.includes,t):[],c=a?pe.populateShallow(pe.parents(a.id,t),t):[],d=a?pe.populateShallow(pe.allowed(a.id,t),t):[];return[s,c,d]=[s,c,d].map(u=>u.filter(h=>(h==null?void 0:h.privilege)!=="guest")),o.length<2&&s.length+c.length+d.length===0?null:C.jsxs(br,{depth:1,className:"w-full border-b p-4",children:[C.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[" ",o.length>2?C.jsx("h4",{className:"text-[13px] font-semibold",children:"Include a privilege"}):C.jsx("div",{}),C.jsxs("div",{className:"flex items-center gap-2",children:[C.jsx(Fu,{onChange:()=>n(!i),checked:i}),C.jsx("label",{className:"text-xs",children:" Show inherited permissions"})]})]}),C.jsxs("div",{className:"flex flex-wrap items-start justify-start gap-1",children:[s.map(u=>C.jsx(q0,{child:u,parent:e,status:"included",onSelect:r,currentPrivilegeId:u.id},u.id)),d.map(u=>C.jsx(q0,{child:u,parent:e,status:"available",onSelect:r,currentPrivilegeId:u.id},u.id)),c.map(u=>C.jsx(q0,{child:u,parent:e,status:"disabled",onSelect:r,currentPrivilegeId:u.id},u.id))]})]})};function da(e,t,r){let n=r.initialDeps??[],i,o=!0;function a(){var s,c,d;let u;r.key&&((s=r.debug)!=null&&s.call(r))&&(u=Date.now());const h=e();if(!(h.length!==n.length||h.some((x,g)=>n[g]!==x)))return i;n=h;let v;if(r.key&&((c=r.debug)!=null&&c.call(r))&&(v=Date.now()),i=t(...h),r.key&&((d=r.debug)!=null&&d.call(r))){const x=Math.round((Date.now()-u)*100)/100,g=Math.round((Date.now()-v)*100)/100,m=g/16,w=(y,_)=>{for(y=String(y);y.length<_;)y=" "+y;return y};console.info(`%c⏱ ${w(g,5)} /${w(x,5)} ms`,`
92
92
  font-size: .6rem;
93
93
  font-weight: bold;
94
- color: hsl(${Math.max(0,Math.min(120-120*m,120))}deg 100% 31%);`,r==null?void 0:r.key)}return r!=null&&r.onChange&&!(o&&r.skipInitialOnChange)&&r.onChange(i),o=!1,i}return a.updateDeps=s=>{n=s},a}function cM(e,t){if(e===void 0)throw new Error("Unexpected undefined");return e}const Xae=(e,t)=>Math.abs(e-t)<1.01,Zae=(e,t,r)=>{let n;return function(...i){e.clearTimeout(n),n=e.setTimeout(()=>t.apply(this,i),r)}},uM=e=>{const{offsetWidth:t,offsetHeight:r}=e;return{width:t,height:r}},Jae=e=>e,Qae=e=>{const t=Math.max(e.startIndex-e.overscan,0),r=Math.min(e.endIndex+e.overscan,e.count-1),n=[];for(let i=t;i<=r;i++)n.push(i);return n},ese=(e,t)=>{const r=e.scrollElement;if(!r)return;const n=e.targetWindow;if(!n)return;const i=a=>{const{width:s,height:c}=a;t({width:Math.round(s),height:Math.round(c)})};if(i(uM(r)),!n.ResizeObserver)return()=>{};const o=new n.ResizeObserver(a=>{const s=()=>{const c=a[0];if(c!=null&&c.borderBoxSize){const d=c.borderBoxSize[0];if(d){i({width:d.inlineSize,height:d.blockSize});return}}i(uM(r))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(s):s()});return o.observe(r,{box:"border-box"}),()=>{o.unobserve(r)}},dM={passive:!0},fM=typeof window>"u"?!0:"onscrollend"in window,tse=(e,t)=>{const r=e.scrollElement;if(!r)return;const n=e.targetWindow;if(!n)return;let i=0;const o=e.options.useScrollendEvent&&fM?()=>{}:Zae(n,()=>{t(i,!1)},e.options.isScrollingResetDelay),a=u=>()=>{const{horizontal:h,isRtl:p}=e.options;i=h?r.scrollLeft*(p&&-1||1):r.scrollTop,o(),t(i,u)},s=a(!0),c=a(!1);r.addEventListener("scroll",s,dM);const d=e.options.useScrollendEvent&&fM;return d&&r.addEventListener("scrollend",c,dM),()=>{r.removeEventListener("scroll",s),d&&r.removeEventListener("scrollend",c)}},rse=(e,t,r)=>{if(t!=null&&t.borderBoxSize){const n=t.borderBoxSize[0];if(n)return Math.round(n[r.options.horizontal?"inlineSize":"blockSize"])}return e[r.options.horizontal?"offsetWidth":"offsetHeight"]},nse=(e,{adjustments:t=0,behavior:r},n)=>{var i,o;const a=e+t;(o=(i=n.scrollElement)==null?void 0:i.scrollTo)==null||o.call(i,{[n.options.horizontal?"left":"top"]:a,behavior:r})};class ise{constructor(t){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this.itemSizeCache=new Map,this.laneAssignments=new Map,this.pendingMeasuredCacheIndexes=[],this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this.elementsCache=new Map,this.now=()=>{var r,n,i;return((i=(n=(r=this.targetWindow)==null?void 0:r.performance)==null?void 0:n.now)==null?void 0:i.call(n))??Date.now()},this.observer=(()=>{let r=null;const n=()=>r||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:r=new this.targetWindow.ResizeObserver(i=>{i.forEach(o=>{const a=()=>{const s=o.target,c=this.indexFromElement(s);if(!s.isConnected){this.observer.unobserve(s);return}this.shouldMeasureDuringScroll(c)&&this.resizeItem(c,this.options.measureElement(s,o,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(a):a()})}));return{disconnect:()=>{var i;(i=n())==null||i.disconnect(),r=null},observe:i=>{var o;return(o=n())==null?void 0:o.observe(i,{box:"border-box"})},unobserve:i=>{var o;return(o=n())==null?void 0:o.unobserve(i)}}})(),this.range=null,this.setOptions=r=>{Object.entries(r).forEach(([n,i])=>{typeof i>"u"&&delete r[n]}),this.options={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:Jae,rangeExtractor:Qae,onChange:()=>{},measureElement:rse,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,...r}},this.notify=r=>{var n,i;(i=(n=this.options).onChange)==null||i.call(n,this,r)},this.maybeNotify=da(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),r=>{this.notify(r)},{key:process.env.NODE_ENV!=="production"&&"maybeNotify",debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(r=>r()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var r;const n=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==n){if(this.cleanup(),!n){this.maybeNotify();return}this.scrollElement=n,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((r=this.scrollElement)==null?void 0:r.window)??null,this.elementsCache.forEach(i=>{this.observer.observe(i)}),this.unsubs.push(this.options.observeElementRect(this,i=>{this.scrollRect=i,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(i,o)=>{this.scrollAdjustments=0,this.scrollDirection=o?this.getScrollOffset()<i?"forward":"backward":null,this.scrollOffset=i,this.isScrolling=o,this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset=="function"?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getFurthestMeasurement=(r,n)=>{const i=new Map,o=new Map;for(let a=n-1;a>=0;a--){const s=r[a];if(i.has(s.lane))continue;const c=o.get(s.lane);if(c==null||s.end>c.end?o.set(s.lane,s):s.end<c.end&&i.set(s.lane,!0),i.size===this.options.lanes)break}return o.size===this.options.lanes?Array.from(o.values()).sort((a,s)=>a.end===s.end?a.index-s.index:a.end-s.end)[0]:void 0},this.getMeasurementOptions=da(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes],(r,n,i,o,a,s)=>(this.prevLanes!==void 0&&this.prevLanes!==s&&(this.lanesChangedFlag=!0),this.prevLanes=s,this.pendingMeasuredCacheIndexes=[],{count:r,paddingStart:n,scrollMargin:i,getItemKey:o,enabled:a,lanes:s}),{key:!1}),this.getMeasurements=da(()=>[this.getMeasurementOptions(),this.itemSizeCache],({count:r,paddingStart:n,scrollMargin:i,getItemKey:o,enabled:a,lanes:s},c)=>{if(!a)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>r)for(const p of this.laneAssignments.keys())p>=r&&this.laneAssignments.delete(p);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMeasuredCacheIndexes=[]),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(p=>{this.itemSizeCache.set(p.key,p.size)}));const d=this.lanesSettling?0:this.pendingMeasuredCacheIndexes.length>0?Math.min(...this.pendingMeasuredCacheIndexes):0;this.pendingMeasuredCacheIndexes=[],this.lanesSettling&&this.measurementsCache.length===r&&(this.lanesSettling=!1);const u=this.measurementsCache.slice(0,d),h=new Array(s).fill(void 0);for(let p=0;p<d;p++){const v=u[p];v&&(h[v.lane]=p)}for(let p=d;p<r;p++){const v=o(p),x=this.laneAssignments.get(p);let g,m;if(x!==void 0&&this.options.lanes>1){g=x;const S=h[g],E=S!==void 0?u[S]:void 0;m=E?E.end+this.options.gap:n+i}else{const S=this.options.lanes===1?u[p-1]:this.getFurthestMeasurement(u,p);m=S?S.end+this.options.gap:n+i,g=S?S.lane:p%this.options.lanes,this.options.lanes>1&&this.laneAssignments.set(p,g)}const w=c.get(v),y=typeof w=="number"?w:this.options.estimateSize(p),_=m+y;u[p]={index:p,start:m,size:y,end:_,key:v,lane:g},h[g]=p}return this.measurementsCache=u,u},{key:process.env.NODE_ENV!=="production"&&"getMeasurements",debug:()=>this.options.debug}),this.calculateRange=da(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(r,n,i,o)=>this.range=r.length>0&&n>0?ose({measurements:r,outerSize:n,scrollOffset:i,lanes:o}):null,{key:process.env.NODE_ENV!=="production"&&"calculateRange",debug:()=>this.options.debug}),this.getVirtualIndexes=da(()=>{let r=null,n=null;const i=this.calculateRange();return i&&(r=i.startIndex,n=i.endIndex),this.maybeNotify.updateDeps([this.isScrolling,r,n]),[this.options.rangeExtractor,this.options.overscan,this.options.count,r,n]},(r,n,i,o,a)=>o===null||a===null?[]:r({startIndex:o,endIndex:a,overscan:n,count:i}),{key:process.env.NODE_ENV!=="production"&&"getVirtualIndexes",debug:()=>this.options.debug}),this.indexFromElement=r=>{const n=this.options.indexAttribute,i=r.getAttribute(n);return i?parseInt(i,10):(console.warn(`Missing attribute name '${n}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=r=>{var n;if(!this.scrollState||this.scrollState.behavior!=="smooth")return!0;const i=this.scrollState.index??((n=this.getVirtualItemForOffset(this.scrollState.lastTargetOffset))==null?void 0:n.index);if(i!==void 0&&this.range){const o=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),a=Math.max(0,i-o),s=Math.min(this.options.count-1,i+o);return r>=a&&r<=s}return!0},this.measureElement=r=>{if(!r){this.elementsCache.forEach((a,s)=>{a.isConnected||(this.observer.unobserve(a),this.elementsCache.delete(s))});return}const n=this.indexFromElement(r),i=this.options.getItemKey(n),o=this.elementsCache.get(i);o!==r&&(o&&this.observer.unobserve(o),this.observer.observe(r),this.elementsCache.set(i,r)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(n)&&this.resizeItem(n,this.options.measureElement(r,void 0,this))},this.resizeItem=(r,n)=>{var i;const o=this.measurementsCache[r];if(!o)return;const a=this.itemSizeCache.get(o.key)??o.size,s=n-a;s!==0&&(((i=this.scrollState)==null?void 0:i.behavior)!=="smooth"&&(this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(o,s,this):o.start<this.getScrollOffset()+this.scrollAdjustments)&&(process.env.NODE_ENV!=="production"&&this.options.debug&&console.info("correction",s),this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=s,behavior:void 0})),this.pendingMeasuredCacheIndexes.push(o.index),this.itemSizeCache=new Map(this.itemSizeCache.set(o.key,n)),this.notify(!1))},this.getVirtualItems=da(()=>[this.getVirtualIndexes(),this.getMeasurements()],(r,n)=>{const i=[];for(let o=0,a=r.length;o<a;o++){const s=r[o],c=n[s];i.push(c)}return i},{key:process.env.NODE_ENV!=="production"&&"getVirtualItems",debug:()=>this.options.debug}),this.getVirtualItemForOffset=r=>{const n=this.getMeasurements();if(n.length!==0)return cM(n[wz(0,n.length-1,i=>cM(n[i]).start,r)])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if("scrollHeight"in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{const r=this.scrollElement.document.documentElement;return this.options.horizontal?r.scrollWidth-this.scrollElement.innerWidth:r.scrollHeight-this.scrollElement.innerHeight}},this.getOffsetForAlignment=(r,n,i=0)=>{if(!this.scrollElement)return 0;const o=this.getSize(),a=this.getScrollOffset();n==="auto"&&(n=r>=a+o?"end":"start"),n==="center"?r+=(i-o)/2:n==="end"&&(r-=o);const s=this.getMaxScrollOffset();return Math.max(Math.min(s,r),0)},this.getOffsetForIndex=(r,n="auto")=>{r=Math.max(0,Math.min(r,this.options.count-1));const i=this.getSize(),o=this.getScrollOffset(),a=this.measurementsCache[r];if(!a)return;if(n==="auto")if(a.end>=o+i-this.options.scrollPaddingEnd)n="end";else if(a.start<=o+this.options.scrollPaddingStart)n="start";else return[o,n];if(n==="end"&&r===this.options.count-1)return[this.getMaxScrollOffset(),n];const s=n==="end"?a.end+this.options.scrollPaddingEnd:a.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(s,n,a.size),n]},this.scrollToOffset=(r,{align:n="start",behavior:i="auto"}={})=>{const o=this.getOffsetForAlignment(r,n),a=this.now();this.scrollState={index:null,align:n,behavior:i,startedAt:a,lastTargetOffset:o,stableFrames:0},this._scrollToOffset(o,{adjustments:void 0,behavior:i}),this.scheduleScrollReconcile()},this.scrollToIndex=(r,{align:n="auto",behavior:i="auto"}={})=>{r=Math.max(0,Math.min(r,this.options.count-1));const o=this.getOffsetForIndex(r,n);if(!o)return;const[a,s]=o,c=this.now();this.scrollState={index:r,align:s,behavior:i,startedAt:c,lastTargetOffset:a,stableFrames:0},this._scrollToOffset(a,{adjustments:void 0,behavior:i}),this.scheduleScrollReconcile()},this.scrollBy=(r,{behavior:n="auto"}={})=>{const i=this.getScrollOffset()+r,o=this.now();this.scrollState={index:null,align:"start",behavior:n,startedAt:o,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:n}),this.scheduleScrollReconcile()},this.getTotalSize=()=>{var r;const n=this.getMeasurements();let i;if(n.length===0)i=this.options.paddingStart;else if(this.options.lanes===1)i=((r=n[n.length-1])==null?void 0:r.end)??0;else{const o=Array(this.options.lanes).fill(null);let a=n.length-1;for(;a>=0&&o.some(s=>s===null);){const s=n[a];o[s.lane]===null&&(o[s.lane]=s.end),a--}i=Math.max(...o.filter(s=>s!==null))}return Math.max(i-this.options.scrollMargin+this.options.paddingEnd,0)},this._scrollToOffset=(r,{adjustments:n,behavior:i})=>{this.options.scrollToFn(r,{behavior:i,adjustments:n},this)},this.measure=()=>{this.itemSizeCache=new Map,this.laneAssignments=new Map,this.notify(!1)},this.setOptions(t)}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId==null&&(this.rafId=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}))}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}const n=this.scrollState.index!=null?this.getOffsetForIndex(this.scrollState.index,this.scrollState.align):void 0,i=n?n[0]:this.scrollState.lastTargetOffset,o=1,a=i!==this.scrollState.lastTargetOffset;if(!a&&Xae(i,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=o){this.scrollState=null;return}}else this.scrollState.stableFrames=0,a&&(this.scrollState.lastTargetOffset=i,this.scrollState.behavior="auto",this._scrollToOffset(i,{adjustments:void 0,behavior:"auto"}));this.scheduleScrollReconcile()}}const wz=(e,t,r,n)=>{for(;e<=t;){const i=(e+t)/2|0,o=r(i);if(o<n)e=i+1;else if(o>n)t=i-1;else return i}return e>0?e-1:0};function ose({measurements:e,outerSize:t,scrollOffset:r,lanes:n}){const i=e.length-1,o=c=>e[c].start;if(e.length<=n)return{startIndex:0,endIndex:i};let a=wz(0,i,o,r),s=a;if(n===1)for(;s<i&&e[s].end<r+t;)s++;else if(n>1){const c=Array(n).fill(0);for(;s<i&&c.some(u=>u<r+t);){const u=e[s];c[u.lane]=u.end,s++}const d=Array(n).fill(r+t);for(;a>=0&&d.some(u=>u>=r);){const u=e[a];d[u.lane]=u.start,a--}a=Math.max(0,a-a%n),s=Math.min(i,s+(n-1-s%n))}return{startIndex:a,endIndex:s}}const hM=typeof document<"u"?nt.useLayoutEffect:nt.useEffect;function ase({useFlushSync:e=!0,...t}){const r=nt.useReducer(()=>({}),{})[1],n={...t,onChange:(o,a)=>{var s;e&&a?xn.flushSync(r):r(),(s=t.onChange)==null||s.call(t,o,a)}},[i]=nt.useState(()=>new ise(n));return i.setOptions(n),hM(()=>i._didMount(),[]),hM(()=>i._willUpdate()),i}function cd(e){return ase({observeElementRect:ese,observeElementOffset:tse,scrollToFn:nse,...e})}const sse=({item:e,depth:t})=>{const r=yr(),[n,i]=O.useState(!1),o=r.getPrivileges(),a=pe.populateShallow(e.includes,o);return C.jsxs("div",{className:"py-1 text-xs text-body",children:[C.jsxs("div",{className:"flex items-center",children:[C.jsx("button",{className:"-ml-1",onClick:s=>{s.stopPropagation(),i(!n)},children:C.jsx(uj,{className:an("h-4 w-4",{"tranform rotate-90":n})})})," ",C.jsx("div",{children:e.privilege})]}),C.jsx("div",{className:"border-l pl-2",style:{marginLeft:t?t*4:3},children:n&&C.jsx(Sz,{depth:t+1,data:a})})]})},Sz=({data:e,depth:t=0})=>e.map(r=>r.includes.length?C.jsx(sse,{item:r,depth:t},r.id):C.jsx("div",{className:an("py-1 text-xs",{}),children:r.privilege},r.id)),Br=()=>document.querySelector(`.${XD.ROLES_EDITOR_SCOPE_CLASS}`)||document.body,ef=({container:e,...t})=>C.jsx(pe.Portal,{...t,container:e||Br()}),pM=O.memo(function({privilege:t,selectedPrivilege:r,onSelect:n,isGuest:i=!1}){const o=yr(),a=o.getPrivileges(),s=pe.populateShallow(t.includes,a),[c,d]=O.useState(!1),[u,h]=O.useState(t.privilege),[p,v]=O.useState(null),x=pe.useOutsideClick(()=>{c&&w()});pe.useDidMountEffect(()=>{t.privilege!==u&&h(t.privilege)},[t.privilege]);function g(){d(!0),v(null)}function m(){d(!1),h(t.privilege)}function w(){v(null);try{pe.validateName(u);const S=pe.renamePrivilege(u,t.id,a);o.actions.updatePrivileges(S),d(!1)}catch(S){v(S.message)}}const y=async S=>{S.stopPropagation();const{confirmed:E}=await o.actions.openModal({title:"Delete Privilege",type:pe.ModalType.CONFIRM,color:pe.ModalColor.DANGER,message:"Are you sure you want to remove this Privilege?",icon:"FdWarningDanger"});if(E){const I=pe.removePrivilege(t.id,a);if((r==null?void 0:r.id)!==t.id){o.actions.updatePrivileges(I);return}const N=Object.keys(I).filter(T=>I[T].privilege!=="guest");if(N.length===0)n(null);else{const T=Object.keys(a).filter(W=>a[W].privilege!=="guest"),M=T.indexOf(t.id),z=Math.max(0,M-1),j=T[z];M===0?n(I[N[0]]):I[j]?n(I[j]):n(I[N[0]])}o.actions.updatePrivileges(I)}},_=O.useMemo(()=>t.resources.some(S=>S.exists===!1),[t]);return C.jsx(Lr,{container:Br(),color:"negative",icon:C.jsx(wi,{}),label:"This privilege uses non-existing resources",isHidden:!_,className:"w-full",usePortal:!0,children:C.jsxs(br,{depth:4,borderType:(r==null?void 0:r.id)===t.id?"primary":_?"negative":"light",className:an("w-full rounded border p-2"),role:"button","data-cy":"privilegeCard",onClick:()=>{n(t)},ref:x,children:[C.jsxs("div",{className:"flex items-center justify-between",children:[C.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[C.jsx("span",{className:"mr-4",children:i?C.jsx(wV,{className:"h-6 w-6"}):C.jsx(pd,{className:"h-6 w-6"})}),c?C.jsxs(wt.Root,{color:p?"negative":"primary",className:"flex-1 mr-2",children:[C.jsx(wt.Group,{className:"border-input-focus-border",children:C.jsx(wt.Field,{autoFocus:!0,value:u,onChange:S=>h(S.target.value),onKeyDown:S=>{S.key==="Enter"&&w(),S.key==="Escape"&&m()},type:"text"})}),p&&C.jsx(wt.Message,{children:p})]}):C.jsx("span",{title:u,className:"inline-block grow overflow-hidden truncate whitespace-nowrap text-xs font-bold",children:u})]}),i?C.jsx("div",{className:"flex items-center justify-center",children:C.jsx(Lr,{icon:C.jsx(wi,{}),label:C.jsx("div",{className:"max-w-xs flex-1 min-w-0 wrap-break-word whitespace-normal py-1",children:"Guest privileges are used to indicate resources accessible without any permission required (e.g. an authenticate function)"}),usePortal:!0,children:C.jsx(on,{className:"h-4 w-4"})})}):C.jsx("div",{className:"flex shrink-0 items-center gap-x-2",children:c?C.jsxs(C.Fragment,{children:[C.jsx(Jt,{variant:"ghost",color:"white",onClick:m,children:C.jsx("span",{children:C.jsx(ej,{className:"h-4 w-4"})})}),C.jsx(Jt,{variant:"ghost",color:"white",onClick:w,children:C.jsx("span",{children:C.jsx(mV,{className:"h-4 w-4"})})})]}):C.jsxs(C.Fragment,{children:[C.jsx(Jt,{variant:"ghost",color:"white",onClick:g,children:C.jsx(cj,{className:"h-4 w-4"})}),C.jsx(Jt,{variant:"ghost",color:"white",onClick:y,children:C.jsx(pj,{className:"h-4 w-4"})})]})})]}),s.length?C.jsx("div",{className:"ml-10.75",children:C.jsx(Sz,{data:s})}):null]})})}),lse=({privileges:e,selectPrivilege:t,selectedPrivilege:r})=>{const n=yr(),i=n.getGuestPrivilege(),o=n.getCatalog(),a=O.useMemo(()=>{if(o===null||!i)return i;const u=yz({guest:i},Object.values((o==null?void 0:o.dataClasses)??{}));return xz(u,o).guest},[e,o]),s=O.useMemo(()=>Object.entries(e).filter(([,u])=>u.privilege!=="guest").sort(([,u],[,h])=>pe.localeCompare(u.privilege,h.privilege)),[e]),c=O.useRef(null),d=cd({count:s.length,getScrollElement:()=>c.current,estimateSize:()=>72,overscan:5});return C.jsxs("div",{ref:c,className:"flex flex-1 flex-col overflow-auto p-4 pb-10 pt-1",children:[a?C.jsx("div",{className:"mb-4",children:C.jsx(pM,{privilege:a,onSelect:t,selectedPrivilege:r,privileges:e,isGuest:!0})}):null,s.length?C.jsx("div",{style:{position:"relative",height:`${d.getTotalSize()}px`},children:d.getVirtualItems().map(u=>{const[h,p]=s[u.index];return C.jsx("div",{ref:d.measureElement,"data-index":u.index,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${u.start}px)`,paddingBottom:"16px"},children:C.jsx(pM,{privilege:p,onSelect:t,selectedPrivilege:r,privileges:e})},h)})}):C.jsx("div",{className:"flex h-full items-center justify-center",children:C.jsx("div",{className:"flex flex-1 items-center justify-center",children:C.jsxs("div",{className:"flex flex-col items-center justify-center gap-y-4 text-inactive-text",children:[C.jsx(on,{className:"h-10 w-10"}),C.jsx("div",{className:"font-semibold",children:"There are no privileges"}),C.jsxs("div",{className:"flex items-center text-sm",children:["Create a new Privilege by clicking on the"," ",C.jsx(ja,{className:"ml-2 inline h-4 w-4"})]})]})})})]})};var au={exports:{}},su={exports:{}},ft={};/** @license React v16.13.1
94
+ color: hsl(${Math.max(0,Math.min(120-120*m,120))}deg 100% 31%);`,r==null?void 0:r.key)}return r!=null&&r.onChange&&!(o&&r.skipInitialOnChange)&&r.onChange(i),o=!1,i}return a.updateDeps=s=>{n=s},a}function cM(e,t){if(e===void 0)throw new Error("Unexpected undefined");return e}const Xae=(e,t)=>Math.abs(e-t)<1.01,Zae=(e,t,r)=>{let n;return function(...i){e.clearTimeout(n),n=e.setTimeout(()=>t.apply(this,i),r)}},uM=e=>{const{offsetWidth:t,offsetHeight:r}=e;return{width:t,height:r}},Jae=e=>e,Qae=e=>{const t=Math.max(e.startIndex-e.overscan,0),r=Math.min(e.endIndex+e.overscan,e.count-1),n=[];for(let i=t;i<=r;i++)n.push(i);return n},ese=(e,t)=>{const r=e.scrollElement;if(!r)return;const n=e.targetWindow;if(!n)return;const i=a=>{const{width:s,height:c}=a;t({width:Math.round(s),height:Math.round(c)})};if(i(uM(r)),!n.ResizeObserver)return()=>{};const o=new n.ResizeObserver(a=>{const s=()=>{const c=a[0];if(c!=null&&c.borderBoxSize){const d=c.borderBoxSize[0];if(d){i({width:d.inlineSize,height:d.blockSize});return}}i(uM(r))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(s):s()});return o.observe(r,{box:"border-box"}),()=>{o.unobserve(r)}},dM={passive:!0},fM=typeof window>"u"?!0:"onscrollend"in window,tse=(e,t)=>{const r=e.scrollElement;if(!r)return;const n=e.targetWindow;if(!n)return;let i=0;const o=e.options.useScrollendEvent&&fM?()=>{}:Zae(n,()=>{t(i,!1)},e.options.isScrollingResetDelay),a=u=>()=>{const{horizontal:h,isRtl:p}=e.options;i=h?r.scrollLeft*(p&&-1||1):r.scrollTop,o(),t(i,u)},s=a(!0),c=a(!1);r.addEventListener("scroll",s,dM);const d=e.options.useScrollendEvent&&fM;return d&&r.addEventListener("scrollend",c,dM),()=>{r.removeEventListener("scroll",s),d&&r.removeEventListener("scrollend",c)}},rse=(e,t,r)=>{if(t!=null&&t.borderBoxSize){const n=t.borderBoxSize[0];if(n)return Math.round(n[r.options.horizontal?"inlineSize":"blockSize"])}return e[r.options.horizontal?"offsetWidth":"offsetHeight"]},nse=(e,{adjustments:t=0,behavior:r},n)=>{var i,o;const a=e+t;(o=(i=n.scrollElement)==null?void 0:i.scrollTo)==null||o.call(i,{[n.options.horizontal?"left":"top"]:a,behavior:r})};class ise{constructor(t){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this.itemSizeCache=new Map,this.laneAssignments=new Map,this.pendingMeasuredCacheIndexes=[],this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this.elementsCache=new Map,this.now=()=>{var r,n,i;return((i=(n=(r=this.targetWindow)==null?void 0:r.performance)==null?void 0:n.now)==null?void 0:i.call(n))??Date.now()},this.observer=(()=>{let r=null;const n=()=>r||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:r=new this.targetWindow.ResizeObserver(i=>{i.forEach(o=>{const a=()=>{const s=o.target,c=this.indexFromElement(s);if(!s.isConnected){this.observer.unobserve(s);return}this.shouldMeasureDuringScroll(c)&&this.resizeItem(c,this.options.measureElement(s,o,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(a):a()})}));return{disconnect:()=>{var i;(i=n())==null||i.disconnect(),r=null},observe:i=>{var o;return(o=n())==null?void 0:o.observe(i,{box:"border-box"})},unobserve:i=>{var o;return(o=n())==null?void 0:o.unobserve(i)}}})(),this.range=null,this.setOptions=r=>{Object.entries(r).forEach(([n,i])=>{typeof i>"u"&&delete r[n]}),this.options={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:Jae,rangeExtractor:Qae,onChange:()=>{},measureElement:rse,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,...r}},this.notify=r=>{var n,i;(i=(n=this.options).onChange)==null||i.call(n,this,r)},this.maybeNotify=da(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),r=>{this.notify(r)},{key:process.env.NODE_ENV!=="production"&&"maybeNotify",debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(r=>r()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var r;const n=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==n){if(this.cleanup(),!n){this.maybeNotify();return}this.scrollElement=n,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((r=this.scrollElement)==null?void 0:r.window)??null,this.elementsCache.forEach(i=>{this.observer.observe(i)}),this.unsubs.push(this.options.observeElementRect(this,i=>{this.scrollRect=i,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(i,o)=>{this.scrollAdjustments=0,this.scrollDirection=o?this.getScrollOffset()<i?"forward":"backward":null,this.scrollOffset=i,this.isScrolling=o,this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset=="function"?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getFurthestMeasurement=(r,n)=>{const i=new Map,o=new Map;for(let a=n-1;a>=0;a--){const s=r[a];if(i.has(s.lane))continue;const c=o.get(s.lane);if(c==null||s.end>c.end?o.set(s.lane,s):s.end<c.end&&i.set(s.lane,!0),i.size===this.options.lanes)break}return o.size===this.options.lanes?Array.from(o.values()).sort((a,s)=>a.end===s.end?a.index-s.index:a.end-s.end)[0]:void 0},this.getMeasurementOptions=da(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes],(r,n,i,o,a,s)=>(this.prevLanes!==void 0&&this.prevLanes!==s&&(this.lanesChangedFlag=!0),this.prevLanes=s,this.pendingMeasuredCacheIndexes=[],{count:r,paddingStart:n,scrollMargin:i,getItemKey:o,enabled:a,lanes:s}),{key:!1}),this.getMeasurements=da(()=>[this.getMeasurementOptions(),this.itemSizeCache],({count:r,paddingStart:n,scrollMargin:i,getItemKey:o,enabled:a,lanes:s},c)=>{if(!a)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>r)for(const p of this.laneAssignments.keys())p>=r&&this.laneAssignments.delete(p);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMeasuredCacheIndexes=[]),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(p=>{this.itemSizeCache.set(p.key,p.size)}));const d=this.lanesSettling?0:this.pendingMeasuredCacheIndexes.length>0?Math.min(...this.pendingMeasuredCacheIndexes):0;this.pendingMeasuredCacheIndexes=[],this.lanesSettling&&this.measurementsCache.length===r&&(this.lanesSettling=!1);const u=this.measurementsCache.slice(0,d),h=new Array(s).fill(void 0);for(let p=0;p<d;p++){const v=u[p];v&&(h[v.lane]=p)}for(let p=d;p<r;p++){const v=o(p),x=this.laneAssignments.get(p);let g,m;if(x!==void 0&&this.options.lanes>1){g=x;const S=h[g],E=S!==void 0?u[S]:void 0;m=E?E.end+this.options.gap:n+i}else{const S=this.options.lanes===1?u[p-1]:this.getFurthestMeasurement(u,p);m=S?S.end+this.options.gap:n+i,g=S?S.lane:p%this.options.lanes,this.options.lanes>1&&this.laneAssignments.set(p,g)}const w=c.get(v),y=typeof w=="number"?w:this.options.estimateSize(p),_=m+y;u[p]={index:p,start:m,size:y,end:_,key:v,lane:g},h[g]=p}return this.measurementsCache=u,u},{key:process.env.NODE_ENV!=="production"&&"getMeasurements",debug:()=>this.options.debug}),this.calculateRange=da(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(r,n,i,o)=>this.range=r.length>0&&n>0?ose({measurements:r,outerSize:n,scrollOffset:i,lanes:o}):null,{key:process.env.NODE_ENV!=="production"&&"calculateRange",debug:()=>this.options.debug}),this.getVirtualIndexes=da(()=>{let r=null,n=null;const i=this.calculateRange();return i&&(r=i.startIndex,n=i.endIndex),this.maybeNotify.updateDeps([this.isScrolling,r,n]),[this.options.rangeExtractor,this.options.overscan,this.options.count,r,n]},(r,n,i,o,a)=>o===null||a===null?[]:r({startIndex:o,endIndex:a,overscan:n,count:i}),{key:process.env.NODE_ENV!=="production"&&"getVirtualIndexes",debug:()=>this.options.debug}),this.indexFromElement=r=>{const n=this.options.indexAttribute,i=r.getAttribute(n);return i?parseInt(i,10):(console.warn(`Missing attribute name '${n}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=r=>{var n;if(!this.scrollState||this.scrollState.behavior!=="smooth")return!0;const i=this.scrollState.index??((n=this.getVirtualItemForOffset(this.scrollState.lastTargetOffset))==null?void 0:n.index);if(i!==void 0&&this.range){const o=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),a=Math.max(0,i-o),s=Math.min(this.options.count-1,i+o);return r>=a&&r<=s}return!0},this.measureElement=r=>{if(!r){this.elementsCache.forEach((a,s)=>{a.isConnected||(this.observer.unobserve(a),this.elementsCache.delete(s))});return}const n=this.indexFromElement(r),i=this.options.getItemKey(n),o=this.elementsCache.get(i);o!==r&&(o&&this.observer.unobserve(o),this.observer.observe(r),this.elementsCache.set(i,r)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(n)&&this.resizeItem(n,this.options.measureElement(r,void 0,this))},this.resizeItem=(r,n)=>{var i;const o=this.measurementsCache[r];if(!o)return;const a=this.itemSizeCache.get(o.key)??o.size,s=n-a;s!==0&&(((i=this.scrollState)==null?void 0:i.behavior)!=="smooth"&&(this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(o,s,this):o.start<this.getScrollOffset()+this.scrollAdjustments)&&(process.env.NODE_ENV!=="production"&&this.options.debug&&console.info("correction",s),this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=s,behavior:void 0})),this.pendingMeasuredCacheIndexes.push(o.index),this.itemSizeCache=new Map(this.itemSizeCache.set(o.key,n)),this.notify(!1))},this.getVirtualItems=da(()=>[this.getVirtualIndexes(),this.getMeasurements()],(r,n)=>{const i=[];for(let o=0,a=r.length;o<a;o++){const s=r[o],c=n[s];i.push(c)}return i},{key:process.env.NODE_ENV!=="production"&&"getVirtualItems",debug:()=>this.options.debug}),this.getVirtualItemForOffset=r=>{const n=this.getMeasurements();if(n.length!==0)return cM(n[wz(0,n.length-1,i=>cM(n[i]).start,r)])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if("scrollHeight"in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{const r=this.scrollElement.document.documentElement;return this.options.horizontal?r.scrollWidth-this.scrollElement.innerWidth:r.scrollHeight-this.scrollElement.innerHeight}},this.getOffsetForAlignment=(r,n,i=0)=>{if(!this.scrollElement)return 0;const o=this.getSize(),a=this.getScrollOffset();n==="auto"&&(n=r>=a+o?"end":"start"),n==="center"?r+=(i-o)/2:n==="end"&&(r-=o);const s=this.getMaxScrollOffset();return Math.max(Math.min(s,r),0)},this.getOffsetForIndex=(r,n="auto")=>{r=Math.max(0,Math.min(r,this.options.count-1));const i=this.getSize(),o=this.getScrollOffset(),a=this.measurementsCache[r];if(!a)return;if(n==="auto")if(a.end>=o+i-this.options.scrollPaddingEnd)n="end";else if(a.start<=o+this.options.scrollPaddingStart)n="start";else return[o,n];if(n==="end"&&r===this.options.count-1)return[this.getMaxScrollOffset(),n];const s=n==="end"?a.end+this.options.scrollPaddingEnd:a.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(s,n,a.size),n]},this.scrollToOffset=(r,{align:n="start",behavior:i="auto"}={})=>{const o=this.getOffsetForAlignment(r,n),a=this.now();this.scrollState={index:null,align:n,behavior:i,startedAt:a,lastTargetOffset:o,stableFrames:0},this._scrollToOffset(o,{adjustments:void 0,behavior:i}),this.scheduleScrollReconcile()},this.scrollToIndex=(r,{align:n="auto",behavior:i="auto"}={})=>{r=Math.max(0,Math.min(r,this.options.count-1));const o=this.getOffsetForIndex(r,n);if(!o)return;const[a,s]=o,c=this.now();this.scrollState={index:r,align:s,behavior:i,startedAt:c,lastTargetOffset:a,stableFrames:0},this._scrollToOffset(a,{adjustments:void 0,behavior:i}),this.scheduleScrollReconcile()},this.scrollBy=(r,{behavior:n="auto"}={})=>{const i=this.getScrollOffset()+r,o=this.now();this.scrollState={index:null,align:"start",behavior:n,startedAt:o,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:n}),this.scheduleScrollReconcile()},this.getTotalSize=()=>{var r;const n=this.getMeasurements();let i;if(n.length===0)i=this.options.paddingStart;else if(this.options.lanes===1)i=((r=n[n.length-1])==null?void 0:r.end)??0;else{const o=Array(this.options.lanes).fill(null);let a=n.length-1;for(;a>=0&&o.some(s=>s===null);){const s=n[a];o[s.lane]===null&&(o[s.lane]=s.end),a--}i=Math.max(...o.filter(s=>s!==null))}return Math.max(i-this.options.scrollMargin+this.options.paddingEnd,0)},this._scrollToOffset=(r,{adjustments:n,behavior:i})=>{this.options.scrollToFn(r,{behavior:i,adjustments:n},this)},this.measure=()=>{this.itemSizeCache=new Map,this.laneAssignments=new Map,this.notify(!1)},this.setOptions(t)}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId==null&&(this.rafId=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}))}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}const n=this.scrollState.index!=null?this.getOffsetForIndex(this.scrollState.index,this.scrollState.align):void 0,i=n?n[0]:this.scrollState.lastTargetOffset,o=1,a=i!==this.scrollState.lastTargetOffset;if(!a&&Xae(i,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=o){this.scrollState=null;return}}else this.scrollState.stableFrames=0,a&&(this.scrollState.lastTargetOffset=i,this.scrollState.behavior="auto",this._scrollToOffset(i,{adjustments:void 0,behavior:"auto"}));this.scheduleScrollReconcile()}}const wz=(e,t,r,n)=>{for(;e<=t;){const i=(e+t)/2|0,o=r(i);if(o<n)e=i+1;else if(o>n)t=i-1;else return i}return e>0?e-1:0};function ose({measurements:e,outerSize:t,scrollOffset:r,lanes:n}){const i=e.length-1,o=c=>e[c].start;if(e.length<=n)return{startIndex:0,endIndex:i};let a=wz(0,i,o,r),s=a;if(n===1)for(;s<i&&e[s].end<r+t;)s++;else if(n>1){const c=Array(n).fill(0);for(;s<i&&c.some(u=>u<r+t);){const u=e[s];c[u.lane]=u.end,s++}const d=Array(n).fill(r+t);for(;a>=0&&d.some(u=>u>=r);){const u=e[a];d[u.lane]=u.start,a--}a=Math.max(0,a-a%n),s=Math.min(i,s+(n-1-s%n))}return{startIndex:a,endIndex:s}}const hM=typeof document<"u"?nt.useLayoutEffect:nt.useEffect;function ase({useFlushSync:e=!0,...t}){const r=nt.useReducer(()=>({}),{})[1],n={...t,onChange:(o,a)=>{var s;e&&a?xn.flushSync(r):r(),(s=t.onChange)==null||s.call(t,o,a)}},[i]=nt.useState(()=>new ise(n));return i.setOptions(n),hM(()=>i._didMount(),[]),hM(()=>i._willUpdate()),i}function cd(e){return ase({observeElementRect:ese,observeElementOffset:tse,scrollToFn:nse,...e})}const sse=({item:e,depth:t})=>{const r=yr(),[n,i]=O.useState(!1),o=r.getPrivileges(),a=pe.populateShallow(e.includes,o);return C.jsxs("div",{className:"py-1 text-xs text-body",children:[C.jsxs("div",{className:"flex items-center",children:[C.jsx("button",{className:"-ml-1",onClick:s=>{s.stopPropagation(),i(!n)},children:C.jsx(uj,{className:an("h-4 w-4",{"tranform rotate-90":n})})})," ",C.jsx("div",{children:e.privilege})]}),C.jsx("div",{className:"border-l pl-2",style:{marginLeft:t?t*4:3},children:n&&C.jsx(Sz,{depth:t+1,data:a})})]})},Sz=({data:e,depth:t=0})=>e.map(r=>r.includes.length?C.jsx(sse,{item:r,depth:t},r.id):C.jsx("div",{className:an("py-1 text-xs",{}),children:r.privilege},r.id)),Br=()=>document.querySelector(`.${XD.ROLES_EDITOR_SCOPE_CLASS}`)||document.body,ef=({container:e,...t})=>C.jsx(pe.Portal,{...t,container:e||Br()}),pM=O.memo(function({privilege:t,selectedPrivilege:r,onSelect:n,isGuest:i=!1}){const o=yr(),a=o.getPrivileges(),s=pe.populateShallow(t.includes,a),[c,d]=O.useState(!1),[u,h]=O.useState(t.privilege),[p,v]=O.useState(null),x=pe.useOutsideClick(()=>{c&&w()});pe.useDidMountEffect(()=>{t.privilege!==u&&h(t.privilege)},[t.privilege]);function g(){d(!0),v(null)}function m(){d(!1),h(t.privilege)}function w(){v(null);try{pe.validateName(u);const S=pe.renamePrivilege(u,t.id,a);o.actions.updatePrivileges(S),d(!1)}catch(S){v(S.message)}}const y=async S=>{S.stopPropagation();const E=()=>{const N=pe.removePrivilege(t.id,a);if((r==null?void 0:r.id)!==t.id){o.actions.updatePrivileges(N);return}const T=Object.keys(N).filter(M=>N[M].privilege!=="guest");if(T.length===0)n(null);else{const M=Object.keys(a).filter(U=>a[U].privilege!=="guest"),z=M.indexOf(t.id),j=Math.max(0,z-1),W=M[j];z===0?n(N[T[0]]):N[W]?n(N[W]):n(N[T[0]])}o.actions.updatePrivileges(N)};if(o.getHost()==="vscode"){E();return}const{confirmed:I}=await o.actions.openModal({title:"Delete Privilege",type:pe.ModalType.CONFIRM,color:pe.ModalColor.DANGER,message:"Are you sure you want to remove this Privilege?",icon:"FdWarningDanger"});I&&E()},_=O.useMemo(()=>t.resources.some(S=>S.exists===!1),[t]);return C.jsx(Lr,{container:Br(),color:"negative",icon:C.jsx(wi,{}),label:"This privilege uses non-existing resources",isHidden:!_,className:"w-full",usePortal:!0,children:C.jsxs(br,{depth:4,borderType:(r==null?void 0:r.id)===t.id?"primary":_?"negative":"light",className:an("w-full rounded border p-2"),role:"button","data-cy":"privilegeCard",onClick:()=>{n(t)},ref:x,children:[C.jsxs("div",{className:"flex items-center justify-between",children:[C.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[C.jsx("span",{className:"mr-4",children:i?C.jsx(wV,{className:"h-6 w-6"}):C.jsx(pd,{className:"h-6 w-6"})}),c?C.jsxs(wt.Root,{color:p?"negative":"primary",className:"flex-1 mr-2",children:[C.jsx(wt.Group,{className:"border-input-focus-border",children:C.jsx(wt.Field,{autoFocus:!0,value:u,onChange:S=>h(S.target.value),onKeyDown:S=>{S.key==="Enter"&&w(),S.key==="Escape"&&m()},type:"text"})}),p&&C.jsx(wt.Message,{children:p})]}):C.jsx("span",{title:u,className:"inline-block grow overflow-hidden truncate whitespace-nowrap text-xs font-bold",children:u})]}),i?C.jsx("div",{className:"flex items-center justify-center",children:C.jsx(Lr,{icon:C.jsx(wi,{}),label:C.jsx("div",{className:"max-w-xs flex-1 min-w-0 wrap-break-word whitespace-normal py-1",children:"Guest privileges are used to indicate resources accessible without any permission required (e.g. an authenticate function)"}),usePortal:!0,children:C.jsx(on,{className:"h-4 w-4"})})}):C.jsx("div",{className:"flex shrink-0 items-center gap-x-2",children:c?C.jsxs(C.Fragment,{children:[C.jsx(Jt,{variant:"ghost",color:"white",onClick:m,children:C.jsx("span",{children:C.jsx(ej,{className:"h-4 w-4"})})}),C.jsx(Jt,{variant:"ghost",color:"white",onClick:w,children:C.jsx("span",{children:C.jsx(mV,{className:"h-4 w-4"})})})]}):C.jsxs(C.Fragment,{children:[C.jsx(Jt,{variant:"ghost",color:"white",onClick:g,children:C.jsx(cj,{className:"h-4 w-4"})}),C.jsx(Jt,{variant:"ghost",color:"white",onClick:y,children:C.jsx(pj,{className:"h-4 w-4"})})]})})]}),s.length?C.jsx("div",{className:"ml-10.75",children:C.jsx(Sz,{data:s})}):null]})})}),lse=({privileges:e,selectPrivilege:t,selectedPrivilege:r})=>{const n=yr(),i=n.getGuestPrivilege(),o=n.getCatalog(),a=O.useMemo(()=>{if(o===null||!i)return i;const u=yz({guest:i},Object.values((o==null?void 0:o.dataClasses)??{}));return xz(u,o).guest},[e,o]),s=O.useMemo(()=>Object.entries(e).filter(([,u])=>u.privilege!=="guest").sort(([,u],[,h])=>pe.localeCompare(u.privilege,h.privilege)),[e]),c=O.useRef(null),d=cd({count:s.length,getScrollElement:()=>c.current,estimateSize:()=>72,overscan:5});return C.jsxs("div",{ref:c,className:"flex flex-1 flex-col overflow-auto p-4 pb-10 pt-1",children:[a?C.jsx("div",{className:"mb-4",children:C.jsx(pM,{privilege:a,onSelect:t,selectedPrivilege:r,privileges:e,isGuest:!0})}):null,s.length?C.jsx("div",{style:{position:"relative",height:`${d.getTotalSize()}px`},children:d.getVirtualItems().map(u=>{const[h,p]=s[u.index];return C.jsx("div",{ref:d.measureElement,"data-index":u.index,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${u.start}px)`,paddingBottom:"16px"},children:C.jsx(pM,{privilege:p,onSelect:t,selectedPrivilege:r,privileges:e})},h)})}):C.jsx("div",{className:"flex h-full items-center justify-center",children:C.jsx("div",{className:"flex flex-1 items-center justify-center",children:C.jsxs("div",{className:"flex flex-col items-center justify-center gap-y-4 text-inactive-text",children:[C.jsx(on,{className:"h-10 w-10"}),C.jsx("div",{className:"font-semibold",children:"There are no privileges"}),C.jsxs("div",{className:"flex items-center text-sm",children:["Create a new Privilege by clicking on the"," ",C.jsx(ja,{className:"ml-2 inline h-4 w-4"})]})]})})})]})};var au={exports:{}},su={exports:{}},ft={};/** @license React v16.13.1
95
95
  * react-is.production.min.js
96
96
  *
97
97
  * Copyright (c) Facebook, Inc. and its affiliates.
@@ -116,5 +116,5 @@ Valid keys: `+JSON.stringify(Object.keys(P),null," "));var Z=ve(q,ne,D,$,H+"."+
116
116
  `)&&(B="(?: "+B+")",Q=" "+Q,X++),W=new RegExp("^(?:"+B+")",P)),_&&(W=new RegExp("^"+B+"$(?!\\s)",P)),w&&(U=N.lastIndex),A=e(h,re?W:N,Q),re?A?(A.input=m(A.input,X),A[0]=m(A[0],X),A.index=N.lastIndex,N.lastIndex+=A[0].length):N.lastIndex=0:w&&A&&(N.lastIndex=N.global?A.index+A[0].length:U),_&&A&&A.length>1&&e(u,A[0],W,function(){for(K=1;K<arguments.length-2;K++)arguments[K]===void 0&&(A[K]=void 0)}),A&&G)for(A.groups=V=a(null),K=0;K<G.length;K++)te=G[K],V[te[0]]=A[te[1]];return A}),pw=p,pw}var OD;function uL(){if(OD)return yD;OD=1;var e=no(),t=fE();return e({target:"RegExp",proto:!0,forced:/./.exec!==t},{exec:t}),yD}uL();var CD={},vw,ID;function dL(){if(ID)return vw;ID=1,uL();var e=Ur(),t=zo(),r=fE(),n=St(),i=Pr(),o=Bl(),a=i("species"),s=RegExp.prototype;return vw=function(c,d,u,h){var p=i(c),v=!n(function(){var w={};return w[p]=function(){return 7},""[c](w)!==7}),x=v&&!n(function(){var w=!1,y=/a/;return c==="split"&&(y={},y.constructor={},y.constructor[a]=function(){return y},y.flags="",y[p]=/./[p]),y.exec=function(){return w=!0,null},y[p](""),!w});if(!v||!x||u){var g=/./[p],m=d(p,""[c],function(w,y,_,S,E){var I=y.exec;return I===r||I===s.exec?v&&!E?{done:!0,value:e(g,y,_,S)}:{done:!0,value:e(w,_,y,S)}:{done:!1}});t(String.prototype,c,m[0]),t(s,p,m[1])}h&&o(s[p],"sham",!0)},vw}var gw,RD;function fL(){if(RD)return gw;RD=1;var e=Xz().charAt;return gw=function(t,r,n){return r+(n?e(t,r).length:1)},gw}var mw,ND;function Gle(){if(ND)return mw;ND=1;var e=Gt(),t=St(),r=e.RegExp,n=!t(function(){var i=!0;try{r(".","d")}catch{i=!1}var o={},a="",s=i?"dgimsy":"gimsy",c=function(p,v){Object.defineProperty(o,p,{get:function(){return a+=v,!0}})},d={dotAll:"s",global:"g",ignoreCase:"i",multiline:"m",sticky:"y"};i&&(d.hasIndices="d");for(var u in d)c(u,d[u]);var h=Object.getOwnPropertyDescriptor(r.prototype,"flags").get.call(o);return h!==s||a!==s});return mw={correct:n},mw}var bw,TD;function hL(){if(TD)return bw;TD=1;var e=Ur(),t=In(),r=of(),n=Gle(),i=cL(),o=RegExp.prototype;return bw=n.correct?function(a){return a.flags}:function(a){return!n.correct&&r(o,a)&&!t(a,"flags")?e(i,a):a.flags},bw}var yw,PD;function pL(){if(PD)return yw;PD=1;var e=Ur(),t=Rn(),r=er(),n=ro(),i=fE(),o=TypeError;return yw=function(a,s){var c=a.exec;if(r(c)){var d=e(c,a,s);return d!==null&&t(d),d}if(n(a)==="RegExp")return e(i,a,s);throw new o("RegExp#exec called on incompatible receiver")},yw}var MD;function Kle(){if(MD)return CD;MD=1;var e=Ur(),t=yt(),r=dL(),n=Rn(),i=dr(),o=aE(),a=Lo(),s=qo(),c=Ll(),d=fL(),u=hL(),h=pL(),p=t("".indexOf);return r("match",function(v,x,g){return[function(w){var y=s(this),_=i(w)?c(w,v):void 0;return _?e(_,w,y):new RegExp(w)[v](a(y))},function(m){var w=n(this),y=a(m),_=g(x,w,y);if(_.done)return _.value;var S=a(u(w));if(p(S,"g")===-1)return h(w,y);var E=p(S,"u")!==-1;w.lastIndex=0;for(var I=[],N=0,T;(T=h(w,y))!==null;){var M=a(T[0]);I[N]=M,M===""&&(w.lastIndex=d(y,o(w.lastIndex),E)),N++}return N===0?null:I}]}),CD}Kle();var kD={},xw,AD;function Yle(){if(AD)return xw;AD=1;var e=jz(),t=Ii();return xw=function(r,n,i){return i.get&&e(i.get,n,{getter:!0}),i.set&&e(i.set,n,{setter:!0}),t.f(r,n,i)},xw}var DD;function Xle(){if(DD)return kD;DD=1;var e=Wn(),t=iE().EXISTS,r=yt(),n=Yle(),i=Function.prototype,o=r(i.toString),a=/function\b(?:\s|\/\*[\S\s]*?\*\/|\/\/[^\n\r]*[\n\r]+)*([^\s(/]*)/,s=r(a.exec),c="name";return e&&!t&&n(i,c,{configurable:!0,get:function(){try{return s(a,o(this))[1]}catch{return""}}}),kD}Xle();var jD={},ww,qD;function Zle(){if(qD)return ww;qD=1;var e=tf(),t=Function.prototype,r=t.apply,n=t.call;return ww=typeof Reflect=="object"&&Reflect.apply||(e?n.bind(r):function(){return n.apply(r,arguments)}),ww}var Sw,zD;function Jle(){if(zD)return Sw;zD=1;var e=yt(),t=Ya(),r=Math.floor,n=e("".charAt),i=e("".replace),o=e("".slice),a=/\$([$&'`]|\d{1,2}|<[^>]*>)/g,s=/\$([$&'`]|\d{1,2})/g;return Sw=function(c,d,u,h,p,v){var x=u+c.length,g=h.length,m=s;return p!==void 0&&(p=t(p),m=a),i(v,m,function(w,y){var _;switch(n(y,0)){case"$":return"$";case"&":return c;case"`":return o(d,0,u);case"'":return o(d,x);case"<":_=p[o(y,1,-1)];break;default:var S=+y;if(S===0)return w;if(S>g){var E=r(S/10);return E===0?w:E<=g?h[E-1]===void 0?n(y,1):h[E-1]+n(y,1):w}_=h[S-1]}return _===void 0?"":_})},Sw}var LD;function Qle(){if(LD)return jD;LD=1;var e=Zle(),t=Ur(),r=yt(),n=dL(),i=St(),o=Rn(),a=er(),s=dr(),c=lf(),d=aE(),u=Lo(),h=qo(),p=fL(),v=Ll(),x=Jle(),g=hL(),m=pL(),w=Pr(),y=w("replace"),_=Math.max,S=Math.min,E=r([].concat),I=r([].push),N=r("".indexOf),T=r("".slice),M=function(U){return U===void 0?U:String(U)},z=(function(){return"a".replace(/./,"$0")==="$0"})(),j=(function(){return/./[y]?/./[y]("a","$0")==="":!1})(),W=!i(function(){var U=/./;return U.exec=function(){var A=[];return A.groups={a:"7"},A},"".replace(U,"$<a>")!=="7"});return n("replace",function(U,A,K){var V=j?"$":"$0";return[function(G,re){var P=h(this),B=s(G)?v(G,y):void 0;return B?t(B,G,P,re):t(A,u(P),G,re)},function(te,G){var re=o(this),P=u(te);if(typeof G=="string"&&N(G,V)===-1&&N(G,"$<")===-1){var B=K(A,re,P,G);if(B.done)return B.value}var X=a(G);X||(G=u(G));var Q=u(g(re)),D=N(Q,"g")!==-1,$;D&&($=N(Q,"u")!==-1,re.lastIndex=0);for(var H=[],q;q=m(re,P),!(q===null||(I(H,q),!D));){var Y=u(q[0]);Y===""&&(re.lastIndex=p(P,d(re.lastIndex),$))}for(var ie="",ne=0,ve=0;ve<H.length;ve++){q=H[ve];for(var Z=u(q[0]),J=_(S(c(q.index),P.length),0),ae=[],he,ue=1;ue<q.length;ue++)I(ae,M(q[ue]));var de=q.groups;if(X){var le=E([Z],ae,J,P);de!==void 0&&I(le,de),he=u(e(G,void 0,le))}else he=x(Z,P,J,ae,de,G);J>=ne&&(ie+=T(P,ne,J)+he,ne=J+Z.length)}return ie+T(P,ne)}]},!W||!z||j),jD}Qle();function Wi(e){return!e||!e.ownerDocument||!e.ownerDocument.defaultView?window:e.ownerDocument.defaultView}function Nu(e){return!e||!e.ownerDocument?document:e.ownerDocument}var ma=null,BD=null;lL&&window.addEventListener("resize",function(){BD!==window.devicePixelRatio&&(BD=window.devicePixelRatio,ma=null)});function FD(e){if(ma===null){var t=Nu(e);if(typeof t>"u")return ma=0,ma;var r=t.body,n=t.createElement("div");n.classList.add("simplebar-hide-scrollbar"),r.appendChild(n);var i=n.getBoundingClientRect().right;r.removeChild(n),ma=i}return ma}var ud=(function(){function e(r,n){var i=this;this.onScroll=function(){var o=Wi(i.el);i.scrollXTicking||(o.requestAnimationFrame(i.scrollX),i.scrollXTicking=!0),i.scrollYTicking||(o.requestAnimationFrame(i.scrollY),i.scrollYTicking=!0)},this.scrollX=function(){i.axis.x.isOverflowing&&(i.showScrollbar("x"),i.positionScrollbar("x")),i.scrollXTicking=!1},this.scrollY=function(){i.axis.y.isOverflowing&&(i.showScrollbar("y"),i.positionScrollbar("y")),i.scrollYTicking=!1},this.onMouseEnter=function(){i.showScrollbar("x"),i.showScrollbar("y")},this.onMouseMove=function(o){i.mouseX=o.clientX,i.mouseY=o.clientY,(i.axis.x.isOverflowing||i.axis.x.forceVisible)&&i.onMouseMoveForAxis("x"),(i.axis.y.isOverflowing||i.axis.y.forceVisible)&&i.onMouseMoveForAxis("y")},this.onMouseLeave=function(){i.onMouseMove.cancel(),(i.axis.x.isOverflowing||i.axis.x.forceVisible)&&i.onMouseLeaveForAxis("x"),(i.axis.y.isOverflowing||i.axis.y.forceVisible)&&i.onMouseLeaveForAxis("y"),i.mouseX=-1,i.mouseY=-1},this.onWindowResize=function(){i.scrollbarWidth=i.getScrollbarWidth(),i.hideNativeScrollbar()},this.hideScrollbars=function(){i.axis.x.track.rect=i.axis.x.track.el.getBoundingClientRect(),i.axis.y.track.rect=i.axis.y.track.el.getBoundingClientRect(),i.isWithinBounds(i.axis.y.track.rect)||(i.axis.y.scrollbar.el.classList.remove(i.classNames.visible),i.axis.y.isVisible=!1),i.isWithinBounds(i.axis.x.track.rect)||(i.axis.x.scrollbar.el.classList.remove(i.classNames.visible),i.axis.x.isVisible=!1)},this.onPointerEvent=function(o){var a,s;i.axis.x.track.rect=i.axis.x.track.el.getBoundingClientRect(),i.axis.y.track.rect=i.axis.y.track.el.getBoundingClientRect(),(i.axis.x.isOverflowing||i.axis.x.forceVisible)&&(a=i.isWithinBounds(i.axis.x.track.rect)),(i.axis.y.isOverflowing||i.axis.y.forceVisible)&&(s=i.isWithinBounds(i.axis.y.track.rect)),(a||s)&&(o.preventDefault(),o.stopPropagation(),o.type==="mousedown"&&(a&&(i.axis.x.scrollbar.rect=i.axis.x.scrollbar.el.getBoundingClientRect(),i.isWithinBounds(i.axis.x.scrollbar.rect)?i.onDragStart(o,"x"):i.onTrackClick(o,"x")),s&&(i.axis.y.scrollbar.rect=i.axis.y.scrollbar.el.getBoundingClientRect(),i.isWithinBounds(i.axis.y.scrollbar.rect)?i.onDragStart(o,"y"):i.onTrackClick(o,"y"))))},this.drag=function(o){var a,s=i.axis[i.draggedAxis].track,c=s.rect[i.axis[i.draggedAxis].sizeAttr],d=i.axis[i.draggedAxis].scrollbar,u=i.contentWrapperEl[i.axis[i.draggedAxis].scrollSizeAttr],h=parseInt(i.elStyles[i.axis[i.draggedAxis].sizeAttr],10);o.preventDefault(),o.stopPropagation(),i.draggedAxis==="y"?a=o.pageY:a=o.pageX;var p=a-s.rect[i.axis[i.draggedAxis].offsetAttr]-i.axis[i.draggedAxis].dragOffset,v=p/(c-d.size),x=v*(u-h);i.draggedAxis==="x"&&(x=i.isRtl&&e.getRtlHelpers().isRtlScrollbarInverted?x-(c+d.size):x,x=i.isRtl&&e.getRtlHelpers().isRtlScrollingInverted?-x:x),i.contentWrapperEl[i.axis[i.draggedAxis].scrollOffsetAttr]=x},this.onEndDrag=function(o){var a=Nu(i.el),s=Wi(i.el);o.preventDefault(),o.stopPropagation(),i.el.classList.remove(i.classNames.dragging),a.removeEventListener("mousemove",i.drag,!0),a.removeEventListener("mouseup",i.onEndDrag,!0),i.removePreventClickId=s.setTimeout(function(){a.removeEventListener("click",i.preventClick,!0),a.removeEventListener("dblclick",i.preventClick,!0),i.removePreventClickId=null})},this.preventClick=function(o){o.preventDefault(),o.stopPropagation()},this.el=r,this.minScrollbarWidth=20,this.options=Object.assign({},e.defaultOptions,n),this.classNames=Object.assign({},e.defaultOptions.classNames,this.options.classNames),this.axis={x:{scrollOffsetAttr:"scrollLeft",sizeAttr:"width",scrollSizeAttr:"scrollWidth",offsetSizeAttr:"offsetWidth",offsetAttr:"left",overflowAttr:"overflowX",dragOffset:0,isOverflowing:!0,isVisible:!1,forceVisible:!1,track:{},scrollbar:{}},y:{scrollOffsetAttr:"scrollTop",sizeAttr:"height",scrollSizeAttr:"scrollHeight",offsetSizeAttr:"offsetHeight",offsetAttr:"top",overflowAttr:"overflowY",dragOffset:0,isOverflowing:!0,isVisible:!1,forceVisible:!1,track:{},scrollbar:{}}},this.removePreventClickId=null,!e.instances.has(this.el)&&(this.recalculate=QA(this.recalculate.bind(this),64),this.onMouseMove=QA(this.onMouseMove.bind(this),64),this.hideScrollbars=tD(this.hideScrollbars.bind(this),this.options.timeout),this.onWindowResize=tD(this.onWindowResize.bind(this),64,{leading:!0}),e.getRtlHelpers=vle(e.getRtlHelpers),this.init())}e.getRtlHelpers=function(){var n=document.createElement("div");n.innerHTML='<div class="hs-dummy-scrollbar-size"><div style="height: 200%; width: 200%; margin: 10px 0;"></div></div>';var i=n.firstElementChild;document.body.appendChild(i);var o=i.firstElementChild;i.scrollLeft=0;var a=e.getOffset(i),s=e.getOffset(o);i.scrollLeft=999;var c=e.getOffset(o);return{isRtlScrollingInverted:a.left!==s.left&&s.left-c.left!==0,isRtlScrollbarInverted:a.left!==s.left}},e.getOffset=function(n){var i=n.getBoundingClientRect(),o=Nu(n),a=Wi(n);return{top:i.top+(a.pageYOffset||o.documentElement.scrollTop),left:i.left+(a.pageXOffset||o.documentElement.scrollLeft)}};var t=e.prototype;return t.init=function(){e.instances.set(this.el,this),lL&&(this.initDOM(),this.setAccessibilityAttributes(),this.scrollbarWidth=this.getScrollbarWidth(),this.recalculate(),this.initListeners())},t.initDOM=function(){var n=this;if(Array.prototype.filter.call(this.el.children,function(a){return a.classList.contains(n.classNames.wrapper)}).length)this.wrapperEl=this.el.querySelector("."+this.classNames.wrapper),this.contentWrapperEl=this.options.scrollableNode||this.el.querySelector("."+this.classNames.contentWrapper),this.contentEl=this.options.contentNode||this.el.querySelector("."+this.classNames.contentEl),this.offsetEl=this.el.querySelector("."+this.classNames.offset),this.maskEl=this.el.querySelector("."+this.classNames.mask),this.placeholderEl=this.findChild(this.wrapperEl,"."+this.classNames.placeholder),this.heightAutoObserverWrapperEl=this.el.querySelector("."+this.classNames.heightAutoObserverWrapperEl),this.heightAutoObserverEl=this.el.querySelector("."+this.classNames.heightAutoObserverEl),this.axis.x.track.el=this.findChild(this.el,"."+this.classNames.track+"."+this.classNames.horizontal),this.axis.y.track.el=this.findChild(this.el,"."+this.classNames.track+"."+this.classNames.vertical);else{for(this.wrapperEl=document.createElement("div"),this.contentWrapperEl=document.createElement("div"),this.offsetEl=document.createElement("div"),this.maskEl=document.createElement("div"),this.contentEl=document.createElement("div"),this.placeholderEl=document.createElement("div"),this.heightAutoObserverWrapperEl=document.createElement("div"),this.heightAutoObserverEl=document.createElement("div"),this.wrapperEl.classList.add(this.classNames.wrapper),this.contentWrapperEl.classList.add(this.classNames.contentWrapper),this.offsetEl.classList.add(this.classNames.offset),this.maskEl.classList.add(this.classNames.mask),this.contentEl.classList.add(this.classNames.contentEl),this.placeholderEl.classList.add(this.classNames.placeholder),this.heightAutoObserverWrapperEl.classList.add(this.classNames.heightAutoObserverWrapperEl),this.heightAutoObserverEl.classList.add(this.classNames.heightAutoObserverEl);this.el.firstChild;)this.contentEl.appendChild(this.el.firstChild);this.contentWrapperEl.appendChild(this.contentEl),this.offsetEl.appendChild(this.contentWrapperEl),this.maskEl.appendChild(this.offsetEl),this.heightAutoObserverWrapperEl.appendChild(this.heightAutoObserverEl),this.wrapperEl.appendChild(this.heightAutoObserverWrapperEl),this.wrapperEl.appendChild(this.maskEl),this.wrapperEl.appendChild(this.placeholderEl),this.el.appendChild(this.wrapperEl)}if(!this.axis.x.track.el||!this.axis.y.track.el){var i=document.createElement("div"),o=document.createElement("div");i.classList.add(this.classNames.track),o.classList.add(this.classNames.scrollbar),i.appendChild(o),this.axis.x.track.el=i.cloneNode(!0),this.axis.x.track.el.classList.add(this.classNames.horizontal),this.axis.y.track.el=i.cloneNode(!0),this.axis.y.track.el.classList.add(this.classNames.vertical),this.el.appendChild(this.axis.x.track.el),this.el.appendChild(this.axis.y.track.el)}this.axis.x.scrollbar.el=this.axis.x.track.el.querySelector("."+this.classNames.scrollbar),this.axis.y.scrollbar.el=this.axis.y.track.el.querySelector("."+this.classNames.scrollbar),this.options.autoHide||(this.axis.x.scrollbar.el.classList.add(this.classNames.visible),this.axis.y.scrollbar.el.classList.add(this.classNames.visible)),this.el.setAttribute("data-simplebar","init")},t.setAccessibilityAttributes=function(){var n=this.options.ariaLabel||"scrollable content";this.contentWrapperEl.setAttribute("tabindex","0"),this.contentWrapperEl.setAttribute("role","region"),this.contentWrapperEl.setAttribute("aria-label",n)},t.initListeners=function(){var n=this,i=Wi(this.el);this.options.autoHide&&this.el.addEventListener("mouseenter",this.onMouseEnter),["mousedown","click","dblclick"].forEach(function(c){n.el.addEventListener(c,n.onPointerEvent,!0)}),["touchstart","touchend","touchmove"].forEach(function(c){n.el.addEventListener(c,n.onPointerEvent,{capture:!0,passive:!0})}),this.el.addEventListener("mousemove",this.onMouseMove),this.el.addEventListener("mouseleave",this.onMouseLeave),this.contentWrapperEl.addEventListener("scroll",this.onScroll),i.addEventListener("resize",this.onWindowResize);var o=!1,a=null,s=i.ResizeObserver||jle;this.resizeObserver=new s(function(){!o||a!==null||(a=i.requestAnimationFrame(function(){n.recalculate(),a=null}))}),this.resizeObserver.observe(this.el),this.resizeObserver.observe(this.contentEl),i.requestAnimationFrame(function(){o=!0}),this.mutationObserver=new i.MutationObserver(this.recalculate),this.mutationObserver.observe(this.contentEl,{childList:!0,subtree:!0,characterData:!0})},t.recalculate=function(){var n=Wi(this.el);this.elStyles=n.getComputedStyle(this.el),this.isRtl=this.elStyles.direction==="rtl";var i=this.heightAutoObserverEl.offsetHeight<=1,o=this.heightAutoObserverEl.offsetWidth<=1,a=this.contentEl.offsetWidth,s=this.contentWrapperEl.offsetWidth,c=this.elStyles.overflowX,d=this.elStyles.overflowY;this.contentEl.style.padding=this.elStyles.paddingTop+" "+this.elStyles.paddingRight+" "+this.elStyles.paddingBottom+" "+this.elStyles.paddingLeft,this.wrapperEl.style.margin="-"+this.elStyles.paddingTop+" -"+this.elStyles.paddingRight+" -"+this.elStyles.paddingBottom+" -"+this.elStyles.paddingLeft;var u=this.contentEl.scrollHeight,h=this.contentEl.scrollWidth;this.contentWrapperEl.style.height=i?"auto":"100%",this.placeholderEl.style.width=o?a+"px":"auto",this.placeholderEl.style.height=u+"px";var p=this.contentWrapperEl.offsetHeight;this.axis.x.isOverflowing=h>a,this.axis.y.isOverflowing=u>p,this.axis.x.isOverflowing=c==="hidden"?!1:this.axis.x.isOverflowing,this.axis.y.isOverflowing=d==="hidden"?!1:this.axis.y.isOverflowing,this.axis.x.forceVisible=this.options.forceVisible==="x"||this.options.forceVisible===!0,this.axis.y.forceVisible=this.options.forceVisible==="y"||this.options.forceVisible===!0,this.hideNativeScrollbar();var v=this.axis.x.isOverflowing?this.scrollbarWidth:0,x=this.axis.y.isOverflowing?this.scrollbarWidth:0;this.axis.x.isOverflowing=this.axis.x.isOverflowing&&h>s-x,this.axis.y.isOverflowing=this.axis.y.isOverflowing&&u>p-v,this.axis.x.scrollbar.size=this.getScrollbarSize("x"),this.axis.y.scrollbar.size=this.getScrollbarSize("y"),this.axis.x.scrollbar.el.style.width=this.axis.x.scrollbar.size+"px",this.axis.y.scrollbar.el.style.height=this.axis.y.scrollbar.size+"px",this.positionScrollbar("x"),this.positionScrollbar("y"),this.toggleTrackVisibility("x"),this.toggleTrackVisibility("y")},t.getScrollbarSize=function(n){if(n===void 0&&(n="y"),!this.axis[n].isOverflowing)return 0;var i=this.contentEl[this.axis[n].scrollSizeAttr],o=this.axis[n].track.el[this.axis[n].offsetSizeAttr],a,s=o/i;return a=Math.max(~~(s*o),this.options.scrollbarMinSize),this.options.scrollbarMaxSize&&(a=Math.min(a,this.options.scrollbarMaxSize)),a},t.positionScrollbar=function(n){if(n===void 0&&(n="y"),!!this.axis[n].isOverflowing){var i=this.contentWrapperEl[this.axis[n].scrollSizeAttr],o=this.axis[n].track.el[this.axis[n].offsetSizeAttr],a=parseInt(this.elStyles[this.axis[n].sizeAttr],10),s=this.axis[n].scrollbar,c=this.contentWrapperEl[this.axis[n].scrollOffsetAttr];c=n==="x"&&this.isRtl&&e.getRtlHelpers().isRtlScrollingInverted?-c:c;var d=c/(i-a),u=~~((o-s.size)*d);u=n==="x"&&this.isRtl&&e.getRtlHelpers().isRtlScrollbarInverted?u+(o-s.size):u,s.el.style.transform=n==="x"?"translate3d("+u+"px, 0, 0)":"translate3d(0, "+u+"px, 0)"}},t.toggleTrackVisibility=function(n){n===void 0&&(n="y");var i=this.axis[n].track.el,o=this.axis[n].scrollbar.el;this.axis[n].isOverflowing||this.axis[n].forceVisible?(i.style.visibility="visible",this.contentWrapperEl.style[this.axis[n].overflowAttr]="scroll"):(i.style.visibility="hidden",this.contentWrapperEl.style[this.axis[n].overflowAttr]="hidden"),this.axis[n].isOverflowing?o.style.display="block":o.style.display="none"},t.hideNativeScrollbar=function(){this.offsetEl.style[this.isRtl?"left":"right"]=this.axis.y.isOverflowing||this.axis.y.forceVisible?"-"+this.scrollbarWidth+"px":0,this.offsetEl.style.bottom=this.axis.x.isOverflowing||this.axis.x.forceVisible?"-"+this.scrollbarWidth+"px":0},t.onMouseMoveForAxis=function(n){n===void 0&&(n="y"),this.axis[n].track.rect=this.axis[n].track.el.getBoundingClientRect(),this.axis[n].scrollbar.rect=this.axis[n].scrollbar.el.getBoundingClientRect();var i=this.isWithinBounds(this.axis[n].scrollbar.rect);i?this.axis[n].scrollbar.el.classList.add(this.classNames.hover):this.axis[n].scrollbar.el.classList.remove(this.classNames.hover),this.isWithinBounds(this.axis[n].track.rect)?(this.showScrollbar(n),this.axis[n].track.el.classList.add(this.classNames.hover)):this.axis[n].track.el.classList.remove(this.classNames.hover)},t.onMouseLeaveForAxis=function(n){n===void 0&&(n="y"),this.axis[n].track.el.classList.remove(this.classNames.hover),this.axis[n].scrollbar.el.classList.remove(this.classNames.hover)},t.showScrollbar=function(n){n===void 0&&(n="y");var i=this.axis[n].scrollbar.el;this.axis[n].isVisible||(i.classList.add(this.classNames.visible),this.axis[n].isVisible=!0),this.options.autoHide&&this.hideScrollbars()},t.onDragStart=function(n,i){i===void 0&&(i="y");var o=Nu(this.el),a=Wi(this.el),s=this.axis[i].scrollbar,c=i==="y"?n.pageY:n.pageX;this.axis[i].dragOffset=c-s.rect[this.axis[i].offsetAttr],this.draggedAxis=i,this.el.classList.add(this.classNames.dragging),o.addEventListener("mousemove",this.drag,!0),o.addEventListener("mouseup",this.onEndDrag,!0),this.removePreventClickId===null?(o.addEventListener("click",this.preventClick,!0),o.addEventListener("dblclick",this.preventClick,!0)):(a.clearTimeout(this.removePreventClickId),this.removePreventClickId=null)},t.onTrackClick=function(n,i){var o=this;if(i===void 0&&(i="y"),!!this.options.clickOnTrack){var a=Wi(this.el);this.axis[i].scrollbar.rect=this.axis[i].scrollbar.el.getBoundingClientRect();var s=this.axis[i].scrollbar,c=s.rect[this.axis[i].offsetAttr],d=parseInt(this.elStyles[this.axis[i].sizeAttr],10),u=this.contentWrapperEl[this.axis[i].scrollOffsetAttr],h=i==="y"?this.mouseY-c:this.mouseX-c,p=h<0?-1:1,v=p===-1?u-d:u+d,x=function g(){if(p===-1){if(u>v){var m;u-=o.options.clickOnTrackSpeed,o.contentWrapperEl.scrollTo((m={},m[o.axis[i].offsetAttr]=u,m)),a.requestAnimationFrame(g)}}else if(u<v){var w;u+=o.options.clickOnTrackSpeed,o.contentWrapperEl.scrollTo((w={},w[o.axis[i].offsetAttr]=u,w)),a.requestAnimationFrame(g)}};x()}},t.getContentElement=function(){return this.contentEl},t.getScrollElement=function(){return this.contentWrapperEl},t.getScrollbarWidth=function(){try{return getComputedStyle(this.contentWrapperEl,"::-webkit-scrollbar").display==="none"||"scrollbarWidth"in document.documentElement.style||"-ms-overflow-style"in document.documentElement.style?0:FD(this.el)}catch{return FD(this.el)}},t.removeListeners=function(){var n=this,i=Wi(this.el);this.options.autoHide&&this.el.removeEventListener("mouseenter",this.onMouseEnter),["mousedown","click","dblclick"].forEach(function(o){n.el.removeEventListener(o,n.onPointerEvent,!0)}),["touchstart","touchend","touchmove"].forEach(function(o){n.el.removeEventListener(o,n.onPointerEvent,{capture:!0,passive:!0})}),this.el.removeEventListener("mousemove",this.onMouseMove),this.el.removeEventListener("mouseleave",this.onMouseLeave),this.contentWrapperEl&&this.contentWrapperEl.removeEventListener("scroll",this.onScroll),i.removeEventListener("resize",this.onWindowResize),this.mutationObserver&&this.mutationObserver.disconnect(),this.resizeObserver&&this.resizeObserver.disconnect(),this.recalculate.cancel(),this.onMouseMove.cancel(),this.hideScrollbars.cancel(),this.onWindowResize.cancel()},t.unMount=function(){this.removeListeners(),e.instances.delete(this.el)},t.isWithinBounds=function(n){return this.mouseX>=n.left&&this.mouseX<=n.left+n.width&&this.mouseY>=n.top&&this.mouseY<=n.top+n.height},t.findChild=function(n,i){var o=n.matches||n.webkitMatchesSelector||n.mozMatchesSelector||n.msMatchesSelector;return Array.prototype.filter.call(n.children,function(a){return o.call(a,i)})[0]},e})();ud.defaultOptions={autoHide:!0,forceVisible:!1,clickOnTrack:!0,clickOnTrackSpeed:40,classNames:{contentEl:"simplebar-content",contentWrapper:"simplebar-content-wrapper",offset:"simplebar-offset",mask:"simplebar-mask",wrapper:"simplebar-wrapper",placeholder:"simplebar-placeholder",scrollbar:"simplebar-scrollbar",track:"simplebar-track",heightAutoObserverWrapperEl:"simplebar-height-auto-observer-wrapper",heightAutoObserverEl:"simplebar-height-auto-observer",visible:"simplebar-visible",horizontal:"simplebar-horizontal",vertical:"simplebar-vertical",hover:"simplebar-hover",dragging:"simplebar-dragging"},scrollbarMinSize:25,scrollbarMaxSize:0,timeout:1e3};ud.instances=new WeakMap;function $D(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),r.push.apply(r,n)}return r}function du(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?$D(Object(r),!0).forEach(function(n){ece(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):$D(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}function ece(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function dd(){return dd=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},dd.apply(this,arguments)}function tce(e,t){if(e==null)return{};var r={},n=Object.keys(e),i,o;for(o=0;o<n.length;o++)i=n[o],!(t.indexOf(i)>=0)&&(r[i]=e[i]);return r}function rce(e,t){if(e==null)return{};var r=tce(e,t),n,i;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(i=0;i<o.length;i++)n=o[i],!(t.indexOf(n)>=0)&&Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var nce=["children","scrollableNodeProps","tag"],ice=function(t){var r=Array.prototype.reduce.call(t,function(n,i){var o=i.name.match(/data-simplebar-(.+)/);if(o){var a=o[1].replace(/\W+(.)/g,function(s,c){return c.toUpperCase()});switch(i.value){case"true":n[a]=!0;break;case"false":n[a]=!1;break;case void 0:n[a]=!0;break;default:n[a]=i.value}}return n},{});return r},hf=O.forwardRef(function(e,t){var r=e.children,n=e.scrollableNodeProps,i=n===void 0?{}:n,o=e.tag,a=o===void 0?"div":o,s=rce(e,nce),c=a,d,u=O.useRef(),h=O.useRef(),p=O.useRef(),v={},x={},g=[];return Object.keys(s).forEach(function(m){Object.prototype.hasOwnProperty.call(ud.defaultOptions,m)?v[m]=s[m]:m.match(/data-simplebar-(.+)/)&&m!=="data-simplebar-direction"?g.push({name:m,value:s[m]}):x[m]=s[m]}),g.length&&console.warn(`simplebar-react: this way of passing options is deprecated. Pass it like normal props instead:
117
117
  'data-simplebar-auto-hide="false"' —> 'autoHide="false"'
118
118
  `),O.useEffect(function(){return u=i.ref||u,h.current&&(d=new ud(h.current,du(du(du(du({},ice(g)),v),u&&{scrollableNode:u.current}),p.current&&{contentNode:p.current})),typeof t=="function"?t(d):t&&(t.current=d)),function(){d.unMount(),d=null,typeof t=="function"&&t(null)}},[]),O.createElement(c,dd({ref:h,"data-simplebar":!0},x),O.createElement("div",{className:"simplebar-wrapper"},O.createElement("div",{className:"simplebar-height-auto-observer-wrapper"},O.createElement("div",{className:"simplebar-height-auto-observer"})),O.createElement("div",{className:"simplebar-mask"},O.createElement("div",{className:"simplebar-offset"},typeof r=="function"?r({scrollableNodeRef:u,contentNodeRef:p}):O.createElement("div",dd({},i,{className:"simplebar-content-wrapper".concat(i.className?" ".concat(i.className):"")}),O.createElement("div",{className:"simplebar-content"},r)))),O.createElement("div",{className:"simplebar-placeholder"})),O.createElement("div",{className:"simplebar-track simplebar-horizontal"},O.createElement("div",{className:"simplebar-scrollbar"})),O.createElement("div",{className:"simplebar-track simplebar-vertical"},O.createElement("div",{className:"simplebar-scrollbar"})))});hf.displayName="SimpleBar";hf.propTypes={children:Fs.oneOfType([Fs.node,Fs.func]),scrollableNodeProps:Fs.object,tag:Fs.string};const vL=e=>{switch(e){case pe.EPermissionType.DATACLASS:return C.jsx(Pu,{className:"h-6 w-6"});case pe.EPermissionType.SINGLETON:return C.jsx(fj,{className:"h-6 w-6"});case pe.EPermissionType.DATASTORE:return C.jsx(lj,{className:"h-6 w-6"});case pe.EPermissionType.ATTRIBUTE:return C.jsx(hj,{className:"h-6 w-6"});case pe.EPermissionType.METHOD:return C.jsx(tj,{className:"h-6 w-6"});case pe.EPermissionType.SINGLETON_METHOD:return C.jsx(sj,{className:"h-6 w-6"});case pe.ESubPermissionType.ENTITY_SEL_METHOD:return C.jsx(aj,{className:"h-6 w-6"});case pe.ESubPermissionType.ENTITY_METHOD:return C.jsx(oj,{className:"h-6 w-6"});case pe.ESubPermissionType.DS_METHOD:return C.jsx(ij,{className:"h-6 w-6"});case pe.ESubPermissionType.DATACLASS_METHOD:return C.jsx(nj,{className:"h-6 w-6"});default:return C.jsx(Pu,{className:"h-6 w-6"})}},VD=({children:e})=>C.jsx("div",{className:"h-full w-full",children:C.jsx("div",{className:"flex h-full w-full flex-1 items-center justify-center",children:C.jsxs("div",{className:"flex flex-col items-center justify-center gap-y-4 py-4 text-inactive-text",children:[C.jsx(on,{className:"h-10 w-10"}),C.jsx("div",{className:"text-center text-sm",children:e})]})})}),fa=({permissions:e,label:t,onToggle:r,onSelect:n,promoted:i,privileges:o,exists:a,optimisticChecked:s})=>{const c=e.find(u=>u.name===t);if(!c)return null;const d=s!==void 0?s:c.checked;return C.jsxs("div",{className:"relative mx-auto flex w-fit items-center",children:[C.jsx(ir,{value:d||c.from.length===0||t==="promote"?d:null,onChange:()=>r&&r(c),isInvalid:a===!1}),C.jsxs("div",{className:"absolute left-full translate-x-1/4 inset-y-0 flex cursor-pointer items-center gap-x-1",children:[t!=="promote"&&(c.checked&&(c.info||c.from.length>0)||!c.checked&&c.from.length>0)&&C.jsx(C.Fragment,{children:C.jsx(Lr,{container:Br(),delay:100,label:C.jsxs("div",{className:"max-w-xs h-fit flex flex-col gap-y-3 p-1.5 text-sm font-semibold",children:[c.from.length?C.jsxs("div",{className:"flex items-start",children:[C.jsx(wi,{className:"mr-2 mt-0.5 h-4 w-4 shrink-0"}),C.jsxs("p",{className:"flex flex-col gap-y-2",children:[C.jsx("span",{className:"mr-1",children:"Permission inherited from:"}),C.jsx("ul",{children:c.from.map(u=>{var h;return C.jsx("li",{className:"cursor-pointer list-disc font-bold hover:underline",onClick:()=>{var p;return n((p=o[u])==null?void 0:p.id)},children:(h=o[u])==null?void 0:h.privilege})})})]})]}):null,c.info&&C.jsxs("div",{className:"flex items-start",children:[C.jsx(Ew,{className:"mr-2 mt-0.5 h-4 w-4 shrink-0"})," ",C.jsx("span",{className:"flex-1 min-w-0 wrap-break-word whitespace-normal text-left",children:c.info})]})]}),children:C.jsx(on,{className:"h-4 w-4 "})})}),(c.checked||c.from.length>0)&&["execute"].includes(t)&&!!(i!=null&&i.length)&&C.jsx(Lr,{container:Br(),delay:100,label:C.jsx("div",{className:"space-y-1 p-1",children:C.jsxs("div",{className:"flex items-start text-s",children:[C.jsx(Ew,{className:"mr-2 mt-0.5 h-4 w-4 shrink-0"}),C.jsxs("p",{children:[C.jsx("span",{className:"mr-1",children:"Function is promoted with: "}),i==null?void 0:i.map(u=>{var h;return C.jsx("li",{className:"cursor-pointer list-disc font-bold hover:underline",onClick:()=>{var p;return n((p=o[u])==null?void 0:p.id)},children:(h=o[u])==null?void 0:h.privilege})})]})]})}),children:C.jsx(xV,{className:"h-3 w-3 "})})]})]})},oce=({privilegeId:e,privileges:t})=>{const r=yr(),n=r.getCatalogMethods(),i=r.getDataclasses(),o=r.getSingletons(),[a,s]=O.useState([]),[c,d]=O.useState("");O.useEffect(()=>{d("")},[e]),O.useEffect(()=>{const p=pe.getInheritedResources(e,t).map(({resource:x,type:g,subType:m})=>({applyTo:x,type:g,subType:m})),v=KS(c.toLowerCase(),n,Object.values(i),Object.values(o));s(v.filter(({applyTo:x,type:g,subType:m})=>!Xi.find(p,{applyTo:x,type:g,subType:m})))},[c,e,t,n,i,o]);const[u,h]=O.useState(!1);return C.jsx(Kh.Root,{className:"w-56",onInputChange:p=>d(p||""),onOpenChange:h,isOpen:u,isSearchable:!0,options:a,getOptionLabel:p=>p?p.applyTo:"",getOptionValue:p=>p?p.applyTo:"",value:null,clearSearchOnSelect:!0,closeMenuOnSelect:!1,onChange:p=>{if(!p)return;const v=pe.addPermission(e,p,t);r.actions.updatePrivileges(v),d("")},children:C.jsx(Kh.Group,{children:C.jsx(Kh.Field,{controlShouldRenderValue:!0,renderOption:({data:p})=>C.jsxs("div",{className:"flex items-center gap-x-2",children:[vL(p.type),C.jsx("span",{children:p.applyTo})]}),placeholder:"Create a permission",hideNoOptions:!0})})})};function ace(e){const t=["datastore","singleton","dataclass","attribute","dsMethod","dataclassMethod","entityMethod","entityselMethod","singletonMethod"],r=e.reduce((n,i)=>{const[o]=i.resource.split("."),a=n.find(s=>s.prefix===o.toLowerCase());return a?(a.resources.push(i),n):[...n,{prefix:o.toLowerCase(),type:i.type,resources:[i]}]},[]);return r.sort((n,i)=>n.prefix==="ds"?-1:i.prefix==="ds"||n.prefix>i.prefix?1:-1),r.map(n=>({...n,resources:n.resources.sort((i,o)=>{const a=t.indexOf(i.type),s=t.indexOf(o.type);return a!==s?a-s:i.resource.toLowerCase()>o.resource.toLowerCase()?1:-1})})).reduce((n,i)=>[...n,...i.resources],[])}const bo={datastore:["datastore"],dataclass:["dataclass"],singleton:["singleton"],functions:["method","singletonMethod","dsMethod","dataclassMethod","entityMethod","entityselMethod"],attribute:["attribute"]},HD=Object.values(bo).flat();function ha(e,t){return t.length>0&&t.every(r=>e.includes(r))}function sce(e,t){return t.some(r=>e.includes(r))}function lce(e,t){return Array.from(new Set([...e,...t]))}function cce(e,t){return e.filter(r=>!t.includes(r))}const uce=({selectedPrivilege:e,onSelect:t,showIncluded:r,privileges:n,rawPrivileges:i})=>{var ne,ve;const[o,a]=O.useState(null),[s,c]=O.useState(null),{styles:d,attributes:u}=Nd(o,s,{modifiers:[{name:"offset",options:{offset:[0,10]}}]}),h=yr(),[p,v]=O.useState([]),[x,g]=O.useState([]),[m,w]=O.useState(""),[y,_]=O.useState(""),[S,E]=O.useState({}),I=i??n;O.useEffect(()=>{const Z=setTimeout(()=>g(p),0);return()=>clearTimeout(Z)},[p]),O.useEffect(()=>{E({})},[I]);const{id:N}=e,T=O.useMemo(()=>pe.getInheritedResources(N,I),[N,(ne=I[N])==null?void 0:ne.includes,(ve=I[N])==null?void 0:ve.resources]),M=O.useMemo(()=>pe.getPromotions(N,I),[I[N]]),z=Z=>{v([...Z])},j=Z=>{v(J=>ha(J,Z)?cce(J,Z):lce(J,Z))},W=Z=>{j(bo[Z])},U=ha(p,HD),A=p.length>0&&!U,K=ha(p,bo.functions),V=!K&&sce(p,bo.functions),te=()=>z(HD),G=()=>z([]),re=async Z=>{if(h.getHost()==="vscode"){const ae=pe.removePermission(e.id,Z,n);h.actions.updatePrivileges(ae);return}const{confirmed:J}=await h.actions.openModal({title:"Delete Privilege",type:pe.ModalType.CONFIRM,color:pe.ModalColor.DANGER,message:"Are you sure you want to remove this Privilege?",icon:"FdWarningDanger"});if(J){const ae=pe.removePermission(e.id,Z,n);h.actions.updatePrivileges(ae)}},P=async()=>{const{confirmed:Z}=await h.actions.openModal({title:"Reset Permissions",type:pe.ModalType.CONFIRM,color:pe.ModalColor.DANGER,message:"Are you sure you want to reset permissions for this Privilege?",icon:"FdWarningDanger"});if(Z){const J=pe.resetResources(e.id,n);h.actions.updatePrivileges(J)}},B=O.useMemo(()=>x.length>0?T.filter(Z=>x.includes(Z.type)):T,[T,x]),X=O.useMemo(()=>B.filter(({resource:Z})=>y?new RegExp(Xi.escapeRegExp(y),"i").test(Z):!0),[B,y]),Q=O.useMemo(()=>ace(X),[X]),D=O.useMemo(()=>Q.filter(Z=>{const J=Z.permissions.every(ae=>!ae.checked)&&Z.permissions.some(ae=>ae.from.length>0);return r||!J}),[Q,r]),$=(Z,J)=>{const ae=`${Z.resource}|${Z.type}|${J.name}`;E(he=>({...he,[ae]:!J.checked})),setTimeout(()=>{const he=pe.togglePermission(e.id,Z,J,n);h.actions.updatePrivileges(he)},0)},H=O.useMemo(()=>D.some(Z=>Z.exists===!1),[D]),q=async()=>{const{confirmed:Z}=await h.actions.openModal({title:"Delete Privilege",type:pe.ModalType.CONFIRM,color:pe.ModalColor.DANGER,message:"Are you sure you want to remove these permissions?",views:{tips:[{type:"warning",message:"This action will remove all permissions that don't exist in the catalog for all privileges"}]},icon:"FdWarningDanger"}),J=Object.entries(I).map(([ae,he])=>{const ue=he.resources.filter(de=>!de.exists);return{[ae]:ue.map(de=>({applyTo:de.resource,type:de.type}))}}).reduce((ae,he)=>({...ae,...he}),{});if(Z){const ae=pe.removeMultiplePermissions(J,n);h.actions.updatePrivileges(ae)}},Y=O.useRef(null),ie=cd({count:D.length,getScrollElement:()=>{var Z;return((Z=Y.current)==null?void 0:Z.getScrollElement())??null},estimateSize:()=>36,overscan:5});return O.useEffect(()=>{var Z,J;(J=(Z=Y.current)==null?void 0:Z.getScrollElement())==null||J.scrollTo({top:0})},[N]),C.jsxs(hf,{ref:Y,className:"z-20 h-full flex-1 overflow-auto p-3.75 pt-0",style:{maxHeight:"calc(100vh - 5.5rem - 85px - 20px)"},children:[C.jsxs("table",{className:"relative h-full w-full border-collapse",children:[C.jsx("thead",{className:"sticky top-0 z-20 bg-panel-1",children:C.jsxs("tr",{className:"border-b border-panel-border-subtle",children:[C.jsx("td",{className:"py-2",children:C.jsxs("div",{className:"flex items-center gap-x-2",children:[C.jsx(wt.Root,{className:"relative w-56",children:C.jsxs(wt.Group,{children:[C.jsx(wt.Icon,{children:C.jsx(dj,{})}),C.jsx(wt.Field,{type:"text",placeholder:"Search available permissions",value:m,onChange:Z=>{const J=Z.target.value;w(J),setTimeout(()=>_(J),0)}}),C.jsx(wn.Popover,{className:"flex items-center",children:({open:Z})=>C.jsxs(C.Fragment,{children:[C.jsx(wn.Popover.Button,{ref:a,children:C.jsx(wt.Icon,{isAction:!0,children:C.jsx(JD,{})})}),Z&&C.jsx(ef,{children:C.jsx(wn.Popover.Panel,{ref:c,style:d.popper,...u.popper,className:"z-50",static:!0,children:C.jsxs(br,{depth:3,borderType:"light",className:"rounded-md border px-4 py-2.5",children:[C.jsxs("label",{className:"mb-2 flex cursor-pointer items-center gap-2",children:[C.jsx(ir,{size:"sm",value:A?null:U,onChange:()=>U?G():te()}),C.jsx("h5",{className:"text-sm font-semibold",children:"Filter"})]}),C.jsxs("div",{className:"space-y-2 text-s",children:[C.jsx("div",{className:"flex items-center",children:C.jsx(ir,{size:"sm",value:ha(p,bo.dataclass),onChange:()=>W("dataclass"),label:"Dataclass"})}),C.jsx("div",{className:"flex items-center",children:C.jsx(ir,{size:"sm",value:ha(p,bo.singleton),onChange:()=>W("singleton"),label:"Singleton"})}),C.jsx("div",{className:"flex items-center",children:C.jsx(ir,{size:"sm",value:V?null:K,onChange:()=>W("functions"),label:"Functions"})}),C.jsx("div",{className:"flex items-center",children:C.jsx(ir,{size:"sm",value:ha(p,bo.attribute),onChange:()=>W("attribute"),label:"Attribute"})})]})]})})})]})})]})}),C.jsx(oce,{privilegeId:N,privileges:I}),C.jsx("div",{children:C.jsx(Lr,{label:`Resetting the privilege will remove all configured
119
- ressources`,container:Br(),children:C.jsx(Jt,{color:"white",variant:"ghost",onClick:P,children:C.jsx(SV,{})})})}),C.jsx(Lr,{icon:C.jsx(wi,{}),label:"Delete all the non existing resources from privileges",container:Br(),children:C.jsx(Jt,{color:"white",variant:"ghost",onClick:q,disabled:!H,children:C.jsx(QD,{className:"h-4 w-4"})})})]})}),C.jsx("td",{className:"px-4 py-2 text-center text-[12px]",children:"Read"}),C.jsx("td",{className:"px-4 py-2 text-center text-[12px]",children:"Create"}),C.jsx("td",{className:"px-4 py-2 text-center text-[12px]",children:"Update"}),C.jsx("td",{className:"px-4 py-2 text-center text-[12px]",children:"Delete"}),C.jsx("td",{className:"px-4 py-2 text-center text-[12px]",children:"Execute"}),C.jsx("td",{className:"px-4 py-2 text-center text-[12px]",children:"Promote"})]})}),D.length?C.jsxs("tbody",{children:[ie.getVirtualItems().length>0?C.jsx("tr",{style:{height:`${ie.getVirtualItems()[0].start}px`},children:C.jsx("td",{colSpan:7})}):null,ie.getVirtualItems().map(Z=>{const J=D[Z.index],ae=J.permissions.some(he=>he.from.length>0);return C.jsxs("tr",{className:an("group even:bg-body/5 hover:bg-input-bg",{"opacity-60":J.exists===!1}),children:[C.jsxs("td",{className:an("group flex items-center gap-3 py-2 text-xs group-hover:rounded-l group-hover:bg-input-bg ",J.exists===!1?"text-negative-text":""),children:[vL(J.type),J.resource,C.jsx(Lr,{label:"Remove Permission",container:Br(),children:C.jsx(Jt,{color:"white",variant:"ghost",disabled:ae,onClick:()=>{ae?pe.toastSubject.next({kind:"info",markdown:!0,message:"**Info:** Inherited permissions can't be removed",customIcon:on}):re({applyTo:J.resource,type:J.type})},className:"opacity-0 group-hover:opacity-100",children:C.jsx(ja,{className:"h-4 w-4 rotate-45 transform"})})})]}),C.jsx("td",{className:"py-2 text-center group-hover:bg-input-bg ",children:C.jsx(fa,{permissions:J.permissions,showIncluded:r,label:"read",onToggle:he=>$(J,he),onSelect:t,privileges:n,exists:J.exists,optimisticChecked:S[`${J.resource}|${J.type}|read`]})}),C.jsx("td",{className:"py-2 text-center group-hover:bg-input-bg ",children:C.jsx(fa,{permissions:J.permissions,showIncluded:r,label:"create",onToggle:he=>$(J,he),onSelect:t,privileges:n,exists:J.exists,optimisticChecked:S[`${J.resource}|${J.type}|create`]})}),C.jsx("td",{className:"py-2 text-center group-hover:bg-input-bg ",children:C.jsx(fa,{permissions:J.permissions,showIncluded:r,label:"update",onToggle:he=>$(J,he),onSelect:t,privileges:n,exists:J.exists,optimisticChecked:S[`${J.resource}|${J.type}|update`]})}),C.jsx("td",{className:"py-2 text-center group-hover:bg-input-bg",children:C.jsx(fa,{permissions:J.permissions,showIncluded:r,label:"drop",onToggle:he=>$(J,he),onSelect:t,privileges:n,exists:J.exists,optimisticChecked:S[`${J.resource}|${J.type}|drop`]})}),C.jsx("td",{className:"py-2 text-center group-hover:bg-input-bg",children:C.jsx(fa,{promoted:M[J.resource],permissions:J.permissions,showIncluded:r,label:"execute",onToggle:he=>$(J,he),onSelect:t,privileges:n,exists:J.exists,optimisticChecked:S[`${J.resource}|${J.type}|execute`]})}),C.jsx("td",{className:"py-2 text-center group-hover:rounded-r group-hover:bg-input-bg",children:C.jsx(fa,{permissions:J.permissions,showIncluded:r,label:"promote",onToggle:he=>$(J,he),onSelect:t,privileges:n,exists:J.exists,optimisticChecked:S[`${J.resource}|${J.type}|promote`]})})]},`${J.resource}-${Z.index}`)}),(()=>{const Z=ie.getVirtualItems();if(!Z.length)return null;const J=ie.getTotalSize()-Z[Z.length-1].end;return J>0?C.jsx("tr",{style:{height:`${J}px`},children:C.jsx("td",{colSpan:7})}):null})()]}):null]}),!Q.length&&y?C.jsx(VD,{children:"The Permission you're looking for can't be found "}):null,!Q.length&&!y?C.jsxs(VD,{children:["This Privilege has no Permissions configured yet ",C.jsx("br",{}),'Add a new permission by using the "Create a permission" input above']}):null]})},dce=({onCreate:e})=>{const t=yr(),r=t.getPrivileges(),[n,i]=O.useState(null),[o,a]=O.useState(null),[s,c]=O.useState(""),[d,u]=O.useState(null),{styles:h,attributes:p}=Nd(n,o,{modifiers:[{name:"offset",options:{offset:[-10,10]}}],placement:"right-start"});O.useEffect(()=>{c(""),u(null)},[o]);const v=(x=()=>{})=>{u(null);try{const g=pe.createPrivilege(s,r),m=Object.values(g).find(w=>w.privilege===s);t.actions.updatePrivileges(g),m&&e(m),setTimeout(()=>{x()},0)}catch(g){u(g.message)}};return C.jsx(wn.Popover,{children:({open:x,close:g})=>C.jsxs(C.Fragment,{children:[C.jsx(wn.Popover.Button,{className:"rounded","data-cy":"New-priv-btn",as:"div",ref:i,children:C.jsx(Jt,{variant:"ghost",color:"white",children:C.jsx(ja,{className:"h-4 w-4"})})}),x&&C.jsx(ef,{children:C.jsx(wn.Popover.Panel,{ref:a,style:h.popper,...p.popper,"data-cy":"New-priv-pop-up",className:"z-50",static:!0,children:C.jsxs(br,{className:"min-w-[256px] border rounded px-4 py-2 text-xs shadow-md",depth:3,borderType:"light",children:[C.jsx("h5",{className:"mb-2 text-xs font-semibold",children:"Create New Privilege"}),C.jsx("div",{className:"mt-2",children:C.jsxs("label",{className:"flex items-center gap-x-4",children:[C.jsx("span",{children:"Name"}),C.jsx(wt.Root,{className:"w-full",color:d?"negative":"primary",children:C.jsxs(wt.Group,{children:[d&&C.jsx(wt.Message,{children:d}),C.jsx(wt.Field,{autoFocus:!0,value:s,onChange:m=>c(m.target.value),onKeyDown:m=>{m.key==="Enter"&&v()},type:"text"})]})})]})}),C.jsxs("div",{className:"mt-4 flex items-center justify-center gap-x-2",children:[C.jsx(Jt,{onClick:()=>v(g),children:"Create"}),C.jsx(Jt,{color:"white",variant:"outline",onClick:()=>g(),children:"Cancel"})]})]})})})]})})},fce=()=>{const e=yr(),t=e.getCatalog(),r=e.getPrivileges(),[n,i]=O.useState(r);O.useEffect(()=>{const g=setTimeout(()=>i(r),0);return()=>clearTimeout(g)},[r]);const o=O.useMemo(()=>{if(t===null)return n;const g=yz(n,Object.values((t==null?void 0:t.dataClasses)??{}));return xz(g,t)},[n,t]),[a,s]=O.useState(null),[c,d]=O.useState(null),u=O.useCallback(g=>{s(g),e.actions.selectPrivilege((g==null?void 0:g.id)??null)},[e]),h=g=>{u(g),setTimeout(()=>d(g),0)},p=O.useMemo(()=>Object.keys(o),[o]);O.useEffect(()=>{if(a&&o[a.id]||!p.length)return;const g=e.getSelectedPrivilege(),m=g&&o[g]||o[p[0]];u(m),d(m)},[o]),O.useEffect(()=>{p.length<2&&x(!0)},[p.length]);const[v,x]=O.useState(!0);return C.jsxs("div",{className:"flex h-full min-h-0 min-w-0 flex-1",children:[C.jsxs(br,{depth:1,className:"flex h-full w-89 shrink-0 flex-col border-r",children:[C.jsxs("div",{className:"flex flex-shrink-0 items-center justify-between px-3.5 py-2.5",children:[C.jsxs("div",{className:"flex items-center gap-x-1",children:[C.jsx("span",{children:C.jsx(pd,{className:"h-3.5 w-3.5"})}),C.jsx("span",{className:"text-[11px] font-semibold",children:"Privileges"})]}),C.jsx(dce,{onCreate:g=>{u(g),d(g)}})]}),C.jsx(lse,{privileges:o,selectedPrivilege:a,selectPrivilege:h})]}),a&&o[a.id]?C.jsxs(br,{depth:1,className:"privileges-container relative flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden border-l-[0.5px]",children:[C.jsxs("div",{className:"mb-1 flex min-h-0 min-w-0 flex-1 h-full w-full flex-col items-stretch overflow-auto",children:[(c??a).privilege!=="guest"?C.jsx(Yae,{privileges:o,selectedPrivilege:c??a,onSelect:g=>u(r[g]),setShowIncluded:x,showIncluded:v}):null,C.jsx(uce,{privileges:o,rawPrivileges:r,selectedPrivilege:c??a,onSelect:g=>u(r[g]),showIncluded:v})]}),C.jsx("div",{className:"mt-auto flex-shrink-0",children:C.jsx(hce,{privileges:o,selectedPrivilege:c??a,setSelectedPrivilege:u})})]}):C.jsx(i6,{tab:"Privilege"})]})},hce=({privileges:e,selectedPrivilege:t,setSelectedPrivilege:r})=>{const[n,i]=O.useState(!1);return C.jsx(pe.Panel,{path:pe.ROLES_TAB_PATH,isOpen:n,onOpen:()=>i(!0),onClose:()=>i(!1),children:C.jsx("div",{className:"flex h-full w-full min-h-0 px-3 pb-3",children:C.jsx(br,{depth:2,className:"h-full w-full overflow-hidden rounded",children:C.jsx(Hae,{dict:e,data:pe.getGraphData(t.id,e),onSelect:o=>r(e[o])})})})})},pce=O.memo(({role:e})=>{var E;const t=yr(),[r,n]=O.useState(e),[i,o]=O.useState(e.role),[a,s]=O.useState(null),c=t.getPrivileges(),d=((E=r.privileges)==null?void 0:E.filter(I=>c[I]&&c[I].privilege!=="guest").length)||0,u=t.getRoles(),{selectedRole:h,selectRole:p}=dS(),[v,x]=O.useState(!1),g=pe.useOutsideClick(()=>{v&&w()});pe.useDidMountEffect(()=>{i!==e.role&&o(e.role)},[e.role]),O.useEffect(()=>{e.role||x(!0)},[]),O.useEffect(()=>{n(e)},[e]);const m=()=>{s(null),x(!0)},w=()=>{s(null),e.role&&e.role===i&&x(!1);try{const I=pe.saveRole({...r,role:i},u);t.actions.updateRoles(I),x(!1)}catch(I){s(I.message)}},y=async I=>{if(I.stopPropagation(),t.getHost()==="vscode"){_();return}const{confirmed:N}=await t.actions.openModal({title:"Delete Role",type:pe.ModalType.CONFIRM,color:pe.ModalColor.DANGER,message:"Are you sure you want to remove this Role?",icon:"FdWarningDanger"});N&&_()},_=()=>{const I=pe.removeRole(r.id,u),N=Object.keys(I);if(h!==r.id){t.actions.updateRoles(I);return}if(N.length===0)p(null);else{const T=Object.keys(u),M=T.indexOf(r.id),z=Math.max(0,M-1),j=T[z];M===0?p(N[0]):I[j]?p(j):p(N[0])}t.actions.updateRoles(I)},S=(I=null)=>{if(I&&I.stopPropagation(),!e.role){_();return}x(!1),o(e.role)};return C.jsx(C.Fragment,{children:C.jsxs(br,{depth:4,borderType:h===r.id?"primary":h!==r.id?"light":"default",className:an("rounded border p-2"),role:"button","data-cy":"privilegeCard",onClick:()=>{p(r.id)},ref:g,children:[C.jsx("div",{className:"flex items-center justify-between",children:C.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[C.jsx("span",{className:"mr-4",children:C.jsx(pd,{className:"h-6 w-6"})}),v?C.jsxs(wt.Root,{color:a?"negative":"primary",className:"flex-1 mr-2",children:[C.jsx(wt.Group,{className:"border-input-focus-border",children:C.jsx(wt.Field,{type:"text",value:i,onChange:({target:{value:I}})=>{o(I)},onKeyDown:I=>{I.key==="Enter"&&w(),I.key==="Escape"&&S()},placeholder:"role",autoComplete:"off",autoFocus:!0})}),a&&C.jsx(wt.Message,{children:a})]}):C.jsx("span",{className:"inline-block grow overflow-hidden truncate whitespace-nowrap text-xs font-bold",title:i,children:r.role}),C.jsx("div",{className:an("justify-between ml-auto flex w-fit shrink-0 items-center gap-x-2"),children:v?C.jsxs(C.Fragment,{children:[C.jsx(Jt,{color:"white",variant:"ghost",onClick:w,children:C.jsx(_V,{className:"h-4 w-4"})}),C.jsx(Jt,{color:"white",variant:"ghost",onClick:S,children:C.jsx(ej,{className:"h-4 w-4"})})]}):C.jsxs(C.Fragment,{children:[C.jsx(Jt,{color:"white",variant:"ghost",onClick:m,children:C.jsx(cj,{className:"h-4 w-4"})}),C.jsx(Jt,{color:"white",variant:"ghost",onClick:I=>y(I),children:C.jsx(pj,{className:"h-4 w-4"})})]})})]})}),C.jsxs("span",{className:an("ml-10.75 py-1 text-xs"),children:[d," Privilege",d>1?"s":""]})]})})}),gL=(e,t)=>e?t[e]:null,WD=(e,t,r)=>{const n=gL(e,r);return n?Object.values(r).reduce((i,o)=>o.id===e?n.privileges.includes(t)?{...i,[n.id]:{...n,privileges:n.privileges.filter(a=>a!==t)}}:{...i,[n.id]:{...n,privileges:[...n.privileges,t]}}:{...i,[o.id]:o},{}):r},vce=()=>{const e=yr(),t=e.getPrivileges(),r=e.getRoles(),{selectedRole:n}=dS(),i=gL(n,r),o=(c,d)=>d&&d.privileges.includes(c.id),a=O.useMemo(()=>Object.values(t).filter(c=>o(c,i)&&c.privilege!=="guest"),[t,i]),s=O.useMemo(()=>Object.values(t).filter(c=>!o(c,i)&&c.privilege!=="guest"),[t,i]);return C.jsxs(br,{depth:1,className:"w-full border-b p-4 ",children:[C.jsx("div",{className:"mb-4 flex items-center gap-x-5",children:C.jsx("h4",{className:"text-[13px] font-semibold ",children:"Privileges"})}),C.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[C.jsx(vu,{"data-cy":"item=>Permisions",className:"italic opacity-90",children:"guest"}),a.map((c,d)=>C.jsxs(vu,{"data-cy":"item=>Permisions",color:"primary",onClick:()=>{const u=WD(i.id,c.id,r);e.actions.updateRoles(u)},children:[c.privilege,C.jsx(Tu.FdPlus,{className:"rotate-45 transform"})]},d)),s.map((c,d)=>C.jsxs(vu,{"data-cy":"item=>Permisions",color:"dark",onClick:()=>{const u=WD(i.id,c.id,r);e.actions.updateRoles(u)},children:[c.privilege,C.jsx(Tu.FdPlus,{})]},d))]})]})},fd=(e,t,r,n=!1)=>{const i=e.applyTo,o=e.type===pe.EPermissionType.DATACLASS?"ds":i.split(".")[0],a={...t,...r},s=()=>({value:!n,inherited:!1,from:[],explicitly:!1}),c={read:s(),create:s(),update:s(),drop:s(),execute:s(),promote:s()},d=h=>{h.forEach(p=>{a[p]&&(a[p].resources.forEach(v=>{if(v.resource===i||v.resource===o){const x=fd(e,t,{[p]:a[p]},n);Object.values(v.permissions).forEach(g=>{c[g.name].explicitly||(!c[g.name].from.includes(a[p].privilege)&&g.checked&&c[g.name].from.push(a[p].privilege),c[g.name].inherited=c[g.name].inherited||x[g.name].value||x[g.name].inherited)})}}),a[p].includes.length>0&&d(a[p].includes))})};if(Object.values(r).forEach(h=>{h.resources.forEach(p=>{p.resource===i&&Object.values(p.permissions).forEach(v=>{v.checked&&(c[v.name].explicitly=!0,n&&(c[v.name].value=!0))})}),(h.includes.length>0||h.privilege==="guest")&&d(h.includes)}),Object.values(t).forEach(h=>{h.resources.forEach(p=>{p.resource===i&&(h.privilege==="guest"?Object.values(p.permissions).forEach(v=>{v.checked&&(c[v.name].explicitly=!0,n&&(c[v.name].value=!0))}):Object.values(p.permissions).forEach(v=>{!c[v.name].explicitly&&v.checked&&(n?c[v.name].value=!0:c[v.name].value=!1)}))})}),(n?Object.entries(c).some(([h,p])=>h!=="promote"&&!p.value&&!p.explicitly):Object.entries(c).some(([h,p])=>h!=="promote"&&p.value&&!p.explicitly))&&![pe.EPermissionType.DATASTORE,pe.EPermissionType.SINGLETON].includes(e.type)){const h={applyTo:o,type:e.type===pe.EPermissionType.DATACLASS?pe.EPermissionType.DATASTORE:e.type===pe.EPermissionType.SINGLETON_METHOD?pe.EPermissionType.SINGLETON:pe.EPermissionType.DATACLASS},p=fd(h,t,r,n),v=x=>{let g=c[x].value;return n?!c[x].value&&!c[x].explicitly&&(g=p[x].value):c[x].value&&!c[x].explicitly&&(g=p[x].value),{value:g,inherited:c[x].inherited||p[x].inherited,from:c[x].from.length>0?c[x].from:p[x].from,explicitly:c[x].explicitly}};return{read:v("read"),create:v("create"),update:v("update"),drop:v("drop"),execute:v("execute"),promote:v("promote")}}return{read:c.read,create:c.create,update:c.update,drop:c.drop,execute:c.execute,promote:c.promote}},gce=({children:e})=>C.jsx("div",{className:"h-full w-full",children:C.jsx("div",{className:"flex h-full w-full flex-1 items-center justify-center",children:C.jsxs("div",{className:"flex flex-col items-center justify-center gap-y-4 py-4 text-inactive-text",children:[C.jsx(on,{className:"absolute -right-full h-10 w-10 translate-x-1"}),C.jsx("div",{className:"text-center text-sm",children:e})]})})}),mce=e=>{switch(e){case"dataclass":return C.jsx(Pu,{className:"h-6 w-6"});case"singleton":return C.jsx(fj,{className:"h-6 w-6"});case"datastore":return C.jsx(lj,{className:"h-6 w-6"});case"attribute":return C.jsx(hj,{className:"h-6 w-6"});case"method":return C.jsx(tj,{className:"h-6 w-6"});case"singletonMethod":return C.jsx(sj,{className:"h-6 w-6"});case"entityselMethod":return C.jsx(aj,{className:"h-6 w-6"});case"entityMethod":return C.jsx(oj,{className:"h-6 w-6"});case"dsMethod":return C.jsx(ij,{className:"h-6 w-6"});case"dataclassMethod":return C.jsx(nj,{className:"h-6 w-6"});default:return C.jsx(Pu,{className:"h-6 w-6"})}},UD=({privileges:e,permission:t,hasChild:r,depth:n,isChild:i=!1,className:o,inSearch:a,toggleCollapse:s,collapsed:c,isRestrictedByDefault:d,toastMessageCallback:u,computedInherited:h})=>{const[p,v]=t.applyTo.split("."),x=O.useMemo(()=>h||fd(t,e.otherPrivs,e.rolePrivs,d),[h,e,t,d]);return C.jsxs("tr",{className:an("group even:bg-body/5 hover:bg-input-bg",o),children:[C.jsxs("td",{className:an("flex h-full w-full items-stretch gap-3 p-0 text-xs group-hover:rounded-l group-hover:bg-input-bg",{"px-1":a}),children:[Array(n).fill("").map((g,m)=>C.jsx("div",{className:an("ml-1.5 mr-1 w-0.5 bg-muted",{"mr-0.5":i})},m)),C.jsxs("div",{className:"flex items-center gap-3 py-2",children:[r&&C.jsx("button",{onClick:s,className:"w-3",children:c?C.jsx(uj,{className:"inline h-4 w-4"}):C.jsx(rj,{className:"inline h-4 w-4"})}),mce(t.type),a?t.applyTo:v||p]})]}),C.jsx("td",{className:"py-2 text-center group-hover:bg-input-bg",children:[pe.EPermissionType.ATTRIBUTE,pe.EPermissionType.DATASTORE,pe.EPermissionType.DATACLASS].includes(t.type)&&C.jsxs("div",{className:"relative mx-auto flex w-fit items-center justify-center gap-x-1",onClick:u,children:[C.jsx(ir,{value:x.read.value||x.read.inherited,isDisabled:!0}),C.jsx("div",{className:"absolute left-full top-1/2 flex -translate-y-1/2 translate-x-1/2 cursor-pointer items-center",children:!x.read.value&&x.read.inherited?C.jsx(Lr,{container:Br(),delay:100,label:C.jsx("div",{className:"space-y-1 p-1",children:x.read.from.length?C.jsxs("div",{className:"flex items-start",children:[C.jsx(wi,{className:"mr-2 mt-0.5 h-4 w-4 shrink-0"}),C.jsxs("p",{className:"flex flex-col gap-y-2",children:[C.jsx("span",{className:"mr-1",children:"Permission inherited from:"}),C.jsx("ul",{children:x.read.from.map((g,m)=>C.jsx("li",{className:"cursor-pointer list-disc font-bold",children:g},m))})]})]}):null}),children:C.jsx(on,{className:"h-4 w-4"})}):""})]})}),C.jsx("td",{className:"py-2 text-center group-hover:bg-input-bg",children:[pe.EPermissionType.ATTRIBUTE,pe.EPermissionType.DATASTORE,pe.EPermissionType.DATACLASS].includes(t.type)&&C.jsxs("div",{className:"relative mx-auto flex w-fit items-center justify-center gap-x-1",onClick:u,children:[C.jsx(ir,{value:x.create.value||x.create.inherited,isDisabled:!0}),C.jsx("div",{className:"absolute left-full top-1/2 flex -translate-y-1/2 translate-x-1/2 cursor-pointer items-center",children:!x.create.value&&x.create.inherited?C.jsx(Lr,{container:Br(),delay:100,label:C.jsx("div",{className:"space-y-1 p-1",children:x.read.from.length?C.jsxs("div",{className:"flex items-start",children:[C.jsx(wi,{className:"mr-2 mt-0.5 h-4 w-4 shrink-0"}),C.jsxs("p",{className:"flex flex-col gap-y-2",children:[C.jsx("span",{className:"mr-1",children:"Permission inherited from:"}),C.jsx("ul",{children:x.read.from.map((g,m)=>C.jsx("li",{className:"cursor-pointer list-disc font-bold",children:g},m))})]})]}):null}),children:C.jsx(on,{className:"h-4 w-4"})}):""})]})}),C.jsx("td",{className:"py-2 text-center group-hover:bg-input-bg",children:[pe.EPermissionType.ATTRIBUTE,pe.EPermissionType.DATASTORE,pe.EPermissionType.DATACLASS].includes(t.type)&&C.jsxs("div",{className:"relative mx-auto flex w-fit items-center justify-center gap-x-1",onClick:u,children:[C.jsx(ir,{value:x.update.value||x.update.inherited,isDisabled:!0}),C.jsx("div",{className:"absolute left-full top-1/2 flex -translate-y-1/2 translate-x-1/2 cursor-pointer items-center",children:!x.update.value&&x.update.inherited?C.jsx(Lr,{container:Br(),delay:100,label:C.jsx("div",{className:"space-y-1 p-1",children:x.update.from.length?C.jsxs("div",{className:"flex items-start",children:[C.jsx(wi,{className:"mr-2 mt-0.5 h-4 w-4 shrink-0"}),C.jsxs("p",{className:"flex flex-col gap-y-2",children:[C.jsx("span",{className:"mr-1",children:"Permission inherited from:"}),C.jsx("ul",{children:x.update.from.map((g,m)=>C.jsx("li",{className:"cursor-pointer list-disc font-bold",children:g},m))})]})]}):null}),children:C.jsx(on,{className:"h-4 w-4"})}):""})]})}),C.jsx("td",{className:"py-2 text-center group-hover:bg-input-bg",children:[pe.EPermissionType.ATTRIBUTE,pe.EPermissionType.DATASTORE,pe.EPermissionType.DATACLASS].includes(t.type)&&C.jsxs("div",{className:"relative mx-auto flex w-fit items-center justify-center gap-x-1",onClick:u,children:[C.jsx(ir,{value:x.drop.value||x.drop.inherited,isDisabled:!0}),C.jsx("div",{className:"absolute left-full top-1/2 flex -translate-y-1/2 translate-x-1/2 cursor-pointer items-center",children:!x.drop.value&&x.drop.inherited?C.jsx(Lr,{container:Br(),delay:100,label:C.jsx("div",{className:"space-y-1 p-1",children:x.drop.from.length?C.jsxs("div",{className:"flex items-start",children:[C.jsx(wi,{className:"mr-2 mt-0.5 h-4 w-4 shrink-0"}),C.jsxs("p",{className:"flex flex-col gap-y-2",children:[C.jsx("span",{className:"mr-1",children:"Permission inherited from:"}),C.jsx("ul",{children:x.drop.from.map((g,m)=>C.jsx("li",{className:"cursor-pointer list-disc font-bold",children:g},m))})]})]}):null}),children:C.jsx(on,{className:"h-4 w-4"})}):""})]})}),C.jsx("td",{className:"py-2 text-center group-hover:rounded-r group-hover:bg-input-bg",children:t.type!=="attribute"&&C.jsxs("div",{className:"relative mx-auto flex w-fit items-center justify-center gap-x-1",onClick:u,children:[C.jsx(ir,{value:x.execute.value||x.execute.inherited,isDisabled:!0}),C.jsx("div",{className:"absolute left-full top-1/2 flex -translate-y-1/2 translate-x-1/2 cursor-pointer items-center",children:!x.execute.value&&x.execute.inherited?C.jsx(Lr,{container:Br(),delay:100,label:C.jsx("div",{className:"space-y-1 p-1",children:x.execute.from.length?C.jsxs("div",{className:"flex items-start",children:[C.jsx(wi,{className:"mr-2 mt-0.5 h-4 w-4 shrink-0"}),C.jsxs("p",{className:"flex flex-col gap-y-2",children:[C.jsx("span",{className:"mr-1",children:"Permission inherited from:"}),C.jsx("ul",{children:x.execute.from.map((g,m)=>C.jsx("li",{className:"cursor-pointer list-disc font-bold",children:g},m))})]})]}):null}),children:C.jsx(on,{className:"h-4 w-4"})}):""})]})})]})};function GD(e,t,r){const n=[],i=(a,s,c)=>n.push({id:a,permission:s,depth:c,hasChild:!1,isChild:!1}),o=(a,s,c,d,u,h)=>{n.push({id:a,permission:s,depth:c,hasChild:!0,isChild:d,toggleId:a,isCollapsed:u}),u||h()};for(const a of Object.values(e)){o("ds-group",{applyTo:a.applyTo,type:a.type},0,!1,t,()=>{for(const s of a.methods)i(`dsm-${s.applyTo}`,s,1);for(const s of a.dataClasses){const c=`dc-${s.applyTo}`;o(c,{applyTo:s.applyTo,type:s.type},1,!0,r[c]??!1,()=>{for(const d of s.attributes)i(`dca-${d.applyTo}`,d,2);for(const d of s.methods)i(`dcm-${d.applyTo}`,d,2)})}});for(const s of a.singletons){const c=`sing-${s.applyTo}`;o(c,{applyTo:s.applyTo,type:s.type},0,!0,r[c]??!1,()=>{for(const d of s.attributes)i(`singa-${d.applyTo}`,d,1);for(const d of s.methods)i(`singm-${d.applyTo}`,d,1)})}}return n}const KD=["datastore","singleton","dataclass","attribute","dsMethod","dataclassMethod","entityMethod","entityselMethod","singletonMethod"],yo={datastore:["datastore"],dataclass:["dataclass"],singleton:["singleton"],functions:["method","singletonMethod","dsMethod","dataclassMethod","entityMethod","entityselMethod"],attribute:["attribute"]},YD=Object.values(yo).flat();function pa(e,t){return t.length>0&&t.every(r=>e.includes(r))}function bce(e,t){return Array.from(new Set([...e,...t]))}function yce(e,t){return e.filter(r=>!t.includes(r))}const xce=({selectedRole:e})=>{const[t,r]=O.useState(null),[n,i]=O.useState(null),{styles:o,attributes:a}=Nd(t,n,{modifiers:[{name:"offset",options:{offset:[0,10]}}]}),s=yr(),c=s.getRestrictedByDefault(),d=s.getPrivileges(),[u,h]=O.useState([]),[p,v]=O.useState([]),[x,g]=O.useState(""),[m,w]=O.useState("");O.useEffect(()=>{const J=setTimeout(()=>v(u),0);return()=>clearTimeout(J)},[u]);const y=s.getCatalogMethods(),_=s.getDataclasses(),S=s.getSingletons(),E=O.useMemo(()=>Uae(y,Object.values(_),Object.values(S)),[y,_,S]),I=O.useMemo(()=>!p.length&&!m?[]:[...KS(m,y,Object.values(_),Object.values(S))].filter(J=>p.length?p.includes(J.type):!0).sort((J,ae)=>{const he=KD.indexOf(J.type),ue=KD.indexOf(ae.type);return he!==ue?he-ue:J.applyTo.toLowerCase()>ae.applyTo.toLowerCase()?1:-1}),[m,p,y,_,S]),N=J=>h([...J]),T=J=>{h(ae=>pa(ae,J)?yce(ae,J):bce(ae,J))},M=J=>T(yo[J]),z=YD.every(J=>u.includes(J)),j=u.length>0&&!z,W=pa(u,yo.functions),U=()=>N(YD),A=()=>N([]),K=s.getRoles(),[V,te]=O.useState(K);O.useEffect(()=>{const J=setTimeout(()=>te(K),0);return()=>clearTimeout(J)},[K]);const G=O.useRef(null);O.useEffect(()=>{var J,ae;(ae=(J=G.current)==null?void 0:J.getScrollElement())==null||ae.scrollTo({top:0})},[e]);const re=cd({count:I.length,getScrollElement:()=>{var J;return((J=G.current)==null?void 0:J.getScrollElement())??null},estimateSize:()=>36,overscan:5,paddingEnd:40}),P=O.useMemo(()=>{const J=Object.values(d).find(le=>le.privilege==="guest"),ae=V[e],he=ae?Object.fromEntries(ae.privileges.map(le=>[le,d[le]]).filter(([,le])=>!!le)):{};if(c)return{rolePrivs:he,otherPrivs:J?{[J.id]:J}:{}};const ue=J?{[J.id]:{...J,active:!0}}:{},de=Object.fromEntries(Object.entries(d).filter(([le])=>le!==(J==null?void 0:J.id)&&!(ae!=null&&ae.privileges.includes(le))).map(([le,xe])=>[le,{...xe,active:!1}]));return{rolePrivs:he,otherPrivs:{...ue,...de}}},[d,V,e,c]),[B,X]=O.useState(!1),[Q,D]=O.useState({}),$=O.useMemo(()=>{const J=[];for(const ae of Object.values(E)){for(const he of ae.dataClasses)J.push(`dc-${he.applyTo}`);for(const he of ae.singletons)J.push(`sing-${he.applyTo}`)}return J},[E]),H=$.length>0&&$.every(J=>Q[J]===!0),q=O.useCallback(()=>{const J={};for(const ae of $)J[ae]=!0;D(J)},[$]),Y=O.useCallback(J=>{J==="ds-group"?X(ae=>!ae):D(ae=>({...ae,[J]:!ae[J]}))},[]),ie=O.useMemo(()=>{const J=new Map;for(const{permission:ae}of GD(E,!1,{}))J.set(`${ae.applyTo}|${ae.type}`,fd(ae,P.otherPrivs,P.rolePrivs,c));return J},[P,c,E]),ne=O.useMemo(()=>GD(E,B,Q),[E,B,Q]),ve=cd({count:ne.length,getScrollElement:()=>{var J;return((J=G.current)==null?void 0:J.getScrollElement())??null},estimateSize:()=>36,overscan:8,paddingEnd:15}),Z=O.useCallback(()=>{pe.toastSubject.next({kind:"info",markdown:!0,message:"**Info:** You can add or modify permissions only in the Privilege section.",customIcon:Ew})},[]);return C.jsxs(hf,{ref:G,className:"z-20 h-full flex-1 overflow-auto p-3.75 pt-0",style:{maxHeight:"calc(100vh - 5.5rem - 85px - 20px)"},children:[C.jsxs("table",{className:"relative h-full w-full border-collapse",children:[C.jsx("thead",{className:"sticky top-0 z-20 bg-panel-1",children:C.jsxs("tr",{className:"border-b border-grey-100",children:[C.jsx("td",{className:"py-2",children:C.jsxs("div",{className:"flex items-center gap-x-2",children:[C.jsx(Lr,{label:"Collapse All",position:"up",container:Br(),children:C.jsx(Jt,{color:"white",variant:"ghost",disabled:B&&H,onClick:()=>{H?(q(),X(!0)):q()},children:C.jsx(yV,{})})}),C.jsx(wt.Root,{className:"w-56",children:C.jsxs(wt.Group,{children:[C.jsx(wt.Icon,{children:C.jsx(dj,{})}),C.jsx(wt.Field,{type:"text",placeholder:"Search",value:x,onChange:J=>{const ae=J.target.value;g(ae),setTimeout(()=>w(ae),0)}}),C.jsx(wn.Popover,{className:"flex items-center",children:({open:J})=>C.jsxs(C.Fragment,{children:[C.jsx(wn.Popover.Button,{ref:r,children:C.jsx(wt.Icon,{isAction:!0,children:C.jsx(JD,{})})}),J&&C.jsx(ef,{children:C.jsx(wn.Popover.Panel,{ref:i,style:o.popper,...a.popper,className:"z-50",static:!0,children:C.jsxs(br,{depth:3,borderType:"light",className:"rounded-md border px-4 py-2.5 text-xs",children:[C.jsxs("label",{className:"mb-2 flex cursor-pointer items-center gap-2",children:[C.jsx(ir,{size:"sm",value:j?null:z,onChange:()=>z?A():U()}),C.jsx("h5",{className:"text-sm font-semibold",children:"Filter"})]}),C.jsxs("div",{className:"space-y-2 text-s",children:[C.jsx("div",{className:"flex items-center",children:C.jsx(ir,{size:"sm",value:pa(u,yo.datastore),onChange:()=>M("datastore"),label:"Datastore"})}),C.jsx("div",{className:"flex items-center",children:C.jsx(ir,{size:"sm",value:pa(u,yo.dataclass),onChange:()=>M("dataclass"),label:"Dataclass"})}),C.jsx("div",{className:"flex items-center",children:C.jsx(ir,{size:"sm",value:pa(u,yo.singleton),onChange:()=>M("singleton"),label:"Singleton"})}),C.jsx("div",{className:"flex items-center",children:C.jsx(ir,{size:"sm",value:W,onChange:()=>M("functions"),label:"Functions"})}),C.jsx("div",{className:"flex items-center",children:C.jsx(ir,{size:"sm",value:pa(u,yo.attribute),onChange:()=>M("attribute"),label:"Attribute"})})]})]})})})]})})]})})]})}),C.jsx("td",{className:"px-4 py-2 text-center text-[12px]",children:"read"}),C.jsx("td",{className:"px-4 py-2 text-center text-[12px]",children:"Create"}),C.jsx("td",{className:"px-4 py-2 text-center text-[12px]",children:"Update"}),C.jsx("td",{className:"px-4 py-2 text-center text-[12px]",children:"Delete"}),C.jsx("td",{className:"px-4 py-2 text-center text-[12px]",children:"Execute"})]})}),C.jsx("tbody",{className:"relative",children:p.length||m?C.jsxs(C.Fragment,{children:[re.getVirtualItems().length>0?C.jsx("tr",{style:{height:`${re.getVirtualItems()[0].start}px`},children:C.jsx("td",{colSpan:6})}):null,re.getVirtualItems().map(J=>{const ae=I[J.index];return C.jsx(UD,{privileges:P,permission:ae,depth:0,inSearch:!0,isRestrictedByDefault:c,allPrivileges:d,toastMessageCallback:Z,computedInherited:ie.get(`${ae.applyTo}|${ae.type}`)},`${ae.type}-${J.index}`)}),(()=>{const J=re.getVirtualItems();if(!J.length)return null;const ae=re.getTotalSize()-J[J.length-1].end;return ae>0?C.jsx("tr",{style:{height:`${ae}px`},children:C.jsx("td",{colSpan:6})}):null})()]}):C.jsxs(C.Fragment,{children:[ve.getVirtualItems().length>0?C.jsx("tr",{style:{height:`${ve.getVirtualItems()[0].start}px`},children:C.jsx("td",{colSpan:6})}):null,ve.getVirtualItems().map(J=>{const ae=ne[J.index];return C.jsx(UD,{privileges:P,permission:ae.permission,depth:ae.depth,hasChild:ae.hasChild,isChild:ae.isChild,collapsed:ae.isCollapsed,toggleCollapse:ae.toggleId?()=>Y(ae.toggleId):void 0,isRestrictedByDefault:c,allPrivileges:d,toastMessageCallback:Z,computedInherited:ie.get(`${ae.permission.applyTo}|${ae.permission.type}`)},ae.id)}),(()=>{const J=ve.getVirtualItems();if(!J.length)return null;const ae=ve.getTotalSize()-J[J.length-1].end;return ae>0?C.jsx("tr",{style:{height:`${ae}px`},children:C.jsx("td",{colSpan:6})}):null})()]})})]}),(m||p.length)&&!I.length?C.jsx(gce,{children:"The Permission you're looking for can't be found "}):null]})},wce=()=>C.jsx("div",{className:"flex flex-1 items-center justify-center",children:C.jsx("div",{className:"h-6 w-6 animate-spin rounded-full border-2 border-grey-200 border-t-primary-dark"})}),Sce=()=>{const e=yr(),t=e.getRoles(),[r,n]=O.useState(null),[i,o]=O.useState(null),[a,s]=O.useState(""),[c,d]=O.useState(null),{styles:u,attributes:h}=Nd(r,i,{modifiers:[{name:"offset",options:{offset:[-10,10]}}],placement:"right-start"});O.useEffect(()=>{s(""),d(null)},[i]);const p=()=>{if(!a)throw new Error("Please enter a valid name");if(Object.values(t).find(m=>m.role.toLowerCase()===a.toLowerCase()))throw new Error(`A role with the name ${a} already exists`);const x=U4.generate(),g=pe.createRole(x,a,t);e.actions.updateRoles(g)};return C.jsx(wn.Popover,{children:({open:v,close:x})=>{const g=()=>{d(null);try{pe.validateName(a),p(),x()}catch(m){d(m.message)}};return C.jsxs(C.Fragment,{children:[C.jsx(wn.Popover.Button,{className:"rounded","data-cy":"New-priv-btn",as:"div",ref:n,children:C.jsx(Jt,{variant:"ghost",color:"white",children:C.jsx(ja,{className:"h-4 w-4"})})}),v&&C.jsx(ef,{children:C.jsx(wn.Popover.Panel,{ref:o,style:u.popper,...h.popper,"data-cy":"New-priv-pop-up",className:"z-50",static:!0,children:C.jsxs(br,{className:"min-w-[256px] border rounded px-4 py-2 text-xs shadow-md",depth:3,borderType:"light",children:[C.jsx("h5",{className:"mb-2 text-xs font-semibold",children:"Create New Role"}),C.jsx("div",{className:"mt-2",children:C.jsxs("label",{className:"flex items-center gap-x-4",children:[C.jsx("span",{children:"Name"}),C.jsx(wt.Root,{color:c?"negative":"primary",className:"w-full",children:C.jsxs(wt.Group,{children:[c&&C.jsx(wt.Message,{children:c}),C.jsx(wt.Field,{autoFocus:!0,value:a,onChange:m=>s(m.target.value),onKeyDown:m=>{m.key==="Enter"&&g()},type:"text"})]})})]})}),C.jsxs("div",{className:"mt-4 flex items-center justify-center gap-x-2",children:[C.jsx(Jt,{onClick:()=>{g()},children:"Create"}),C.jsx(Jt,{color:"white",variant:"outline",onClick:()=>x(),children:"Cancel"})]})]})})})]})}})},Ece=()=>{const e=yr(),t=e.getRoles(),r=e.getPrivileges(),{selectedRole:n,deferredSelectedRole:i}=dS(),o=O.useMemo(()=>Object.values(t).sort((a,s)=>pe.localeCompare(a.role,s.role)),[t]);return C.jsxs("div",{className:"flex flex-1 h-full",children:[C.jsxs(br,{depth:1,className:"flex h-full w-89 flex-col border-r",children:[C.jsxs("div",{className:"flex shrink-0 items-center justify-between px-3.5 py-2.5",children:[C.jsxs("div",{className:"flex items-center gap-x-1",children:[C.jsx("span",{children:C.jsx(pd,{className:"h-3.5 w-3.5"})}),C.jsx("span",{className:"text-[11px] font-semibold",children:"Roles"})]}),C.jsx(Sce,{})]}),C.jsx("div",{className:"flex-1 overflow-auto p-4 pb-10 pt-1",children:o.length>0?C.jsx("div",{className:"flex flex-col gap-4",children:o.map(a=>C.jsx(pce,{role:a,privileges:r},a.id))}):C.jsx("div",{className:"flex h-full items-center justify-center",children:C.jsx("div",{className:"flex flex-1 items-center justify-center text-inactive-text",children:C.jsxs("div",{className:"flex flex-col items-center justify-center gap-y-4",children:[C.jsx(on,{className:"h-10 w-10"}),C.jsx("div",{className:"font-semibold",children:"There are no roles"}),C.jsxs("div",{className:"flex items-center text-sm",children:["Create a new role by clicking on the"," ",C.jsx(ja,{className:"ml-2 inline h-4 w-4"})]})]})})})})]}),C.jsx(br,{depth:1,className:an("relative flex h-full w-full flex-1 flex-col items-stretch overflow-x-auto",{"border-l-[0.5px]":n}),children:C.jsx("div",{className:"flex h-full w-full select-none flex-col",children:n?C.jsxs(C.Fragment,{children:[C.jsx(vce,{}),i?C.jsx(xce,{selectedRole:i}):C.jsx(wce,{})]}):C.jsx(i6,{tab:"Role"})})})]})},mL=()=>{const e=yr(),t=e.getQodly(),r=e.getSelectedTab(),n=e.getForceLogin(),i=e.getRestrictedByDefault(),{canUndo:o,canRedo:a}=e.getHistory(),s=O.useRef();return C.jsx("div",{className:"absolute inset-0 flex flex-1 overflow-hidden",children:C.jsx("div",{className:"relative flex flex-1 overflow-hidden","data-cy":"Roles&Privileges-editor-cy",ref:c=>s.current=c,children:C.jsxs("div",{className:"flex min-h-0 w-full flex-1 flex-col",children:[C.jsx($Y,{activeTab:r,forceLogin:n,restrictedByDefault:i,canUndo:o,canRedo:a,onUndo:e.actions.undo,onRedo:e.actions.redo,onTabChange:c=>{e.actions.toggleTab(c)},onForceLoginChange:c=>{e.actions.toggleForceLogin(c)},onRestrictedByDefaultChange:c=>{e.actions.toggleRestrictedByDefault(c)},qodly:t}),C.jsx("div",{className:r==="roles"?"flex flex-1 overflow-hidden":"hidden",children:C.jsx(RX,{children:C.jsx(Ece,{})})}),C.jsx("div",{className:r==="privileges"?"flex flex-1 overflow-hidden":"hidden",children:C.jsx(fce,{})})]})})})},_ce="object",Oce={forceLogin:{type:"boolean"},restrictedByDefault:{type:"boolean"},privileges:{type:"array",items:{$ref:"#/definitions/Privilege"}},roles:{type:"array",items:{$ref:"#/definitions/Role"}},permissions:{type:"object",properties:{allowed:{type:"array",items:{$ref:"#/definitions/Permission"}}}}},Cce={Privilege:{type:"object",properties:{id:{type:"string"},privilege:{type:"string"},includes:{type:"array",items:{type:"string"}}},required:["privilege"]},Role:{type:"object",properties:{id:{type:"string"},role:{type:"string"},privileges:{type:"array",items:{type:"string"}}},required:["role"]},PermissionEntry:{type:"array",items:{type:"string"}},Permission:{type:"object",properties:{applyTo:{type:"string"},type:{enum:["dataclass","method","attribute","datastore","singleton","singletonMethod","dsMethod","dataclassMethod","entityMethod","entityselMethod"]},subType:{enum:["dsMethod","dataclassMethod","entityMethod","entityselMethod"]},read:{$ref:"#/definitions/PermissionEntry"},create:{$ref:"#/definitions/PermissionEntry"},update:{$ref:"#/definitions/PermissionEntry"},drop:{$ref:"#/definitions/PermissionEntry"},execute:{$ref:"#/definitions/PermissionEntry"},promote:{$ref:"#/definitions/PermissionEntry"}},required:["applyTo","type"]}},Ice={type:_ce,properties:Oce,definitions:Cce},Rce=()=>{const{modals:e,closeModal:t,editModal:r}=IX();return C.jsx(C.Fragment,{children:e.map((n,i)=>C.jsx(pe.Modal,{hasOverlay:i===0,...n,onClose:t,onEdit:r,container:Br()},n.id))})},bL=e=>{if(!e)return pe.rolesToAPI(pe.sanitizeRoles({}));try{return pe.rolesToAPI(pe.sanitizeRoles(JSON.parse(e)))}catch{return pe.rolesToAPI(pe.sanitizeRoles({}))}},Nce=({initialValue:e,onChange:t,...r})=>{const n=yr(),i=n.getRolesFlags(),o=n.getRolesAndPrivileges(),a=O.useMemo(()=>bL(e),[e]),s=O.useRef(o),c=O.useRef(a),d=O.useRef(a);return O.useEffect(()=>{s.current=o},[o]),O.useEffect(()=>{Xi.isEqual(a,d.current)||(d.current=a,c.current=a,!Xi.isEqual(a,s.current)&&n.actions.setRolesContent({content:a,flags:{touched:!1}}))},[n,a]),pe.useDidMountEffect(()=>{if(!(!t||!i.touched)&&!Xi.isEqual(o,c.current))try{const u=JSON.stringify(o,null,2);t(u),c.current=o}catch(u){console.error("[Roles Editor Standalone] Error on value stringify:",u)}},[o,i.touched,t]),C.jsxs(C.Fragment,{children:[C.jsx("div",{className:"relative h-screen z-10 overflow-hidden",children:C.jsx(mL,{...r})}),C.jsx(Rce,{})]})},Tce=e=>{const t=CX();return C.jsx(z4,{adapter:t,children:C.jsx(pe.TipsProvider,{children:C.jsx(Nce,{...e})})})},Pce=({initialValue:e,catalog:t,history:r,activeTab:n,onTabChange:i,selectedRole:o,onSelectRole:a,selectedPrivilege:s,onSelectPrivilege:c,...d})=>{const u=O.useMemo(()=>({...pe.sanitizeRoles(bL(e)),flags:{touched:!1}}),[e]);return C.jsx(OX,{initialState:u,catalog:t,history:r,selectedTab:n,onTabChange:i,selectedRole:o,onSelectRole:a,selectedPrivilege:s,onSelectPrivilege:c,children:C.jsx(Tce,{initialValue:e,...d})})};exports.ROLES_EDITOR_SCOPE_CLASS=XD.ROLES_EDITOR_SCOPE_CLASS;exports.EditorStateAdapterProvider=z4;exports.Roles=mL;exports.Standalone=Pce;exports.jsonSchema=Ice;exports.useReduxAdapter=WY;
119
+ ressources`,container:Br(),children:C.jsx(Jt,{color:"white",variant:"ghost",onClick:P,children:C.jsx(SV,{})})})}),C.jsx(Lr,{icon:C.jsx(wi,{}),label:"Delete all the non existing resources from privileges",container:Br(),children:C.jsx(Jt,{color:"white",variant:"ghost",onClick:q,disabled:!H,children:C.jsx(QD,{className:"h-4 w-4"})})})]})}),C.jsx("td",{className:"px-4 py-2 text-center text-[12px]",children:"Read"}),C.jsx("td",{className:"px-4 py-2 text-center text-[12px]",children:"Create"}),C.jsx("td",{className:"px-4 py-2 text-center text-[12px]",children:"Update"}),C.jsx("td",{className:"px-4 py-2 text-center text-[12px]",children:"Delete"}),C.jsx("td",{className:"px-4 py-2 text-center text-[12px]",children:"Execute"}),C.jsx("td",{className:"px-4 py-2 text-center text-[12px]",children:"Promote"})]})}),D.length?C.jsxs("tbody",{children:[ie.getVirtualItems().length>0?C.jsx("tr",{style:{height:`${ie.getVirtualItems()[0].start}px`},children:C.jsx("td",{colSpan:7})}):null,ie.getVirtualItems().map(Z=>{const J=D[Z.index],ae=J.permissions.some(he=>he.from.length>0);return C.jsxs("tr",{className:an("group even:bg-body/5 hover:bg-input-bg",{"opacity-60":J.exists===!1}),children:[C.jsxs("td",{className:an("group flex items-center gap-3 py-2 text-xs group-hover:rounded-l group-hover:bg-input-bg ",J.exists===!1?"text-negative-text":""),children:[vL(J.type),J.resource,C.jsx(Lr,{label:"Remove Permission",container:Br(),children:C.jsx(Jt,{color:"white",variant:"ghost",disabled:ae,onClick:()=>{ae?pe.toastSubject.next({kind:"info",markdown:!0,message:"**Info:** Inherited permissions can't be removed",customIcon:on}):re({applyTo:J.resource,type:J.type})},className:"opacity-0 group-hover:opacity-100",children:C.jsx(ja,{className:"h-4 w-4 rotate-45 transform"})})})]}),C.jsx("td",{className:"py-2 text-center group-hover:bg-input-bg ",children:C.jsx(fa,{permissions:J.permissions,showIncluded:r,label:"read",onToggle:he=>$(J,he),onSelect:t,privileges:n,exists:J.exists,optimisticChecked:S[`${J.resource}|${J.type}|read`]})}),C.jsx("td",{className:"py-2 text-center group-hover:bg-input-bg ",children:C.jsx(fa,{permissions:J.permissions,showIncluded:r,label:"create",onToggle:he=>$(J,he),onSelect:t,privileges:n,exists:J.exists,optimisticChecked:S[`${J.resource}|${J.type}|create`]})}),C.jsx("td",{className:"py-2 text-center group-hover:bg-input-bg ",children:C.jsx(fa,{permissions:J.permissions,showIncluded:r,label:"update",onToggle:he=>$(J,he),onSelect:t,privileges:n,exists:J.exists,optimisticChecked:S[`${J.resource}|${J.type}|update`]})}),C.jsx("td",{className:"py-2 text-center group-hover:bg-input-bg",children:C.jsx(fa,{permissions:J.permissions,showIncluded:r,label:"drop",onToggle:he=>$(J,he),onSelect:t,privileges:n,exists:J.exists,optimisticChecked:S[`${J.resource}|${J.type}|drop`]})}),C.jsx("td",{className:"py-2 text-center group-hover:bg-input-bg",children:C.jsx(fa,{promoted:M[J.resource],permissions:J.permissions,showIncluded:r,label:"execute",onToggle:he=>$(J,he),onSelect:t,privileges:n,exists:J.exists,optimisticChecked:S[`${J.resource}|${J.type}|execute`]})}),C.jsx("td",{className:"py-2 text-center group-hover:rounded-r group-hover:bg-input-bg",children:C.jsx(fa,{permissions:J.permissions,showIncluded:r,label:"promote",onToggle:he=>$(J,he),onSelect:t,privileges:n,exists:J.exists,optimisticChecked:S[`${J.resource}|${J.type}|promote`]})})]},`${J.resource}-${Z.index}`)}),(()=>{const Z=ie.getVirtualItems();if(!Z.length)return null;const J=ie.getTotalSize()-Z[Z.length-1].end;return J>0?C.jsx("tr",{style:{height:`${J}px`},children:C.jsx("td",{colSpan:7})}):null})()]}):null]}),!Q.length&&y?C.jsx(VD,{children:"The Permission you're looking for can't be found "}):null,!Q.length&&!y?C.jsxs(VD,{children:["This Privilege has no Permissions configured yet ",C.jsx("br",{}),'Add a new permission by using the "Create a permission" input above']}):null]})},dce=({onCreate:e})=>{const t=yr(),r=t.getPrivileges(),[n,i]=O.useState(null),[o,a]=O.useState(null),[s,c]=O.useState(""),[d,u]=O.useState(null),{styles:h,attributes:p}=Nd(n,o,{modifiers:[{name:"offset",options:{offset:[-10,10]}}],placement:"right-start"});O.useEffect(()=>{c(""),u(null)},[o]);const v=(x=()=>{})=>{u(null);try{const g=pe.createPrivilege(s,r),m=Object.values(g).find(w=>w.privilege===s);t.actions.updatePrivileges(g),m&&e(m),setTimeout(()=>{x()},0)}catch(g){u(g.message)}};return C.jsx(wn.Popover,{children:({open:x,close:g})=>C.jsxs(C.Fragment,{children:[C.jsx(wn.Popover.Button,{className:"rounded","data-cy":"New-priv-btn",as:"div",ref:i,children:C.jsx(Jt,{variant:"ghost",color:"white",children:C.jsx(ja,{className:"h-4 w-4"})})}),x&&C.jsx(ef,{children:C.jsx(wn.Popover.Panel,{ref:a,style:h.popper,...p.popper,"data-cy":"New-priv-pop-up",className:"z-50",static:!0,children:C.jsxs(br,{className:"min-w-[256px] border rounded px-4 py-2 text-xs shadow-md",depth:3,borderType:"light",children:[C.jsx("h5",{className:"mb-2 text-xs font-semibold",children:"Create New Privilege"}),C.jsx("div",{className:"mt-2",children:C.jsxs("label",{className:"flex items-center gap-x-4",children:[C.jsx("span",{children:"Name"}),C.jsx(wt.Root,{className:"w-full",color:d?"negative":"primary",children:C.jsxs(wt.Group,{children:[d&&C.jsx(wt.Message,{children:d}),C.jsx(wt.Field,{autoFocus:!0,value:s,onChange:m=>c(m.target.value),onKeyDown:m=>{m.key==="Enter"&&v()},type:"text"})]})})]})}),C.jsxs("div",{className:"mt-4 flex items-center justify-center gap-x-2",children:[C.jsx(Jt,{onClick:()=>v(g),children:"Create"}),C.jsx(Jt,{color:"white",variant:"outline",onClick:()=>g(),children:"Cancel"})]})]})})})]})})},fce=()=>{const e=yr(),t=e.getCatalog(),r=e.getPrivileges(),[n,i]=O.useState(r);O.useEffect(()=>{const g=setTimeout(()=>i(r),0);return()=>clearTimeout(g)},[r]);const o=O.useMemo(()=>{if(t===null)return n;const g=yz(n,Object.values((t==null?void 0:t.dataClasses)??{}));return xz(g,t)},[n,t]),[a,s]=O.useState(null),[c,d]=O.useState(null),u=O.useCallback(g=>{s(g),e.actions.selectPrivilege((g==null?void 0:g.id)??null)},[e]),h=g=>{u(g),setTimeout(()=>d(g),0)},p=O.useMemo(()=>Object.keys(o),[o]);O.useEffect(()=>{if(a&&o[a.id]||!p.length)return;const g=e.getSelectedPrivilege(),m=g&&o[g]||o[p[0]];u(m),d(m)},[o]),O.useEffect(()=>{p.length<2&&x(!0)},[p.length]);const[v,x]=O.useState(!0);return C.jsxs("div",{className:"flex h-full min-h-0 min-w-0 flex-1",children:[C.jsxs(br,{depth:1,className:"flex h-full w-89 shrink-0 flex-col border-r",children:[C.jsxs("div",{className:"flex flex-shrink-0 items-center justify-between px-3.5 py-2.5",children:[C.jsxs("div",{className:"flex items-center gap-x-1",children:[C.jsx("span",{children:C.jsx(pd,{className:"h-3.5 w-3.5"})}),C.jsx("span",{className:"text-[11px] font-semibold",children:"Privileges"})]}),C.jsx(dce,{onCreate:g=>{u(g),d(g)}})]}),C.jsx(lse,{privileges:o,selectedPrivilege:a,selectPrivilege:h})]}),a&&o[a.id]?C.jsxs(br,{depth:1,className:"privileges-container relative flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden border-l-[0.5px]",children:[C.jsxs("div",{className:"mb-1 flex min-h-0 min-w-0 flex-1 h-full w-full flex-col items-stretch overflow-auto",children:[(c??a).privilege!=="guest"?C.jsx(Yae,{privileges:o,selectedPrivilege:c??a,onSelect:g=>u(r[g]),setShowIncluded:x,showIncluded:v}):null,C.jsx(uce,{privileges:o,rawPrivileges:r,selectedPrivilege:c??a,onSelect:g=>u(r[g]),showIncluded:v})]}),C.jsx("div",{className:"mt-auto flex-shrink-0",children:C.jsx(hce,{privileges:o,selectedPrivilege:c??a,setSelectedPrivilege:u})})]}):C.jsx(i6,{tab:"Privilege"})]})},hce=({privileges:e,selectedPrivilege:t,setSelectedPrivilege:r})=>{const[n,i]=O.useState(!1);return C.jsx(pe.Panel,{path:pe.ROLES_TAB_PATH,isOpen:n,onOpen:()=>i(!0),onClose:()=>i(!1),children:C.jsx("div",{className:"flex h-full w-full min-h-0 px-3 pb-3",children:C.jsx(br,{depth:2,className:"h-full w-full overflow-hidden rounded",children:C.jsx(Hae,{dict:e,data:pe.getGraphData(t.id,e),onSelect:o=>r(e[o])})})})})},pce=O.memo(({role:e})=>{var E;const t=yr(),[r,n]=O.useState(e),[i,o]=O.useState(e.role),[a,s]=O.useState(null),c=t.getPrivileges(),d=((E=r.privileges)==null?void 0:E.filter(I=>c[I]&&c[I].privilege!=="guest").length)||0,u=t.getRoles(),{selectedRole:h,selectRole:p}=dS(),[v,x]=O.useState(!1),g=pe.useOutsideClick(()=>{v&&w()});pe.useDidMountEffect(()=>{i!==e.role&&o(e.role)},[e.role]),O.useEffect(()=>{e.role||x(!0)},[]),O.useEffect(()=>{n(e)},[e]);const m=()=>{s(null),x(!0)},w=()=>{s(null),e.role&&e.role===i&&x(!1);try{const I=pe.saveRole({...r,role:i},u);t.actions.updateRoles(I),x(!1)}catch(I){s(I.message)}},y=async I=>{if(I.stopPropagation(),t.getHost()==="vscode"){_();return}const{confirmed:N}=await t.actions.openModal({title:"Delete Role",type:pe.ModalType.CONFIRM,color:pe.ModalColor.DANGER,message:"Are you sure you want to remove this Role?",icon:"FdWarningDanger"});N&&_()},_=()=>{const I=pe.removeRole(r.id,u),N=Object.keys(I);if(h!==r.id){t.actions.updateRoles(I);return}if(N.length===0)p(null);else{const T=Object.keys(u),M=T.indexOf(r.id),z=Math.max(0,M-1),j=T[z];M===0?p(N[0]):I[j]?p(j):p(N[0])}t.actions.updateRoles(I)},S=(I=null)=>{if(I&&I.stopPropagation(),!e.role){_();return}x(!1),o(e.role)};return C.jsx(C.Fragment,{children:C.jsxs(br,{depth:4,borderType:h===r.id?"primary":h!==r.id?"light":"default",className:an("rounded border p-2"),role:"button","data-cy":"privilegeCard",onClick:()=>{p(r.id)},ref:g,children:[C.jsx("div",{className:"flex items-center justify-between",children:C.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[C.jsx("span",{className:"mr-4",children:C.jsx(pd,{className:"h-6 w-6"})}),v?C.jsxs(wt.Root,{color:a?"negative":"primary",className:"flex-1 mr-2",children:[C.jsx(wt.Group,{className:"border-input-focus-border",children:C.jsx(wt.Field,{type:"text",value:i,onChange:({target:{value:I}})=>{o(I)},onKeyDown:I=>{I.key==="Enter"&&w(),I.key==="Escape"&&S()},placeholder:"role",autoComplete:"off",autoFocus:!0})}),a&&C.jsx(wt.Message,{children:a})]}):C.jsx("span",{className:"inline-block grow overflow-hidden truncate whitespace-nowrap text-xs font-bold",title:i,children:r.role}),C.jsx("div",{className:an("justify-between ml-auto flex w-fit shrink-0 items-center gap-x-2"),children:v?C.jsxs(C.Fragment,{children:[C.jsx(Jt,{color:"white",variant:"ghost",onClick:w,children:C.jsx(_V,{className:"h-4 w-4"})}),C.jsx(Jt,{color:"white",variant:"ghost",onClick:S,children:C.jsx(ej,{className:"h-4 w-4"})})]}):C.jsxs(C.Fragment,{children:[C.jsx(Jt,{color:"white",variant:"ghost",onClick:m,children:C.jsx(cj,{className:"h-4 w-4"})}),C.jsx(Jt,{color:"white",variant:"ghost",onClick:I=>y(I),children:C.jsx(pj,{className:"h-4 w-4"})})]})})]})}),C.jsxs("span",{className:an("ml-10.75 py-1 text-xs"),children:[d," Privilege",d>1?"s":""]})]})})}),gL=(e,t)=>e?t[e]:null,WD=(e,t,r)=>{const n=gL(e,r);return n?Object.values(r).reduce((i,o)=>o.id===e?n.privileges.includes(t)?{...i,[n.id]:{...n,privileges:n.privileges.filter(a=>a!==t)}}:{...i,[n.id]:{...n,privileges:[...n.privileges,t]}}:{...i,[o.id]:o},{}):r},vce=()=>{const e=yr(),t=e.getPrivileges(),r=e.getRoles(),{selectedRole:n}=dS(),i=gL(n,r),o=(c,d)=>d&&d.privileges.includes(c.id),a=O.useMemo(()=>Object.values(t).filter(c=>o(c,i)&&c.privilege!=="guest"),[t,i]),s=O.useMemo(()=>Object.values(t).filter(c=>!o(c,i)&&c.privilege!=="guest"),[t,i]);return C.jsxs(br,{depth:1,className:"w-full border-b p-4 ",children:[C.jsx("div",{className:"mb-4 flex items-center gap-x-5",children:C.jsx("h4",{className:"text-[13px] font-semibold ",children:"Privileges"})}),C.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[C.jsx(vu,{"data-cy":"item=>Permisions",className:"italic opacity-90",children:"guest"}),a.map((c,d)=>C.jsxs(vu,{"data-cy":"item=>Permisions",color:"primary",onClick:()=>{const u=WD(i.id,c.id,r);e.actions.updateRoles(u)},children:[c.privilege,C.jsx(Tu.FdPlus,{className:"rotate-45 transform"})]},d)),s.map((c,d)=>C.jsxs(vu,{"data-cy":"item=>Permisions",color:"dark",onClick:()=>{const u=WD(i.id,c.id,r);e.actions.updateRoles(u)},children:[c.privilege,C.jsx(Tu.FdPlus,{})]},d))]})]})},fd=(e,t,r,n=!1)=>{const i=e.applyTo,o=e.type===pe.EPermissionType.DATACLASS?"ds":i.split(".")[0],a={...t,...r},s=()=>({value:!n,inherited:!1,from:[],explicitly:!1}),c={read:s(),create:s(),update:s(),drop:s(),execute:s(),promote:s()},d=h=>{h.forEach(p=>{a[p]&&(a[p].resources.forEach(v=>{if(v.resource===i||v.resource===o){const x=fd(e,t,{[p]:a[p]},n);Object.values(v.permissions).forEach(g=>{c[g.name].explicitly||(!c[g.name].from.includes(a[p].privilege)&&g.checked&&c[g.name].from.push(a[p].privilege),c[g.name].inherited=c[g.name].inherited||x[g.name].value||x[g.name].inherited)})}}),a[p].includes.length>0&&d(a[p].includes))})};if(Object.values(r).forEach(h=>{h.resources.forEach(p=>{p.resource===i&&Object.values(p.permissions).forEach(v=>{v.checked&&(c[v.name].explicitly=!0,n&&(c[v.name].value=!0))})}),(h.includes.length>0||h.privilege==="guest")&&d(h.includes)}),Object.values(t).forEach(h=>{h.resources.forEach(p=>{p.resource===i&&(h.privilege==="guest"?Object.values(p.permissions).forEach(v=>{v.checked&&(c[v.name].explicitly=!0,n&&(c[v.name].value=!0))}):Object.values(p.permissions).forEach(v=>{!c[v.name].explicitly&&v.checked&&(n?c[v.name].value=!0:c[v.name].value=!1)}))})}),(n?Object.entries(c).some(([h,p])=>h!=="promote"&&!p.value&&!p.explicitly):Object.entries(c).some(([h,p])=>h!=="promote"&&p.value&&!p.explicitly))&&![pe.EPermissionType.DATASTORE,pe.EPermissionType.SINGLETON].includes(e.type)){const h={applyTo:o,type:e.type===pe.EPermissionType.DATACLASS?pe.EPermissionType.DATASTORE:e.type===pe.EPermissionType.SINGLETON_METHOD?pe.EPermissionType.SINGLETON:pe.EPermissionType.DATACLASS},p=fd(h,t,r,n),v=x=>{let g=c[x].value;return n?!c[x].value&&!c[x].explicitly&&(g=p[x].value):c[x].value&&!c[x].explicitly&&(g=p[x].value),{value:g,inherited:c[x].inherited||p[x].inherited,from:c[x].from.length>0?c[x].from:p[x].from,explicitly:c[x].explicitly}};return{read:v("read"),create:v("create"),update:v("update"),drop:v("drop"),execute:v("execute"),promote:v("promote")}}return{read:c.read,create:c.create,update:c.update,drop:c.drop,execute:c.execute,promote:c.promote}},gce=({children:e})=>C.jsx("div",{className:"h-full w-full",children:C.jsx("div",{className:"flex h-full w-full flex-1 items-center justify-center",children:C.jsxs("div",{className:"flex flex-col items-center justify-center gap-y-4 py-4 text-inactive-text",children:[C.jsx(on,{className:"absolute -right-full h-10 w-10 translate-x-1"}),C.jsx("div",{className:"text-center text-sm",children:e})]})})}),mce=e=>{switch(e){case"dataclass":return C.jsx(Pu,{className:"h-6 w-6"});case"singleton":return C.jsx(fj,{className:"h-6 w-6"});case"datastore":return C.jsx(lj,{className:"h-6 w-6"});case"attribute":return C.jsx(hj,{className:"h-6 w-6"});case"method":return C.jsx(tj,{className:"h-6 w-6"});case"singletonMethod":return C.jsx(sj,{className:"h-6 w-6"});case"entityselMethod":return C.jsx(aj,{className:"h-6 w-6"});case"entityMethod":return C.jsx(oj,{className:"h-6 w-6"});case"dsMethod":return C.jsx(ij,{className:"h-6 w-6"});case"dataclassMethod":return C.jsx(nj,{className:"h-6 w-6"});default:return C.jsx(Pu,{className:"h-6 w-6"})}},UD=({privileges:e,permission:t,hasChild:r,depth:n,isChild:i=!1,className:o,inSearch:a,toggleCollapse:s,collapsed:c,isRestrictedByDefault:d,toastMessageCallback:u,computedInherited:h})=>{const[p,v]=t.applyTo.split("."),x=O.useMemo(()=>h||fd(t,e.otherPrivs,e.rolePrivs,d),[h,e,t,d]);return C.jsxs("tr",{className:an("group even:bg-body/5 hover:bg-input-bg",o),children:[C.jsxs("td",{className:an("flex h-full w-full items-stretch gap-3 p-0 text-xs group-hover:rounded-l group-hover:bg-input-bg",{"px-1":a}),children:[Array(n).fill("").map((g,m)=>C.jsx("div",{className:an("ml-1.5 mr-1 w-0.5 bg-muted",{"mr-0.5":i})},m)),C.jsxs("div",{className:"flex items-center gap-3 py-2",children:[r&&C.jsx("button",{onClick:s,className:"w-3",children:c?C.jsx(uj,{className:"inline h-4 w-4"}):C.jsx(rj,{className:"inline h-4 w-4"})}),mce(t.type),a?t.applyTo:v||p]})]}),C.jsx("td",{className:"py-2 text-center group-hover:bg-input-bg",children:[pe.EPermissionType.ATTRIBUTE,pe.EPermissionType.DATASTORE,pe.EPermissionType.DATACLASS].includes(t.type)&&C.jsxs("div",{className:"relative mx-auto flex w-fit items-center justify-center gap-x-1",onClick:u,children:[C.jsx(ir,{value:x.read.value||x.read.inherited,isDisabled:!0}),C.jsx("div",{className:"absolute left-full top-1/2 flex -translate-y-1/2 translate-x-1/2 cursor-pointer items-center",children:!x.read.value&&x.read.inherited?C.jsx(Lr,{container:Br(),delay:100,label:C.jsx("div",{className:"space-y-1 p-1",children:x.read.from.length?C.jsxs("div",{className:"flex items-start",children:[C.jsx(wi,{className:"mr-2 mt-0.5 h-4 w-4 shrink-0"}),C.jsxs("p",{className:"flex flex-col gap-y-2",children:[C.jsx("span",{className:"mr-1",children:"Permission inherited from:"}),C.jsx("ul",{children:x.read.from.map((g,m)=>C.jsx("li",{className:"cursor-pointer list-disc font-bold",children:g},m))})]})]}):null}),children:C.jsx(on,{className:"h-4 w-4"})}):""})]})}),C.jsx("td",{className:"py-2 text-center group-hover:bg-input-bg",children:[pe.EPermissionType.ATTRIBUTE,pe.EPermissionType.DATASTORE,pe.EPermissionType.DATACLASS].includes(t.type)&&C.jsxs("div",{className:"relative mx-auto flex w-fit items-center justify-center gap-x-1",onClick:u,children:[C.jsx(ir,{value:x.create.value||x.create.inherited,isDisabled:!0}),C.jsx("div",{className:"absolute left-full top-1/2 flex -translate-y-1/2 translate-x-1/2 cursor-pointer items-center",children:!x.create.value&&x.create.inherited?C.jsx(Lr,{container:Br(),delay:100,label:C.jsx("div",{className:"space-y-1 p-1",children:x.read.from.length?C.jsxs("div",{className:"flex items-start",children:[C.jsx(wi,{className:"mr-2 mt-0.5 h-4 w-4 shrink-0"}),C.jsxs("p",{className:"flex flex-col gap-y-2",children:[C.jsx("span",{className:"mr-1",children:"Permission inherited from:"}),C.jsx("ul",{children:x.read.from.map((g,m)=>C.jsx("li",{className:"cursor-pointer list-disc font-bold",children:g},m))})]})]}):null}),children:C.jsx(on,{className:"h-4 w-4"})}):""})]})}),C.jsx("td",{className:"py-2 text-center group-hover:bg-input-bg",children:[pe.EPermissionType.ATTRIBUTE,pe.EPermissionType.DATASTORE,pe.EPermissionType.DATACLASS].includes(t.type)&&C.jsxs("div",{className:"relative mx-auto flex w-fit items-center justify-center gap-x-1",onClick:u,children:[C.jsx(ir,{value:x.update.value||x.update.inherited,isDisabled:!0}),C.jsx("div",{className:"absolute left-full top-1/2 flex -translate-y-1/2 translate-x-1/2 cursor-pointer items-center",children:!x.update.value&&x.update.inherited?C.jsx(Lr,{container:Br(),delay:100,label:C.jsx("div",{className:"space-y-1 p-1",children:x.update.from.length?C.jsxs("div",{className:"flex items-start",children:[C.jsx(wi,{className:"mr-2 mt-0.5 h-4 w-4 shrink-0"}),C.jsxs("p",{className:"flex flex-col gap-y-2",children:[C.jsx("span",{className:"mr-1",children:"Permission inherited from:"}),C.jsx("ul",{children:x.update.from.map((g,m)=>C.jsx("li",{className:"cursor-pointer list-disc font-bold",children:g},m))})]})]}):null}),children:C.jsx(on,{className:"h-4 w-4"})}):""})]})}),C.jsx("td",{className:"py-2 text-center group-hover:bg-input-bg",children:[pe.EPermissionType.ATTRIBUTE,pe.EPermissionType.DATASTORE,pe.EPermissionType.DATACLASS].includes(t.type)&&C.jsxs("div",{className:"relative mx-auto flex w-fit items-center justify-center gap-x-1",onClick:u,children:[C.jsx(ir,{value:x.drop.value||x.drop.inherited,isDisabled:!0}),C.jsx("div",{className:"absolute left-full top-1/2 flex -translate-y-1/2 translate-x-1/2 cursor-pointer items-center",children:!x.drop.value&&x.drop.inherited?C.jsx(Lr,{container:Br(),delay:100,label:C.jsx("div",{className:"space-y-1 p-1",children:x.drop.from.length?C.jsxs("div",{className:"flex items-start",children:[C.jsx(wi,{className:"mr-2 mt-0.5 h-4 w-4 shrink-0"}),C.jsxs("p",{className:"flex flex-col gap-y-2",children:[C.jsx("span",{className:"mr-1",children:"Permission inherited from:"}),C.jsx("ul",{children:x.drop.from.map((g,m)=>C.jsx("li",{className:"cursor-pointer list-disc font-bold",children:g},m))})]})]}):null}),children:C.jsx(on,{className:"h-4 w-4"})}):""})]})}),C.jsx("td",{className:"py-2 text-center group-hover:rounded-r group-hover:bg-input-bg",children:t.type!=="attribute"&&C.jsxs("div",{className:"relative mx-auto flex w-fit items-center justify-center gap-x-1",onClick:u,children:[C.jsx(ir,{value:x.execute.value||x.execute.inherited,isDisabled:!0}),C.jsx("div",{className:"absolute left-full top-1/2 flex -translate-y-1/2 translate-x-1/2 cursor-pointer items-center",children:!x.execute.value&&x.execute.inherited?C.jsx(Lr,{container:Br(),delay:100,label:C.jsx("div",{className:"space-y-1 p-1",children:x.execute.from.length?C.jsxs("div",{className:"flex items-start",children:[C.jsx(wi,{className:"mr-2 mt-0.5 h-4 w-4 shrink-0"}),C.jsxs("p",{className:"flex flex-col gap-y-2",children:[C.jsx("span",{className:"mr-1",children:"Permission inherited from:"}),C.jsx("ul",{children:x.execute.from.map((g,m)=>C.jsx("li",{className:"cursor-pointer list-disc font-bold",children:g},m))})]})]}):null}),children:C.jsx(on,{className:"h-4 w-4"})}):""})]})})]})};function GD(e,t,r){const n=[],i=(a,s,c)=>n.push({id:a,permission:s,depth:c,hasChild:!1,isChild:!1}),o=(a,s,c,d,u,h)=>{n.push({id:a,permission:s,depth:c,hasChild:!0,isChild:d,toggleId:a,isCollapsed:u}),u||h()};for(const a of Object.values(e)){o("ds-group",{applyTo:a.applyTo,type:a.type},0,!1,t,()=>{for(const s of a.methods)i(`dsm-${s.applyTo}`,s,1);for(const s of a.dataClasses){const c=`dc-${s.applyTo}`;o(c,{applyTo:s.applyTo,type:s.type},1,!0,r[c]??!1,()=>{for(const d of s.attributes)i(`dca-${d.applyTo}`,d,2);for(const d of s.methods)i(`dcm-${d.applyTo}`,d,2)})}});for(const s of a.singletons){const c=`sing-${s.applyTo}`;o(c,{applyTo:s.applyTo,type:s.type},0,!0,r[c]??!1,()=>{for(const d of s.attributes)i(`singa-${d.applyTo}`,d,1);for(const d of s.methods)i(`singm-${d.applyTo}`,d,1)})}}return n}const KD=["datastore","singleton","dataclass","attribute","dsMethod","dataclassMethod","entityMethod","entityselMethod","singletonMethod"],yo={datastore:["datastore"],dataclass:["dataclass"],singleton:["singleton"],functions:["method","singletonMethod","dsMethod","dataclassMethod","entityMethod","entityselMethod"],attribute:["attribute"]},YD=Object.values(yo).flat();function pa(e,t){return t.length>0&&t.every(r=>e.includes(r))}function bce(e,t){return Array.from(new Set([...e,...t]))}function yce(e,t){return e.filter(r=>!t.includes(r))}const xce=({selectedRole:e})=>{const[t,r]=O.useState(null),[n,i]=O.useState(null),{styles:o,attributes:a}=Nd(t,n,{modifiers:[{name:"offset",options:{offset:[0,10]}}]}),s=yr(),c=s.getRestrictedByDefault(),d=s.getPrivileges(),[u,h]=O.useState([]),[p,v]=O.useState([]),[x,g]=O.useState(""),[m,w]=O.useState("");O.useEffect(()=>{const J=setTimeout(()=>v(u),0);return()=>clearTimeout(J)},[u]);const y=s.getCatalogMethods(),_=s.getDataclasses(),S=s.getSingletons(),E=O.useMemo(()=>Uae(y,Object.values(_),Object.values(S)),[y,_,S]),I=O.useMemo(()=>!p.length&&!m?[]:[...KS(m,y,Object.values(_),Object.values(S))].filter(J=>p.length?p.includes(J.type):!0).sort((J,ae)=>{const he=KD.indexOf(J.type),ue=KD.indexOf(ae.type);return he!==ue?he-ue:J.applyTo.toLowerCase()>ae.applyTo.toLowerCase()?1:-1}),[m,p,y,_,S]),N=J=>h([...J]),T=J=>{h(ae=>pa(ae,J)?yce(ae,J):bce(ae,J))},M=J=>T(yo[J]),z=YD.every(J=>u.includes(J)),j=u.length>0&&!z,W=pa(u,yo.functions),U=()=>N(YD),A=()=>N([]),K=s.getRoles(),[V,te]=O.useState(K);O.useEffect(()=>{const J=setTimeout(()=>te(K),0);return()=>clearTimeout(J)},[K]);const G=O.useRef(null);O.useEffect(()=>{var J,ae;(ae=(J=G.current)==null?void 0:J.getScrollElement())==null||ae.scrollTo({top:0})},[e]);const re=cd({count:I.length,getScrollElement:()=>{var J;return((J=G.current)==null?void 0:J.getScrollElement())??null},estimateSize:()=>36,overscan:5,paddingEnd:40}),P=O.useMemo(()=>{const J=Object.values(d).find(le=>le.privilege==="guest"),ae=V[e],he=ae?Object.fromEntries(ae.privileges.map(le=>[le,d[le]]).filter(([,le])=>!!le)):{};if(c)return{rolePrivs:he,otherPrivs:J?{[J.id]:J}:{}};const ue=J?{[J.id]:{...J,active:!0}}:{},de=Object.fromEntries(Object.entries(d).filter(([le])=>le!==(J==null?void 0:J.id)&&!(ae!=null&&ae.privileges.includes(le))).map(([le,xe])=>[le,{...xe,active:!1}]));return{rolePrivs:he,otherPrivs:{...ue,...de}}},[d,V,e,c]),[B,X]=O.useState(!1),[Q,D]=O.useState({}),$=O.useMemo(()=>{const J=[];for(const ae of Object.values(E)){for(const he of ae.dataClasses)J.push(`dc-${he.applyTo}`);for(const he of ae.singletons)J.push(`sing-${he.applyTo}`)}return J},[E]),H=$.length>0&&$.every(J=>Q[J]===!0),q=O.useCallback(()=>{const J={};for(const ae of $)J[ae]=!0;D(J)},[$]),Y=O.useCallback(J=>{J==="ds-group"?X(ae=>!ae):D(ae=>({...ae,[J]:!ae[J]}))},[]),ie=O.useMemo(()=>{const J=new Map;for(const{permission:ae}of GD(E,!1,{}))J.set(`${ae.applyTo}|${ae.type}`,fd(ae,P.otherPrivs,P.rolePrivs,c));return J},[P,c,E]),ne=O.useMemo(()=>GD(E,B,Q),[E,B,Q]),ve=cd({count:ne.length,getScrollElement:()=>{var J;return((J=G.current)==null?void 0:J.getScrollElement())??null},estimateSize:()=>36,overscan:8,paddingEnd:15}),Z=O.useCallback(()=>{pe.toastSubject.next({kind:"info",markdown:!0,message:"**Info:** You can add or modify permissions only in the Privilege section.",customIcon:Ew})},[]);return C.jsxs(hf,{ref:G,className:"z-20 h-full flex-1 overflow-auto p-3.75 pt-0",style:{maxHeight:"calc(100vh - 5.5rem - 85px - 20px)"},children:[C.jsxs("table",{className:"relative h-full w-full border-collapse",children:[C.jsx("thead",{className:"sticky top-0 z-20 bg-panel-1",children:C.jsxs("tr",{className:"border-b border-grey-100",children:[C.jsx("td",{className:"py-2",children:C.jsxs("div",{className:"flex items-center gap-x-2",children:[C.jsx(Lr,{label:"Collapse All",position:"up",container:Br(),children:C.jsx(Jt,{color:"white",variant:"ghost",disabled:B&&H,onClick:()=>{H?(q(),X(!0)):q()},children:C.jsx(yV,{})})}),C.jsx(wt.Root,{className:"w-56",children:C.jsxs(wt.Group,{children:[C.jsx(wt.Icon,{children:C.jsx(dj,{})}),C.jsx(wt.Field,{type:"text",placeholder:"Search",value:x,onChange:J=>{const ae=J.target.value;g(ae),setTimeout(()=>w(ae),0)}}),C.jsx(wn.Popover,{className:"flex items-center",children:({open:J})=>C.jsxs(C.Fragment,{children:[C.jsx(wn.Popover.Button,{ref:r,children:C.jsx(wt.Icon,{isAction:!0,children:C.jsx(JD,{})})}),J&&C.jsx(ef,{children:C.jsx(wn.Popover.Panel,{ref:i,style:o.popper,...a.popper,className:"z-50",static:!0,children:C.jsxs(br,{depth:3,borderType:"light",className:"rounded-md border px-4 py-2.5 text-xs",children:[C.jsxs("label",{className:"mb-2 flex cursor-pointer items-center gap-2",children:[C.jsx(ir,{size:"sm",value:j?null:z,onChange:()=>z?A():U()}),C.jsx("h5",{className:"text-sm font-semibold",children:"Filter"})]}),C.jsxs("div",{className:"space-y-2 text-s",children:[C.jsx("div",{className:"flex items-center",children:C.jsx(ir,{size:"sm",value:pa(u,yo.datastore),onChange:()=>M("datastore"),label:"Datastore"})}),C.jsx("div",{className:"flex items-center",children:C.jsx(ir,{size:"sm",value:pa(u,yo.dataclass),onChange:()=>M("dataclass"),label:"Dataclass"})}),C.jsx("div",{className:"flex items-center",children:C.jsx(ir,{size:"sm",value:pa(u,yo.singleton),onChange:()=>M("singleton"),label:"Singleton"})}),C.jsx("div",{className:"flex items-center",children:C.jsx(ir,{size:"sm",value:W,onChange:()=>M("functions"),label:"Functions"})}),C.jsx("div",{className:"flex items-center",children:C.jsx(ir,{size:"sm",value:pa(u,yo.attribute),onChange:()=>M("attribute"),label:"Attribute"})})]})]})})})]})})]})})]})}),C.jsx("td",{className:"px-4 py-2 text-center text-[12px]",children:"read"}),C.jsx("td",{className:"px-4 py-2 text-center text-[12px]",children:"Create"}),C.jsx("td",{className:"px-4 py-2 text-center text-[12px]",children:"Update"}),C.jsx("td",{className:"px-4 py-2 text-center text-[12px]",children:"Delete"}),C.jsx("td",{className:"px-4 py-2 text-center text-[12px]",children:"Execute"})]})}),C.jsx("tbody",{className:"relative",children:p.length||m?C.jsxs(C.Fragment,{children:[re.getVirtualItems().length>0?C.jsx("tr",{style:{height:`${re.getVirtualItems()[0].start}px`},children:C.jsx("td",{colSpan:6})}):null,re.getVirtualItems().map(J=>{const ae=I[J.index];return C.jsx(UD,{privileges:P,permission:ae,depth:0,inSearch:!0,isRestrictedByDefault:c,allPrivileges:d,toastMessageCallback:Z,computedInherited:ie.get(`${ae.applyTo}|${ae.type}`)},`${ae.type}-${J.index}`)}),(()=>{const J=re.getVirtualItems();if(!J.length)return null;const ae=re.getTotalSize()-J[J.length-1].end;return ae>0?C.jsx("tr",{style:{height:`${ae}px`},children:C.jsx("td",{colSpan:6})}):null})()]}):C.jsxs(C.Fragment,{children:[ve.getVirtualItems().length>0?C.jsx("tr",{style:{height:`${ve.getVirtualItems()[0].start}px`},children:C.jsx("td",{colSpan:6})}):null,ve.getVirtualItems().map(J=>{const ae=ne[J.index];return C.jsx(UD,{privileges:P,permission:ae.permission,depth:ae.depth,hasChild:ae.hasChild,isChild:ae.isChild,collapsed:ae.isCollapsed,toggleCollapse:ae.toggleId?()=>Y(ae.toggleId):void 0,isRestrictedByDefault:c,allPrivileges:d,toastMessageCallback:Z,computedInherited:ie.get(`${ae.permission.applyTo}|${ae.permission.type}`)},ae.id)}),(()=>{const J=ve.getVirtualItems();if(!J.length)return null;const ae=ve.getTotalSize()-J[J.length-1].end;return ae>0?C.jsx("tr",{style:{height:`${ae}px`},children:C.jsx("td",{colSpan:6})}):null})()]})})]}),(m||p.length)&&!I.length?C.jsx(gce,{children:"The Permission you're looking for can't be found "}):null]})},wce=()=>C.jsx("div",{className:"flex flex-1 items-center justify-center",children:C.jsx("div",{className:"h-6 w-6 animate-spin rounded-full border-2 border-grey-200 border-t-primary-dark"})}),Sce=()=>{const e=yr(),t=e.getRoles(),[r,n]=O.useState(null),[i,o]=O.useState(null),[a,s]=O.useState(""),[c,d]=O.useState(null),{styles:u,attributes:h}=Nd(r,i,{modifiers:[{name:"offset",options:{offset:[-10,10]}}],placement:"right-start"});O.useEffect(()=>{s(""),d(null)},[i]);const p=()=>{if(!a)throw new Error("Please enter a valid name");if(Object.values(t).find(m=>m.role.toLowerCase()===a.toLowerCase()))throw new Error(`A role with the name ${a} already exists`);const x=U4.generate(),g=pe.createRole(x,a,t);e.actions.updateRoles(g)};return C.jsx(wn.Popover,{children:({open:v,close:x})=>{const g=()=>{d(null);try{pe.validateName(a),p(),x()}catch(m){d(m.message)}};return C.jsxs(C.Fragment,{children:[C.jsx(wn.Popover.Button,{className:"rounded","data-cy":"New-priv-btn",as:"div",ref:n,children:C.jsx(Jt,{variant:"ghost",color:"white",children:C.jsx(ja,{className:"h-4 w-4"})})}),v&&C.jsx(ef,{children:C.jsx(wn.Popover.Panel,{ref:o,style:u.popper,...h.popper,"data-cy":"New-priv-pop-up",className:"z-50",static:!0,children:C.jsxs(br,{className:"min-w-[256px] border rounded px-4 py-2 text-xs shadow-md",depth:3,borderType:"light",children:[C.jsx("h5",{className:"mb-2 text-xs font-semibold",children:"Create New Role"}),C.jsx("div",{className:"mt-2",children:C.jsxs("label",{className:"flex items-center gap-x-4",children:[C.jsx("span",{children:"Name"}),C.jsx(wt.Root,{color:c?"negative":"primary",className:"w-full",children:C.jsxs(wt.Group,{children:[c&&C.jsx(wt.Message,{children:c}),C.jsx(wt.Field,{autoFocus:!0,value:a,onChange:m=>s(m.target.value),onKeyDown:m=>{m.key==="Enter"&&g()},type:"text"})]})})]})}),C.jsxs("div",{className:"mt-4 flex items-center justify-center gap-x-2",children:[C.jsx(Jt,{onClick:()=>{g()},children:"Create"}),C.jsx(Jt,{color:"white",variant:"outline",onClick:()=>x(),children:"Cancel"})]})]})})})]})}})},Ece=()=>{const e=yr(),t=e.getRoles(),r=e.getPrivileges(),{selectedRole:n,deferredSelectedRole:i}=dS(),o=O.useMemo(()=>Object.values(t).sort((a,s)=>pe.localeCompare(a.role,s.role)),[t]);return C.jsxs("div",{className:"flex flex-1 h-full",children:[C.jsxs(br,{depth:1,className:"flex h-full w-89 flex-col border-r",children:[C.jsxs("div",{className:"flex shrink-0 items-center justify-between px-3.5 py-2.5",children:[C.jsxs("div",{className:"flex items-center gap-x-1",children:[C.jsx("span",{children:C.jsx(pd,{className:"h-3.5 w-3.5"})}),C.jsx("span",{className:"text-[11px] font-semibold",children:"Roles"})]}),C.jsx(Sce,{})]}),C.jsx("div",{className:"flex-1 overflow-auto p-4 pb-10 pt-1",children:o.length>0?C.jsx("div",{className:"flex flex-col gap-4",children:o.map(a=>C.jsx(pce,{role:a,privileges:r},a.id))}):C.jsx("div",{className:"flex h-full items-center justify-center",children:C.jsx("div",{className:"flex flex-1 items-center justify-center text-inactive-text",children:C.jsxs("div",{className:"flex flex-col items-center justify-center gap-y-4",children:[C.jsx(on,{className:"h-10 w-10"}),C.jsx("div",{className:"font-semibold",children:"There are no roles"}),C.jsxs("div",{className:"flex items-center text-sm",children:["Create a new role by clicking on the"," ",C.jsx(ja,{className:"ml-2 inline h-4 w-4"})]})]})})})})]}),C.jsx(br,{depth:1,className:an("relative flex h-full w-full flex-1 flex-col items-stretch overflow-x-auto",{"border-l-[0.5px]":n}),children:C.jsx("div",{className:"flex h-full w-full select-none flex-col",children:n?C.jsxs(C.Fragment,{children:[C.jsx(vce,{}),i?C.jsx(xce,{selectedRole:i}):C.jsx(wce,{})]}):C.jsx(i6,{tab:"Role"})})})]})},mL=()=>{const e=yr(),t=e.getQodly(),r=e.getSelectedTab(),n=e.getForceLogin(),i=e.getRestrictedByDefault(),{canUndo:o,canRedo:a}=e.getHistory(),s=O.useRef();return C.jsx("div",{className:"absolute inset-0 flex flex-1 overflow-hidden",children:C.jsx("div",{className:"relative flex flex-1 overflow-hidden","data-cy":"Roles&Privileges-editor-cy",ref:c=>s.current=c,children:C.jsxs("div",{className:"flex min-h-0 w-full flex-1 flex-col",children:[C.jsx($Y,{activeTab:r,forceLogin:n,restrictedByDefault:i,canUndo:o,canRedo:a,onUndo:e.actions.undo,onRedo:e.actions.redo,onTabChange:c=>{e.actions.toggleTab(c)},onForceLoginChange:c=>{e.actions.toggleForceLogin(c)},onRestrictedByDefaultChange:c=>{e.actions.toggleRestrictedByDefault(c)},qodly:t}),C.jsx("div",{className:r==="roles"?"flex flex-1 overflow-hidden":"hidden",children:C.jsx(RX,{children:C.jsx(Ece,{})})}),C.jsx("div",{className:r==="privileges"?"flex flex-1 overflow-hidden":"hidden",children:C.jsx(fce,{})})]})})})},_ce="object",Oce={forceLogin:{type:"boolean"},restrictedByDefault:{type:"boolean"},privileges:{type:"array",items:{$ref:"#/definitions/Privilege"}},roles:{type:"array",items:{$ref:"#/definitions/Role"}},permissions:{type:"object",properties:{allowed:{type:"array",items:{$ref:"#/definitions/Permission"}}}}},Cce={Privilege:{type:"object",properties:{id:{type:"string"},privilege:{type:"string"},includes:{type:"array",items:{type:"string"}}},required:["privilege"]},Role:{type:"object",properties:{id:{type:"string"},role:{type:"string"},privileges:{type:"array",items:{type:"string"}}},required:["role"]},PermissionEntry:{type:"array",items:{type:"string"}},Permission:{type:"object",properties:{applyTo:{type:"string"},type:{enum:["dataclass","method","attribute","datastore","singleton","singletonMethod","dsMethod","dataclassMethod","entityMethod","entityselMethod"]},subType:{enum:["dsMethod","dataclassMethod","entityMethod","entityselMethod"]},read:{$ref:"#/definitions/PermissionEntry"},create:{$ref:"#/definitions/PermissionEntry"},update:{$ref:"#/definitions/PermissionEntry"},drop:{$ref:"#/definitions/PermissionEntry"},execute:{$ref:"#/definitions/PermissionEntry"},promote:{$ref:"#/definitions/PermissionEntry"}},required:["applyTo","type"]}},Ice={type:_ce,properties:Oce,definitions:Cce},Rce=()=>{const{modals:e,closeModal:t,editModal:r}=IX();return C.jsx(C.Fragment,{children:e.map((n,i)=>C.jsx(pe.Modal,{hasOverlay:i===0,...n,onClose:t,onEdit:r,container:Br()},n.id))})},bL=e=>{if(!e)return pe.rolesToAPI(pe.sanitizeRoles({}));try{return pe.rolesToAPI(pe.sanitizeRoles(JSON.parse(e)))}catch{return pe.rolesToAPI(pe.sanitizeRoles({}))}},Nce=({initialValue:e,onChange:t,...r})=>{const n=yr(),i=n.getRolesFlags(),o=n.getRolesAndPrivileges(),a=O.useMemo(()=>bL(e),[e]),s=O.useRef(o),c=O.useRef(a),d=O.useRef(a);return O.useEffect(()=>{s.current=o},[o]),O.useEffect(()=>{Xi.isEqual(a,d.current)||(d.current=a,c.current=a,!Xi.isEqual(a,s.current)&&n.actions.setRolesContent({content:a,flags:{touched:!1}}))},[n,a]),pe.useDidMountEffect(()=>{if(!(!t||!i.touched)&&!Xi.isEqual(o,c.current))try{const u=JSON.stringify(o,null,2);t(u),c.current=o}catch(u){console.error("[Roles Editor Standalone] Error on value stringify:",u)}},[o,i.touched,t]),C.jsxs(C.Fragment,{children:[C.jsx("div",{className:"relative h-screen z-10 overflow-hidden",children:C.jsx(mL,{...r})}),C.jsx(Rce,{})]})},Tce=e=>{const t=CX();return C.jsx(z4,{adapter:t,children:C.jsx(pe.TipsProvider,{children:C.jsx(Nce,{...e})})})},Pce=({initialValue:e,catalog:t,history:r,activeTab:n,onTabChange:i,selectedRole:o,onSelectRole:a,selectedPrivilege:s,onSelectPrivilege:c,host:d="vscode",...u})=>{const h=O.useMemo(()=>({...pe.sanitizeRoles(bL(e)),flags:{touched:!1}}),[e]);return C.jsx(OX,{initialState:h,catalog:t,host:d,history:r,selectedTab:n,onTabChange:i,selectedRole:o,onSelectRole:a,selectedPrivilege:s,onSelectPrivilege:c,children:C.jsx(Tce,{initialValue:e,...u})})};exports.ROLES_EDITOR_SCOPE_CLASS=XD.ROLES_EDITOR_SCOPE_CLASS;exports.EditorStateAdapterProvider=z4;exports.Roles=mL;exports.Standalone=Pce;exports.jsonSchema=Ice;exports.useReduxAdapter=WY;
120
120
  //# sourceMappingURL=index.cjs.js.map