UNPKG

unleash-server

Version:

Unleash is an enterprise ready feature flag service. It provides different strategies for handling feature flags.

3 lines 53.3 kB
import{n as e,r as t,s as n,t as r}from"./jsx-runtime-ButemYzH.js";import{t as i}from"./objectId-D7ukzTLu.js";import{$l as a,$u as o,Aa as s,Bn as c,Bs as l,Cd as u,Ci as d,Cs as f,Da as p,Dn as m,Dt as h,Es as g,Eu as _,Fs as v,Fu as y,Hs as b,Ht as x,Iu as S,Kn as C,Ls as w,Mr as T,Ms as E,Nr as D,Ns as O,Oa as k,Ps as A,Ql as j,Ra as M,Rs as ee,Ud as N,Ut as te,Vs as ne,Vu as re,Wa as ie,Ws as ae,Xd as oe,Xn as se,Xu as P,Yi as ce,Ys as le,Yu as F,Zd as ue,Zs as de,_d as I,_r as fe,_t as pe,ad as L,ai as me,ba as R,co as he,ec as z,ed as ge,fc as _e,ft as ve,fu as ye,gi as be,gt as xe,hd as Se,hu as Ce,ic as we,id as B,jc as Te,ji as Ee,ki as V,lt as De,lu as Oe,mc as ke,mi as Ae,mt as je,nc as Me,pc as Ne,pd as Pe,qn as Fe,qu as Ie,rc as Le,rd as H,ru as Re,st as ze,tc as U,uc as Be,uu as W,vr as Ve,vt as He,xd as G,xr as Ue,yt as We,yu as Ge,zs as Ke}from"./index-B0RbDPtk.js";import{t as qe}from"./useApiTokens-Cl4y9yhp.js";import{A as Je,B as Ye,C as Xe,G as Ze,H as Qe,I as K,J as $e,K as et,P as q,Q as J,R as tt,U as nt,V as rt,W as it,_ as at,b as ot,f as st,g as ct,h as lt,i as ut,j as dt,k as ft,l as pt,m as mt,n as ht,o as gt,q as _t,r as vt,t as yt,tt as bt,u as xt,v as St,w as Ct,y as wt,z as Tt}from"./dist-CYYjHgCS.js";var Y=n(e()),Et=()=>{let{makeRequest:e,createRequest:t,errors:n,loading:r}=E({propagateErrors:!0}),i=`api/admin/playground`;return{evaluateAdvancedPlayground:async n=>{let r=t(`${i}/advanced`,{method:`POST`,body:JSON.stringify(n)});return(await e(r.caller,r.id)).json()},evaluateChangeRequestPlayground:async(n,r)=>{let a=t(`${i}/change-request/${n}`,{method:`POST`,body:JSON.stringify(r)});return(await e(a.caller,a.id)).json()},errors:n,loading:r}},Dt=n(t(((e,t)=>{function n(e,t=100,n={}){if(typeof e!=`function`)throw TypeError(`Expected the first parameter to be a function, got \`${typeof e}\`.`);if(t<0)throw RangeError("`wait` must not be negative.");let{immediate:r}=typeof n==`boolean`?{immediate:n}:n,i,a,o,s,c;function l(){let t=i,n=a;return i=void 0,a=void 0,c=e.apply(t,n),c}function u(){let e=Date.now()-s;e<t&&e>=0?o=setTimeout(u,t-e):(o=void 0,r||(c=l()))}let d=function(...e){if(i&&this!==i&&Object.getPrototypeOf(this)===Object.getPrototypeOf(i))throw Error(`Debounced method called with different contexts of the same prototype.`);i=this,a=e,s=Date.now();let n=r&&!o;return o||=setTimeout(u,t),n&&(c=l()),c};return Object.defineProperty(d,`isPending`,{get(){return o!==void 0}}),d.clear=()=>{o&&=(clearTimeout(o),void 0)},d.flush=()=>{o&&d.trigger()},d.trigger=()=>{c=l(),d.clear()},d}t.exports.debounce=n,t.exports=n}))(),1),Ot=function(e){e===void 0&&(e={});var{crosshairCursor:t=!1}=e,n=[];e.closeBracketsKeymap!==!1&&(n=n.concat(vt)),e.defaultKeymap!==!1&&(n=n.concat(mt)),e.searchKeymap!==!1&&(n=n.concat(pt)),e.historyKeymap!==!1&&(n=n.concat(ct)),e.foldKeymap!==!1&&(n=n.concat(Ct)),e.completionKeymap!==!1&&(n=n.concat(ut)),e.lintKeymap!==!1&&(n=n.concat(st));var r=[];return e.lineNumbers!==!1&&r.push(Ze()),e.highlightActiveLineGutter!==!1&&r.push(Qe()),e.highlightSpecialChars!==!1&&r.push(nt()),e.history!==!1&&r.push(lt()),e.foldGutter!==!1&&r.push(Xe()),e.drawSelection!==!1&&r.push(Tt()),e.dropCursor!==!1&&r.push(Ye()),e.allowMultipleSelections!==!1&&r.push(J.allowMultipleSelections.of(!0)),e.indentOnInput!==!1&&r.push(ft()),e.syntaxHighlighting!==!1&&r.push(dt(ot,{fallback:!0})),e.bracketMatching!==!1&&r.push(wt()),e.closeBrackets!==!1&&r.push(ht()),e.autocompletion!==!1&&r.push(yt()),e.rectangularSelection!==!1&&r.push(_t()),t!==!1&&r.push(tt()),e.highlightActiveLine!==!1&&r.push(rt()),e.highlightSelectionMatches!==!1&&r.push(gt()),e.tabSize&&typeof e.tabSize==`number`&&r.push(Je.of(` `.repeat(e.tabSize))),r.concat([it.of(n.flat())]).filter(Boolean)},kt=`#e5c07b`,At=`#e06c75`,jt=`#56b6c2`,Mt=`#ffffff`,X=`#abb2bf`,Nt=`#7d8799`,Pt=`#61afef`,Ft=`#98c379`,It=`#d19a66`,Lt=`#c678dd`,Rt=`#21252b`,zt=`#2c313a`,Bt=`#282c34`,Vt=`#353a42`,Ht=`#3E4451`,Ut=`#528bff`,Wt=[K.theme({"&":{color:X,backgroundColor:Bt},".cm-content":{caretColor:Ut},".cm-cursor, .cm-dropCursor":{borderLeftColor:Ut},"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:Ht},".cm-panels":{backgroundColor:Rt,color:X},".cm-panels.cm-panels-top":{borderBottom:`2px solid black`},".cm-panels.cm-panels-bottom":{borderTop:`2px solid black`},".cm-searchMatch":{backgroundColor:`#72a1ff59`,outline:`1px solid #457dff`},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:`#6199ff2f`},".cm-activeLine":{backgroundColor:`#6699ff0b`},".cm-selectionMatch":{backgroundColor:`#aafe661a`},"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket":{backgroundColor:`#bad0f847`},".cm-gutters":{backgroundColor:Bt,color:Nt,border:`none`},".cm-activeLineGutter":{backgroundColor:zt},".cm-foldPlaceholder":{backgroundColor:`transparent`,border:`none`,color:`#ddd`},".cm-tooltip":{border:`none`,backgroundColor:Vt},".cm-tooltip .cm-tooltip-arrow:before":{borderTopColor:`transparent`,borderBottomColor:`transparent`},".cm-tooltip .cm-tooltip-arrow:after":{borderTopColor:Vt,borderBottomColor:Vt},".cm-tooltip-autocomplete":{"& > ul > li[aria-selected]":{backgroundColor:zt,color:X}}},{dark:!0}),dt(St.define([{tag:q.keyword,color:Lt},{tag:[q.name,q.deleted,q.character,q.propertyName,q.macroName],color:At},{tag:[q.function(q.variableName),q.labelName],color:Pt},{tag:[q.color,q.constant(q.name),q.standard(q.name)],color:It},{tag:[q.definition(q.name),q.separator],color:X},{tag:[q.typeName,q.className,q.number,q.changed,q.annotation,q.modifier,q.self,q.namespace],color:kt},{tag:[q.operator,q.operatorKeyword,q.url,q.escape,q.regexp,q.link,q.special(q.string)],color:jt},{tag:[q.meta,q.comment],color:Nt},{tag:q.strong,fontWeight:`bold`},{tag:q.emphasis,fontStyle:`italic`},{tag:q.strikethrough,textDecoration:`line-through`},{tag:q.link,color:Nt,textDecoration:`underline`},{tag:q.heading,fontWeight:`bold`,color:At},{tag:[q.atom,q.bool,q.special(q.variableName)],color:It},{tag:[q.processingInstruction,q.string,q.inserted],color:Ft},{tag:q.invalid,color:Mt}]))],Gt=K.theme({"&":{backgroundColor:`#fff`}},{dark:!1}),Kt=function(e){e===void 0&&(e={});var{indentWithTab:t=!0,editable:n=!0,readOnly:r=!1,theme:i=`light`,placeholder:a=``,basicSetup:o=!0}=e,s=[];switch(t&&s.unshift(it.of([at])),o&&(typeof o==`boolean`?s.unshift(Ot()):s.unshift(Ot(o))),a&&s.unshift(et(a)),i){case`light`:s.push(Gt);break;case`dark`:s.push(Wt);break;case`none`:break;default:s.push(i);break}return n===!1&&s.push(K.editable.of(!1)),r&&s.push(J.readOnly.of(!0)),[...s]},qt=e=>({line:e.state.doc.lineAt(e.state.selection.main.from),lineCount:e.state.doc.lines,lineBreak:e.state.lineBreak,length:e.state.doc.length,readOnly:e.state.readOnly,tabSize:e.state.tabSize,selection:e.state.selection,selectionAsSingle:e.state.selection.asSingle().main,ranges:e.state.selection.ranges,selectionCode:e.state.sliceDoc(e.state.selection.main.from,e.state.selection.main.to),selections:e.state.selection.ranges.map(t=>e.state.sliceDoc(t.from,t.to)),selectedText:e.state.selection.ranges.some(e=>!e.empty)}),Jt=class{constructor(e,t){this.timeLeftMS=void 0,this.timeoutMS=void 0,this.isCancelled=!1,this.isTimeExhausted=!1,this.callbacks=[],this.timeLeftMS=t,this.timeoutMS=t,this.callbacks.push(e)}tick(){if(!this.isCancelled&&!this.isTimeExhausted&&(this.timeLeftMS--,this.timeLeftMS<=0)){this.isTimeExhausted=!0;var e=this.callbacks.slice();this.callbacks.length=0,e.forEach(e=>{try{e()}catch(e){console.error(`TimeoutLatch callback error:`,e)}})}}cancel(){this.isCancelled=!0,this.callbacks.length=0}reset(){this.timeLeftMS=this.timeoutMS,this.isCancelled=!1,this.isTimeExhausted=!1}get isDone(){return this.isCancelled||this.isTimeExhausted}},Yt=class{constructor(){this.interval=null,this.latches=new Set}add(e){this.latches.add(e),this.start()}remove(e){this.latches.delete(e),this.latches.size===0&&this.stop()}start(){this.interval===null&&(this.interval=setInterval(()=>{this.latches.forEach(e=>{e.tick(),e.isDone&&this.remove(e)})},1))}stop(){this.interval!==null&&(clearInterval(this.interval),this.interval=null)}},Xt=null,Zt=()=>typeof window>`u`?new Yt:(Xt||=new Yt,Xt),Qt=$e.define(),$t=200,en=[];function tn(e){var{value:t,selection:n,onChange:r,onStatistics:i,onCreateEditor:a,onUpdate:o,extensions:s=en,autoFocus:c,theme:l=`light`,height:u=null,minHeight:d=null,maxHeight:f=null,width:p=null,minWidth:m=null,maxWidth:h=null,placeholder:g=``,editable:_=!0,readOnly:v=!1,indentWithTab:y=!0,basicSetup:b=!0,root:x,initialState:S}=e,[C,w]=(0,Y.useState)(),[T,E]=(0,Y.useState)(),[D,O]=(0,Y.useState)(),k=(0,Y.useState)(()=>({current:null}))[0],A=(0,Y.useState)(()=>({current:null}))[0],j=K.theme({"&":{height:u,minHeight:d,maxHeight:f,width:p,minWidth:m,maxWidth:h},"& .cm-scroller":{height:`100% !important`}}),M=[K.updateListener.of(e=>{e.docChanged&&typeof r==`function`&&!e.transactions.some(e=>e.annotation(Qt))&&(k.current?k.current.reset():(k.current=new Jt(()=>{if(A.current){var e=A.current;A.current=null,e()}k.current=null},$t),Zt().add(k.current)),r(e.state.doc.toString(),e)),i&&i(qt(e))}),j,...Kt({theme:l,editable:_,readOnly:v,placeholder:g,indentWithTab:y,basicSetup:b})];return o&&typeof o==`function`&&M.push(K.updateListener.of(o)),M=M.concat(s),(0,Y.useLayoutEffect)(()=>{if(C&&!D){var e={doc:t,selection:n,extensions:M},r=S?J.fromJSON(S.json,e,S.fields):J.create(e);if(O(r),!T){var i=new K({state:r,parent:C,root:x});E(i),a&&a(i,r)}}return()=>{T&&(O(void 0),E(void 0))}},[C,D]),(0,Y.useEffect)(()=>{e.container&&w(e.container)},[e.container]),(0,Y.useEffect)(()=>()=>{T&&(T.destroy(),E(void 0)),k.current&&=(k.current.cancel(),null)},[T]),(0,Y.useEffect)(()=>{c&&T&&T.focus()},[c,T]),(0,Y.useEffect)(()=>{T&&T.dispatch({effects:bt.reconfigure.of(M)})},[l,s,u,d,f,p,m,h,g,_,v,y,b,r,o]),(0,Y.useEffect)(()=>{if(t!==void 0){var e=T?T.state.doc.toString():``;if(T&&t!==e){var n=k.current&&!k.current.isDone,r=()=>{T&&t!==T.state.doc.toString()&&T.dispatch({changes:{from:0,to:T.state.doc.toString().length,insert:t||``},annotations:[Qt.of(!0)]})};n?A.current=r:r()}}},[t,T]),{state:D,setState:O,view:T,setView:E,container:C,setContainer:w}}var Z=r(),nn=[`className`,`value`,`selection`,`extensions`,`onChange`,`onStatistics`,`onCreateEditor`,`onUpdate`,`autoFocus`,`theme`,`height`,`minHeight`,`maxHeight`,`width`,`minWidth`,`maxWidth`,`basicSetup`,`placeholder`,`indentWithTab`,`editable`,`readOnly`,`root`,`initialState`],rn=(0,Y.forwardRef)((e,t)=>{var{className:n,value:r=``,selection:i,extensions:a=[],onChange:o,onStatistics:s,onCreateEditor:c,onUpdate:l,autoFocus:u,theme:d=`light`,height:f,minHeight:p,maxHeight:m,width:h,minWidth:g,maxWidth:_,basicSetup:v,placeholder:y,indentWithTab:b,editable:x,readOnly:S,root:C,initialState:w}=e,T=Se(e,nn),E=(0,Y.useRef)(null),{state:D,view:O,container:k,setContainer:A}=tn({root:C,value:r,autoFocus:u,theme:d,height:f,minHeight:p,maxHeight:m,width:h,minWidth:g,maxWidth:_,basicSetup:v,placeholder:y,indentWithTab:b,editable:x,readOnly:S,selection:i,onChange:o,onStatistics:s,onCreateEditor:c,onUpdate:l,extensions:a,initialState:w});(0,Y.useImperativeHandle)(t,()=>({editor:E.current,state:D,view:O}),[E,k,D,O]);var j=(0,Y.useCallback)(e=>{E.current=e,A(e)},[A]);if(typeof r!=`string`)throw Error(`value must be typeof string but got `+typeof r);return(0,Z.jsx)(`div`,N({ref:j,className:(typeof d==`string`?`cm-theme-`+d:`cm-theme`)+(n?` `+n:``)},T))});rn.displayName=`CodeMirror`;var an=e=>{var{theme:t,settings:n={},styles:r=[]}=e,i={".cm-gutters":{}},a={};n.background&&(a.backgroundColor=n.background),n.backgroundImage&&(a.backgroundImage=n.backgroundImage),n.foreground&&(a.color=n.foreground),n.fontSize&&(a.fontSize=n.fontSize),(n.background||n.foreground)&&(i[`&`]=a),n.fontFamily&&(i[`&.cm-editor .cm-scroller`]={fontFamily:n.fontFamily}),n.gutterBackground&&(i[`.cm-gutters`].backgroundColor=n.gutterBackground),n.gutterForeground&&(i[`.cm-gutters`].color=n.gutterForeground),n.gutterBorder&&(i[`.cm-gutters`].borderRightColor=n.gutterBorder),n.caret&&(i[`.cm-content`]={caretColor:n.caret},i[`.cm-cursor, .cm-dropCursor`]={borderLeftColor:n.caret});var o={};return n.gutterActiveForeground&&(o.color=n.gutterActiveForeground),n.lineHighlight&&(i[`.cm-activeLine`]={backgroundColor:n.lineHighlight},o.backgroundColor=n.lineHighlight),i[`.cm-activeLineGutter`]=o,n.selection&&(i[`&.cm-focused .cm-selectionBackground, & .cm-line::selection, & .cm-selectionLayer .cm-selectionBackground, .cm-content ::selection`]={background:n.selection+` !important`}),n.selectionMatch&&(i[`& .cm-selectionMatch`]={backgroundColor:n.selectionMatch}),[K.theme(i,{dark:t===`dark`}),dt(St.define(r))]},on={background:`#faf8f5`,foreground:`#b29762`,caret:`#93abdc`,selection:`#e3dcce`,selectionMatch:`#e3dcce`,gutterBackground:`#faf8f5`,gutterForeground:`#cdc4b1`,gutterBorder:`transparent`,lineHighlight:`#ddceb154`},sn=[{tag:[q.comment,q.bracket],color:`#b6ad9a`},{tag:[q.atom,q.number,q.keyword,q.link,q.attributeName,q.quote],color:`#063289`},{tag:[q.emphasis,q.heading,q.tagName,q.propertyName,q.variableName],color:`#2d2006`},{tag:[q.typeName,q.url,q.string],color:`#896724`},{tag:[q.operator,q.string],color:`#1659df`},{tag:[q.propertyName],color:`#b29762`},{tag:[q.unit,q.punctuation],color:`#063289`}],cn=(e=>{var{theme:t=`light`,settings:n={},styles:r=[]}=e||{};return an({theme:t,settings:N({},on,n),styles:[...sn,...r]})})(),ln={background:`#2a2734`,foreground:`#6c6783`,caret:`#ffad5c`,selection:`#91ff6c26`,selectionMatch:`#91ff6c26`,gutterBackground:`#2a2734`,gutterForeground:`#545167`,lineHighlight:`#36334280`},un=[{tag:[q.comment,q.bracket],color:`#6c6783`},{tag:[q.atom,q.number,q.keyword,q.link,q.attributeName,q.quote],color:`#ffcc99`},{tag:[q.emphasis,q.heading,q.tagName,q.propertyName,q.className,q.variableName],color:`#eeebff`},{tag:[q.typeName,q.url],color:`#7a63ee`},{tag:q.operator,color:`#ffad5c`},{tag:q.string,color:`#ffb870`},{tag:[q.propertyName],color:`#9a86fd`},{tag:[q.unit,q.punctuation],color:`#e09142`}],dn=(e=>{var{theme:t=`dark`,settings:n={},styles:r=[]}=e||{};return an({theme:t,settings:N({},ln,n),styles:[...un,...r]})})(),fn=G(`aside`)(({theme:e})=>({height:`50px`,backgroundColor:e.palette.background.paper,borderTopRightRadius:e.shape.borderRadiusMedium,borderTopLeftRadius:e.shape.borderRadiusMedium,padding:e.spacing(1,2),color:e.palette.text.primary,display:`flex`,justifyContent:`space-between`,alignItems:`center`,border:`1px solid ${e.palette.divider}`})),pn=G(`div`)(({theme:e,style:t})=>({width:e.spacing(3),height:e.spacing(3),display:`flex`,alignItems:`center`,color:e.palette.background.paper,justifyContent:`center`,transition:`background-color 0.5s ease-in-out`,borderRadius:`50%`,...t})),mn=G(`div`)(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.error.dark,marginRight:e.spacing(1)})),hn=()=>(0,Z.jsx)(pn,{style:{backgroundColor:u().palette.success.main},children:(0,Z.jsx)(Ee,{sx:e=>({width:e.spacing(2),height:e.spacing(2)})})}),gn=()=>(0,Z.jsx)(pn,{style:{backgroundColor:u().palette.error.main},children:(0,Z.jsx)(ze,{})}),_n=({context:e,setContext:t,error:n})=>{let{themeMode:r}=(0,Y.useContext)(Oe),i=u(),o=(0,Y.useCallback)(e=>{t(e)},[t]),s=`calc(6 * ${i.typography.body1.fontSize} * ${i.typography.body1.lineHeight}) + 8px`;return(0,Z.jsxs)(P,{sx:{width:`100%`},children:[(0,Z.jsxs)(fn,{children:[`JSON`,(0,Z.jsx)(a,{condition:!!n,show:(0,Z.jsxs)(P,{sx:e=>({display:`flex`,alignItems:`center`}),children:[(0,Z.jsx)(mn,{children:n}),(0,Z.jsx)(gn,{})]}),elseShow:(0,Z.jsx)(hn,{})})]}),(0,Z.jsx)(rn,{value:e,minHeight:s,theme:r===`dark`?dn:cn,extensions:[xt()],onChange:o,style:{border:`1px solid ${i.palette.divider}`,borderTop:`none`},placeholder:JSON.stringify({currentTime:`2022-07-04T14:13:03.929Z`,appName:`playground`,userId:`test`,remoteAddress:`127.0.0.1`},null,2)})]})};function vn(e){return Array.isArray(e)?e:[e]}var yn=e=>!e||e.length===0||e.length===1&&e[0]===`*`?`*`:vn(e),bn=e=>vn(e),xn=e=>{let t=Sn(e);return t.length>0?t[0]:``},Sn=e=>e.filter(({enabled:e})=>!!e).sort((e,t)=>e.sortOrder-t.sortOrder).map(({name:e})=>e),Cn=(e,t)=>e?`100%`:t&&!e?`60%`:`50%`,wn=e=>typeof e==`string`?!0:Array.isArray(e)?e.every(e=>typeof e==`string`):!1,Tn=e=>{let t=new Set([`appName`,`environment`,`userId`,`sessionId`,`remoteAddress`,`currentTime`,`properties`]),n={...e},r=!1;for(let i in e)t.has(i)||(n.properties||={},n.properties[i]=e[i],delete n[i],r=!0);return!r&&!e.properties&&delete n.properties,n},En=e=>{let[t]=e.split(`.`),[n,r]=t.split(`:`);if(!n||!r)throw Error(`Invalid token format`);if(r===`*`)throw Error(`Admin tokens are not supported in the playground`)},Dn=e=>{let[t]=e.split(`.`);return t.split(`:`)},On=e=>me({mode:`all`},e),kn=e=>{let t=e=>e.toSorted((e,t)=>e.sortOrder-t.sortOrder).map(e=>({key:e.name,label:e.name})),n=e.reduce(({project:e,global:t},n)=>(n.project?e.push(n):t.push(n),{project:e,global:t}),{project:[],global:[]}),r=[];return n.project.length&&r.push({groupHeader:`Project context fields`,options:t(n.project)}),n.global.length&&r.push({groupHeader:`Global context fields`,options:t(n.global)}),r},An=({context:e,setContext:t})=>{let n=u(),{setToastData:r}=A(),{context:i}=On(),a=kn(i),[s,c]=(0,Y.useState)(),[l,d]=(0,Y.useState)(!1),[p,m]=(0,Y.useState)(``),[h,g]=(0,Y.useState)(``),_=(0,Y.useMemo)(()=>(0,Dt.default)(e=>{if(!e)return c(void 0);try{let t=JSON.parse(e);d(t[p]!==void 0||t?.properties?.[p]!==void 0)}catch(e){return c(O(e))}return c(void 0)},250),[c,p,d]);(0,Y.useEffect)(()=>{_(e)},[_,e]);let v=()=>{try{let n=JSON.parse(e||`{}`);t(JSON.stringify(Tn({...n,[p]:h}),null,2));let r=i.find(e=>e.name===p);if(r?.legalValues&&r.legalValues.length>0||p===`currentTime`)return g(``)}catch(e){r({type:`error`,text:`Error parsing context: ${O(e)}`})}},y=(e,t)=>{if(wn(t)){if(Array.isArray(t))return g((t||[]).length>1?t.join(`,`):t[0]);g(t)}},b=()=>{if(!h||h===``)return[];let e=(i.find(e=>e.name===p)?.legalValues||[]).length>1;return h.includes(`,`)&&e?h.split(`,`):[h]};return(0,Z.jsxs)(P,{children:[(0,Z.jsx)(P,{sx:{display:`flex`,alignItems:`center`,mb:2},children:(0,Z.jsx)(H,{variant:`body2`,color:n.palette.text.primary,sx:{ml:1},children:`Unleash context`})}),(0,Z.jsxs)(P,{sx:{display:`flex`,gap:2,flexWrap:`wrap`,mb:2},children:[(0,Z.jsx)(f,{label:`Context field`,labelId:`context-field-label`,id:`context-field`,value:p,onChange:e=>{if(m(e||``),e===`currentTime`)return g(new Date().toISOString());g(``)},variant:`outlined`,size:`small`,sx:{width:200,maxWidth:`100%`},options:a}),(()=>{if(p===`currentTime`){let e=ke(h);return(0,Z.jsx)(W,{id:`date`,label:`Date`,size:`small`,type:`datetime-local`,value:Ne(e?e.toISOString():new Date().toISOString()),sx:{width:200,maxWidth:`100%`},onChange:e=>{let t=ke(e.target.value)?.toISOString();t&&g(t)},InputLabelProps:{shrink:!0},required:!0})}let e=i.find(e=>e.name===p);return e?.legalValues&&e.legalValues.length>0?(0,Z.jsx)(o,{disablePortal:!0,limitTags:3,id:`context-legal-values`,multiple:!0,options:e.legalValues.map(({value:e})=>e),disableCloseOnSelect:!0,size:`small`,value:b(),onChange:y,getOptionLabel:e=>e,renderOption:(e,t,{selected:n})=>(0,Z.jsxs)(`li`,{...e,children:[(0,Z.jsx)(Ie,{icon:(0,Z.jsx)(Fe,{fontSize:`small`}),checkedIcon:(0,Z.jsx)(C,{fontSize:`small`}),sx:e=>({marginRight:e.spacing(.5)}),checked:n}),t]}),sx:{width:370,maxWidth:`100%`},renderInput:e=>(0,Z.jsx)(W,{...e,label:`Value`})}):(0,Z.jsx)(W,{label:`Value`,id:`context-value`,sx:{width:370,maxWidth:`100%`},placeholder:`value1,value2,value3`,size:`small`,value:h,onChange:e=>g(e.target.value||``)})})(),(0,Z.jsx)(F,{variant:`outlined`,disabled:!p||!!s,onClick:v,sx:{width:`95px`,maxHeight:`40px`},children:`${l?`Replace`:`Add`} `})]}),(0,Z.jsx)(_n,{context:e,setContext:t,error:s})]})},jn=({environments:e,setEnvironments:t,availableEnvironments:n,disabled:r})=>{let i=[...n.map(e=>({label:e,id:e}))],a=i.filter(({id:t})=>e.includes(t));return(0,Z.jsx)(o,{disablePortal:!0,limitTags:3,id:`environment`,multiple:!0,options:i,sx:{flex:1},renderInput:e=>(0,Z.jsx)(W,{...e,label:`Environments`}),renderOption:te,renderTags:(e,t)=>e.map((e,n)=>{let{key:r,...i}=t({index:n});return(0,Z.jsx)(ge,{size:`small`,...i,label:e.label},r)}),getOptionLabel:({label:e})=>e,disableCloseOnSelect:!1,size:`small`,value:a,onChange:(e,n,r)=>{let i=n;return r===`clear`||i===null?t([]):Array.isArray(i)?i.length===0?t([]):t(i.map(({id:e})=>e)):t([i.id])},disabled:r,"data-testid":`PLAYGROUND_ENVIRONMENT_SELECT`})},Mn={label:`ALL`,id:`*`},Nn=G(Ue)({fontSize:`1.25rem`}),Pn=G(Ae)(()=>({width:`100%`})),Fn=G(P)(({theme:e})=>({display:`grid`,columnGap:e.spacing(2),rowGap:e.spacing(2),gridTemplateColumns:`1fr`,[e.breakpoints.up(`md`)]:{gridTemplateColumns:`1fr 1fr`}})),In=G(Pn)(({theme:e})=>({"& label":{WebkitTextFillColor:e.palette.text.secondary},"& input.Mui-disabled":{WebkitTextFillColor:e.palette.text.secondary}})),Ln=({environments:e,projects:t,token:n,setProjects:r,setEnvironments:i,setToken:o,availableEnvironments:s,changeRequest:c,onClearChangeRequest:l})=>{let d=u(),{tokens:f}=qe(),[p,m]=(0,Y.useState)(),{projects:h}=he(),g=[Mn,...h.map(({name:e,id:t})=>({label:e,id:t}))],_=async e=>{let t=e.target.value;if(o?.(t),t===``){T();return}try{En(t),m(void 0),v(t)}catch(e){m(e.message)}},v=e=>{let[t,n]=Dn(e);switch(i([n]),t){case`[]`:S(e);break;case`*`:C();break;default:w(t)}},b=e=>{!e.projects||e.projects===`*`?r([Mn.id]):typeof e.projects==`string`?r([e.projects]):Array.isArray(e.projects)&&r(e.projects)},S=e=>{let t=f.find(({secret:t})=>t===e);t?b(t):m(`Invalid token. Ensure you use a valid token from this Unleash instance.`)},C=()=>{r([Mn.id])},w=e=>{g.map(e=>e.id).includes(e)?r([e]):m(`Invalid token. Project ${e} does not exist.`)},T=()=>{m(void 0)};return(0,Z.jsxs)(P,{sx:{pb:2},children:[(0,Z.jsx)(P,{sx:{display:`flex`,alignItems:`center`,mb:2},children:(0,Z.jsx)(H,{variant:`body2`,color:d.palette.text.primary,sx:{ml:1},children:`Access configuration`})}),(0,Z.jsxs)(Fn,{children:[(0,Z.jsx)(P,{children:(0,Z.jsx)(Ge,{arrow:!0,title:n?`Environment is automatically selected because you are using a token`:`Select environments to use in the playground`,children:(0,Z.jsx)(P,{children:(0,Z.jsx)(jn,{environments:e,setEnvironments:i,availableEnvironments:s,disabled:!!(n||c)})})})}),(0,Z.jsx)(P,{children:(0,Z.jsx)(Ge,{arrow:!0,title:n?`Project is automatically selected because you are using a token`:`Select projects to use in the playground`,children:(0,Z.jsx)(x,{selectedProjects:t,onChange:r,dataTestId:`PLAYGROUND_PROJECT_SELECT`,disabled:!!(n||c),limitTags:3})})}),(0,Z.jsx)(P,{children:(0,Z.jsx)(Pn,{label:`API token`,value:n||(c?` `:``),onChange:_,type:`text`,error:!!p,errorText:p,placeholder:`Enter your API token`,"data-testid":`PLAYGROUND_TOKEN_INPUT`,InputProps:{endAdornment:n?(0,Z.jsx)(y,{position:`end`,"data-testid":`TOKEN_INPUT_CLEAR_BTN`,children:(0,Z.jsx)(L,{"aria-label":`clear API token`,onClick:()=>{o?.(``),T()},edge:`end`,children:(0,Z.jsx)(Nn,{})})}):null},disabled:!!c})}),(0,Z.jsx)(a,{condition:!!c,show:(0,Z.jsxs)(P,{sx:{display:`flex`,gap:2},children:[(0,Z.jsx)(P,{sx:{flex:1},children:(0,Z.jsx)(In,{label:`Change request`,value:c?`Change request #${c}`:``,onChange:()=>{},type:`text`,disabled:!0,InputProps:{endAdornment:(0,Z.jsx)(y,{position:`end`,children:(0,Z.jsx)(L,{"aria-label":`clear Change request results`,onClick:l,edge:`end`,children:(0,Z.jsx)(Nn,{})})})}})}),(0,Z.jsx)(F,{variant:`outlined`,size:`small`,to:`/projects/${t[0]}/change-requests/${c}`,component:oe,children:`View change request`})]})})]})]})},Rn=({availableEnvironments:e,environments:t,onSubmit:n,projects:r,token:i,setToken:a,setProjects:o,setEnvironments:s,context:c,setContext:l,changeRequest:u,onClearChangeRequest:d})=>(0,Z.jsxs)(P,{component:`form`,onSubmit:n,sx:{display:`flex`,flexDirection:`column`},children:[(0,Z.jsx)(Ln,{environments:Array.isArray(t)?t:[t],projects:r,token:i,setToken:a,setEnvironments:s,setProjects:o,availableEnvironments:e.map(({name:e})=>e),changeRequest:u,onClearChangeRequest:d}),(0,Z.jsx)(An,{context:c,setContext:l}),(0,Z.jsx)(P,{sx:{mt:2,display:`flex`,alignItems:`center`,justifyContent:`space-between`},children:(0,Z.jsx)(F,{variant:`contained`,size:`large`,type:`submit`,sx:{marginLeft:`auto`},children:`Try configuration`})})]}),zn=G(`div`)(({style:e,theme:t})=>({width:`25px`,height:`25px`,borderRadius:`50%`,color:t.palette.common.white,display:`flex`,alignItems:`center`,justifyContent:`center`,fontWeight:`bold`,...e})),Bn=({style:e,children:t,type:n})=>{let r=u(),i={backgroundColor:r.palette.background.alternative,color:r.palette.common.white};return n===`secondary`&&(i.backgroundColor=r.palette.background.paper,i.color=r.palette.text.secondary),(0,Z.jsx)(zn,{style:{...i,...e},children:t})},Vn=({headerText:e,bodyText:t,sectionNumber:n})=>(0,Z.jsx)(P,{sx:{display:`flex`,alignItems:`flex-start`,mt:2,flexDirection:`column`},children:(0,Z.jsxs)(P,{sx:{display:`flex`},children:[(0,Z.jsx)(P,{children:(0,Z.jsx)(Bn,{children:n})}),(0,Z.jsxs)(P,{sx:{ml:2,display:`flex`,flexDirection:`column`},children:[(0,Z.jsx)(H,{variant:`body1`,sx:{fontWeight:`bold`},children:e}),(0,Z.jsx)(a,{condition:!!t,show:(0,Z.jsx)(H,{variant:`body1`,sx:{mt:1},children:t})})]})]})}),Hn=()=>(0,Z.jsxs)(P,{sx:{ml:4},children:[(0,Z.jsx)(H,{variant:`body1`,children:`Unleash playground is for helping you to understand how Unleash works, how feature flags are evaluated and for you to easily debug your feature flags.`}),(0,Z.jsx)(re,{sx:{mt:2,mb:2}}),(0,Z.jsx)(H,{variant:`body1`,sx:{mb:1},children:`What you need to do is:`}),(0,Z.jsx)(Vn,{headerText:`Select in which environment you want to test your feature flag configuration`,bodyText:`You can also specify specific projects, or check flags in all projects.`,sectionNumber:`1`}),(0,Z.jsx)(Vn,{headerText:`Select a context field that you'd like to check`,bodyText:`You can configure as many context fields as you want. You can also leave the context empty to test against an empty context.`,sectionNumber:`2`}),(0,Z.jsx)(Vn,{headerText:`Submit the form to try the configuration`,bodyText:`The results of evaluating your feature flags will appear after you submit the form. Then view the results.`,sectionNumber:`3`})]}),Un=I((0,Z.jsx)(`path`,{d:`M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2m1 17h-2v-2h2zm2.07-7.75-.9.92C13.45 12.9 13 13.5 13 15h-2v-.5c0-1.1.45-2.1 1.17-2.83l1.24-1.26c.37-.36.59-.86.59-1.41 0-1.1-.9-2-2-2s-2 .9-2 2H8c0-2.21 1.79-4 4-4s4 1.79 4 4c0 .88-.36 1.68-.93 2.25`}),`Help`),Wn=G(_)(({theme:e})=>({"& .MuiPaper-root":{borderRadius:e.shape.borderRadiusExtraLarge,border:`1px solid ${e.palette.divider}`,padding:e.spacing(8,4),maxWidth:`500px`}})),Gn=()=>{let[e,t]=(0,Y.useState)(null),n=e=>t(e.currentTarget),r=()=>t(null);return(0,Z.jsxs)(P,{children:[(0,Z.jsx)(L,{onClick:n,"aria-label":`Open Playground guidance`,children:(0,Z.jsx)(Un,{})}),(0,Z.jsxs)(Wn,{open:!!e,anchorEl:e,onClose:r,anchorOrigin:{vertical:`bottom`,horizontal:`center`},transformOrigin:{vertical:`top`,horizontal:`center`},sx:e=>({zIndex:e.zIndex.tooltip,background:`none`}),children:[(0,Z.jsx)(L,{onClick:r,sx:{position:`absolute`,right:25,top:15},children:(0,Z.jsx)(j,{})}),(0,Z.jsx)(Hn,{})]})]})},Q=Ke(),Kn=e=>(0,Z.jsx)(`svg`,{width:14,height:14,viewBox:`0 0 14 14`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,...e,children:(0,Z.jsx)(`path`,{fillRule:`evenodd`,clipRule:`evenodd`,d:`M8.84818 0.184159C8.56367 -0.0789547 8.1234 -0.0575747 7.86482 0.231912C7.60623 0.521399 7.62724 0.96937 7.91175 1.23248C9.48292 2.68551 10.6076 4.74934 10.6076 7C10.6076 9.25066 9.48292 11.3145 7.91175 12.7675C7.62724 13.0306 7.60623 13.4786 7.86482 13.7681C8.1234 14.0576 8.56367 14.079 8.84818 13.8158C10.6396 12.1592 11.9998 9.73702 11.9998 7C11.9998 4.26298 10.6396 1.84083 8.84818 0.184159ZM6.04105 2.23302C6.29109 1.93586 6.73054 1.90121 7.02259 2.15563C8.33146 3.29586 9.35426 5.02309 9.35426 6.99995C9.35426 8.97682 8.33145 10.7039 7.02259 11.8441C6.73054 12.0986 6.29109 12.0639 6.04105 11.7668C5.79101 11.4696 5.82506 11.0225 6.11711 10.768C7.19425 9.82969 7.96199 8.46967 7.96199 6.99995C7.96199 5.53021 7.19423 4.17007 6.11711 3.23173C5.82506 2.97731 5.79101 2.53017 6.04105 2.23302ZM6.56908 7.00015C6.56908 8.56492 5.3224 9.83342 3.78454 9.83342C2.24668 9.83342 1 8.56492 1 7.00015C1 5.43539 2.24668 4.16689 3.78454 4.16689C5.3224 4.16689 6.56908 5.43539 6.56908 7.00015Z`,fill:`currentColor`})}),qn=e=>(0,Z.jsx)(`svg`,{width:14,height:14,viewBox:`0 0 14 14`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,...e,children:(0,Z.jsx)(`path`,{fillRule:`evenodd`,clipRule:`evenodd`,d:`M8.84835 0.184159C8.56384 -0.0789547 8.12358 -0.0575747 7.86499 0.231912C7.6064 0.521399 7.62741 0.96937 7.91192 1.23248C9.4831 2.68551 10.6078 4.74934 10.6078 7C10.6078 7.40738 10.5709 7.80863 10.5012 8.20125L11.6597 9.35972C11.8783 8.60937 12 7.81877 12 7C12 4.26298 10.6397 1.84083 8.84835 0.184159ZM9.35443 6.99995L9.35418 7.0542L7.63252 5.33255C7.30901 4.52372 6.76993 3.80029 6.11728 3.23173C5.82523 2.97731 5.79118 2.53017 6.04122 2.23302C6.29127 1.93586 6.73072 1.90121 7.02276 2.15563C8.33164 3.29586 9.35443 5.02309 9.35443 6.99995ZM7.57827 8.79752L6.48307 7.70233C6.17606 8.92745 5.08437 9.83342 3.78471 9.83342C2.24685 9.83342 1.00017 8.56492 1.00017 7.00015C1.00017 5.69492 1.8676 4.59583 3.04789 4.26714L0.458225 1.67748C0.172794 1.39205 0.178843 0.923223 0.471736 0.63033C0.764629 0.337437 1.23345 0.331388 1.51889 0.616819L13.2132 12.3111C13.4986 12.5965 13.4926 13.0654 13.1997 13.3583C12.9068 13.6511 12.4379 13.6572 12.1525 13.3718L10.556 11.7753C10.0694 12.539 9.48623 13.2259 8.84835 13.8158C8.56384 14.079 8.12358 14.0576 7.86499 13.7681C7.6064 13.4786 7.62741 13.0306 7.91192 12.7675C8.54021 12.1865 9.0971 11.5078 9.53922 10.7585L8.62356 9.84281C8.20906 10.6195 7.64861 11.2989 7.02276 11.8441C6.73072 12.0986 6.29127 12.0639 6.04122 11.7668C5.79118 11.4696 5.82523 11.0225 6.11728 10.768C6.73471 10.2302 7.25048 9.55374 7.57827 8.79752Z`,fill:`currentColor`})}),Jn=e=>e===`unknown`||e===`unevaluated`?[V,`info`]:e===!0?[Kn,`success`]:[qn,`error`],$=({enabled:e,label:t,showIcon:n=!0})=>{let[r,i]=Jn(e);return(0,Z.jsx)(ie,{color:i,icon:n?(0,Z.jsx)(r,{"aria-hidden":!0,color:i,strokeWidth:`0.25`}):void 0,children:t})},Yn=G(P)(({theme:e})=>({display:`flex`,alignItems:`center`,padding:e.spacing(1,0,1,2)})),Xn=G(P)(()=>({marginRight:`auto`})),Zn=({feature:e})=>{let[t,n]=e?.isEnabled?[!0,`True`]:e?.strategies?.result===`unknown`?[`unknown`,`Unknown`]:[!1,`False`];return(0,Z.jsx)(Yn,{children:(0,Z.jsx)(Xn,{"data-loading":!0,children:(0,Z.jsx)($,{enabled:t,label:n,showIcon:t!==`unknown`})})})};function Qn(e){return e===void 0?!0:Object.values(e).every(e=>e&&typeof e==`object`?Qn(e):e===null)}var $n=e=>e.strategies?.data?.find(e=>!k.includes(e.name)),er=e=>e.strategies?.data?.length>0&&!e.strategies?.data?.find(e=>k.includes(e.name)),tr=G(`div`)({display:`flex`,justifyContent:`space-between`,width:`100%`}),nr=G(`hgroup`)(({theme:e})=>({display:`inline-flex`,alignItems:`center`,gap:e.spacing(1.5)})),rr=G(`h3`)(({theme:e})=>({fontWeight:`bold`,fontSize:e.typography.subtitle1.fontSize,margin:0})),ir=({feature:e,input:t,onClose:n})=>{let r=u(),[i,a,o]=e.isEnabled?[`This feature flag is True in ${t?.environment} because `,`at least one strategy is True`,r.palette.success.contrastText]:e.hasUnsatisfiedDependency&&!e.isEnabledInCurrentEnvironment?[`This feature flag is False in ${t?.environment} because `,`parent dependency is not satisfied and the environment is disabled`,r.palette.error.contrastText]:e.isEnabledInCurrentEnvironment?er(e)?[`This feature flag is Unknown in ${t?.environment} because `,`no strategies could be fully evaluated`,r.palette.warning.contrastText]:$n(e)?[`This feature flag is Unknown in ${t?.environment} because `,`not all strategies could be fully evaluated`,r.palette.warning.contrastText]:e.hasUnsatisfiedDependency?[`This feature flag is False in ${t?.environment} because `,`parent dependency is not satisfied`,r.palette.error.contrastText]:[`This feature flag is False in ${t?.environment} because `,`all strategies are either False or could not be fully evaluated`,r.palette.error.contrastText]:[`This feature flag is False in ${t?.environment} because `,`the environment is disabled`,r.palette.error.contrastText],s=Qn(t?.context)?`You did not provide a value for your context field in step 2 of the configuration`:void 0,l=$n(e)?`This feature uses custom strategies. Custom strategies can't be evaluated, so they will be marked accordingly.`:void 0,d=n&&(e=>{e.stopPropagation(),n()});return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(tr,{children:[(0,Z.jsxs)(nr,{children:[(0,Z.jsx)(rr,{children:e.name}),(0,Z.jsx)(`p`,{children:e?.strategies?.result===`unknown`?(0,Z.jsx)($,{enabled:`unknown`,label:`Unknown`,showIcon:!1}):(0,Z.jsx)($,{enabled:e.isEnabled,label:e.isEnabled?`True`:`False`})})]}),(0,Z.jsx)(L,{"aria-label":`Close`,onClick:d,children:(0,Z.jsx)(c,{})})]}),(0,Z.jsxs)(`p`,{children:[i,(0,Z.jsx)(H,{color:o,component:`span`,children:a}),`.`]}),s?(0,Z.jsx)(B,{color:`info`,children:s}):null,l?(0,Z.jsx)(B,{severity:`warning`,color:`info`,children:l}):null]})},ar=G(`div`,{shouldForwardProp:e=>e!==`variant`})(({theme:e,variant:t})=>({"--font-size":e.typography.body2.fontSize,display:`flex`,alignItems:`center`,gap:e.spacing(1),padding:e.spacing(.5,.25),color:t===`ok`?e.palette.success.dark:e.palette.error.dark,fontSize:`var(--font-size)`,svg:{fontSize:`calc(var(--font-size) * 1.25)`}})),or=()=>(0,Z.jsxs)(ar,{variant:`ok`,children:[(0,Z.jsx)(h,{"aria-hidden":`true`}),(0,Z.jsx)(`p`,{children:`Constraint met by value in context`})]}),sr=({text:e})=>(0,Z.jsxs)(ar,{variant:`error`,children:[(0,Z.jsx)(be,{"aria-hidden":`true`}),(0,Z.jsx)(`p`,{children:e})]}),cr=({constraint:e,input:t})=>{if(!e)return null;let n=()=>{let n=t?.context[e.contextName];return e.operator===`REGEX`&&n&&e.value?`Constraint not met – the value in the context ${e.contextName}: { ${n} } is not matching ${e.operator} ${e.value}`:n?`Constraint not met – the value in the context: { ${n} } is not ${e.operator} ${e.contextName}`:`Constraint not met – no value was specified for ${e.contextName}`};return(0,Z.jsx)(T,{children:(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(Ve,{...e}),e.result?(0,Z.jsx)(or,{}):(0,Z.jsx)(sr,{text:n()})]})})},lr=G(P)(({theme:e})=>({width:`auto`,height:`auto`,padding:e.spacing(2,3),borderRadius:e.shape.borderRadiusMedium,border:`1px solid ${e.palette.divider}`})),ur=({segment:e,input:t})=>(0,Z.jsx)(fe,{segment:e,constraintList:e.constraints.length>0?(0,Z.jsx)(D,{children:e.constraints.map(e=>(0,Z.jsx)(cr,{constraint:e,input:t},i(e)))}):void 0,isExpanded:!0}),dr=({strategyResult:e,input:t})=>{let{name:n,constraints:r,segments:a,parameters:o}=e,c=pe(e),{strategies:l}=M(),{isCustomStrategy:u,customStrategyParameters:d}=He(e,l),f=!!(a&&a.length>0),p=!!(r&&r?.length>0),m=n!==`default`&&Object.keys(s).includes(n);if(!o)return null;let h=[...f?a.map(e=>(0,Z.jsx)(ur,{segment:e,input:t},i(e))):[],...p?r.map(e=>(0,Z.jsx)(cr,{constraint:e,input:t},i(e))):[],m&&c.map((e,t)=>(0,Z.jsx)(T,{children:e},t)),u&&d.map((e,t)=>(0,Z.jsx)(T,{children:e},t)),n===`default`&&(0,Z.jsxs)(lr,{sx:{width:`100%`},children:[`The standard strategy is `,(0,Z.jsx)(ie,{color:`success`,children:`ON`}),` for all users.`]},`default-on`)].filter(Boolean),{variant:g,variants:_}=e.result;return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(D,{children:h}),_?.length?(0,Z.jsx)(xe,{variants:_,selected:g?.name}):null]})},fr=({strategy:e,input:t,className:n})=>{let{result:r}=e,a=r.evaluationStatus===`incomplete`||r.evaluationStatus===`unevaluated`?`Not evaluated`:r.enabled?`True`:`False`;return(0,Z.jsx)(je,{strategy:{...e,id:`${i(e)}`},strategyHeaderLevel:4,className:n,headerItemsLeft:e.disabled?null:(0,Z.jsx)($,{showIcon:!1,enabled:r.enabled,label:a}),children:(0,Z.jsx)(dr,{strategyResult:e,input:t})})},pr=G(`hgroup`)(({theme:e})=>({paddingBottom:e.spacing(2)})),mr=G(`h4`)(({theme:e})=>({fontWeight:`normal`,fontSize:e.typography.body1.fontSize,margin:0})),hr=G(`p`)(({theme:e})=>({fontWeight:`bold`,fontSize:e.typography.body2.fontSize})),gr=G(ve)(({theme:e})=>({marginInline:`calc(var(--popover-inline-padding) * -1)`,borderTop:`1px solid ${e.palette.divider}`,"> li:last-of-type":{paddingBottom:0}})),_r=({strategies:e,input:t,titlePrefix:n,infoText:r})=>e.length===0?null:(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(pr,{children:[(0,Z.jsx)(mr,{children:`${n?n.concat(` strategies`):`Strategies`} (${e?.length})`}),r?(0,Z.jsx)(hr,{children:r}):null]}),(0,Z.jsx)(gr,{children:e?.map((e,n)=>(0,Z.jsxs)(De,{children:[n>0?(0,Z.jsx)(We,{}):``,(0,Z.jsx)(fr,{strategy:e,input:t})]},e.id))})]}),vr=({feature:e})=>{if(!e?.strategies?.data)return null;let t;if(e.hasUnsatisfiedDependency&&!e.isEnabledInCurrentEnvironment)t=`If the environment was enabled and parent dependencies were satisfied`;else if(e.hasUnsatisfiedDependency)t=`If parent dependencies were satisfied`;else if(!e.isEnabledInCurrentEnvironment)t=`If the environment was enabled`;else return;return(0,Z.jsxs)(B,{severity:`info`,color:`info`,children:[t,`, then this feature flag would be`,` `,e.strategies?.result?`TRUE`:`FALSE`,` with strategies evaluated like this:`]})},yr=({feature:e,input:t})=>{let n=e.strategies?.data?.filter(e=>!e.disabled),r=e.strategies?.data?.filter(e=>e.disabled),i=r?.length>0;return(e?.strategies?.data.length??0)===0?(0,Z.jsx)(B,{severity:`info`,children:`There are no strategies added to this feature flag in the selected environment.`}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(vr,{feature:e}),(0,Z.jsx)(_r,{strategies:n||[],input:t,titlePrefix:i?`Enabled`:void 0}),i?(0,Z.jsx)(_r,{strategies:r,input:t,titlePrefix:`Disabled`,infoText:`Disabled strategies are not evaluated for the overall result.`}):null]})},br=G(`div`)(({theme:e})=>({alignItems:`flex-end`,color:e.palette.divider})),xr=({feature:e,input:t})=>{let[n,r]=(0,Y.useState)(!1),i=(0,Y.useRef)(null);return(0,Z.jsxs)(br,{children:[(0,Z.jsx)(L,{onClick:()=>{r(!n)},children:(0,Z.jsx)(V,{ref:i})}),(0,Z.jsxs)(_,{open:n,onClose:()=>r(!1),anchorEl:i.current,PaperProps:{sx:e=>({"--popover-inline-padding":e.spacing(4),paddingInline:`var(--popover-inline-padding)`,paddingBlock:e.spacing(3),display:`flex`,flexDirection:`column`,width:728,maxWidth:`100%`,height:`auto`,gap:e.spacing(3),overflowY:`auto`,backgroundColor:e.palette.background.elevation1,borderRadius:e.shape.borderRadius})},anchorOrigin:{vertical:`top`,horizontal:`right`},transformOrigin:{vertical:`center`,horizontal:`left`},children:[(0,Z.jsx)(ir,{feature:e,input:t,onClose:()=>r(!1)}),(0,Z.jsx)(yr,{feature:e,input:t})]})]})},Sr=e=>e.feature?(0,Z.jsx)(xr,{...e}):null,Cr=I((0,Z.jsx)(`path`,{d:`M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2m0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8m4.59-12.42L10 14.17l-2.59-2.58L6 13l4 4 8-8z`}),`CheckCircleOutlined`),wr=G(`div`)(({theme:e})=>({padding:e.spacing(4),maxWidth:`400px`})),Tr=G(H)(({theme:e})=>({marginBottom:e.spacing(2)})),Er=G(Cr)(({theme:e})=>({color:e.palette.success.main})),Dr=({variants:e,selectedVariant:t})=>{let n=u(),r=(0,Y.useMemo)(()=>e.map(e=>({name:e.name,weight:`${_e(e.weight)}%`,selected:e.name===t})),[e,t]),{getTableProps:i,getTableBodyProps:a,headerGroups:o,rows:s,prepareRow:c}=(0,Q.useTable)({initialState:(0,Y.useMemo)(()=>({sortBy:[{id:`name`,desc:!1}]}),[]),columns:Or,data:r,sortTypes:p,autoResetGlobalFilter:!1,autoResetSortBy:!1,disableSortRemove:!0},Q.useGlobalFilter,Q.useSortBy);return(0,Z.jsxs)(wr,{children:[(0,Z.jsx)(Tr,{variant:`subtitle2`,children:`Variant Information`}),(0,Z.jsx)(Tr,{variant:`body2`,children:`The following table shows the variants defined on this feature toggle and the variant result based on your context configuration.`}),(0,Z.jsx)(Tr,{variant:`body2`,children:`If you include "userId" or "sessionId" in your context, the variant will be the same every time because unleash uses these properties to ensure that the user receives the same experience.`}),(0,Z.jsxs)(Le,{...i(),rowHeight:`dense`,children:[(0,Z.jsx)(we,{headerGroups:o}),(0,Z.jsx)(Ce,{...a(),children:s.map(e=>{let t={};e.original.selected||(t.color=n.palette.text.secondary),c(e);let{key:r,...i}=e.getRowProps();return(0,Z.jsx)(ye,{hover:!0,...i,children:e.cells.map(e=>{let{key:n,...r}=e.getCellProps();return(0,Z.jsx)(Me,{...r,style:t,children:e.render(`Cell`)},n)})},r)})})]})]})},Or=[{id:`Icon`,Cell:({row:{original:{selected:e}}})=>(0,Z.jsx)(Z.Fragment,{children:(0,Z.jsx)(a,{condition:e,show:(0,Z.jsx)(se,{icon:(0,Z.jsx)(Er,{})})})}),maxWidth:25,disableGlobalFilter:!0},{Header:`Name`,accessor:`name`,searchable:!0,Cell:({row:{original:{name:e}}})=>(0,Z.jsx)(le,{children:e}),maxWidth:175,width:175},{Header:`Weight`,accessor:`weight`,sortType:`alphanumeric`,searchable:!0,maxWidth:75,Cell:({row:{original:{weight:e}}})=>(0,Z.jsx)(le,{children:e})}],kr=G(`div`)(()=>({maxWidth:`100%`,display:`flex`,alignItems:`center`,wordBreak:`break-all`})),Ar=({variant:e,variants:t,feature:n,isEnabled:r})=>{let i=u(),[o,s]=(0,Y.useState)(null),c=e=>s(e.currentTarget),l=()=>s(null),d=!!o;return(0,Z.jsxs)(kr,{children:[e,(0,Z.jsx)(a,{condition:!!t&&t.length>0&&r,show:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(L,{onClick:c,children:(0,Z.jsx)(V,{})}),(0,Z.jsx)(_,{open:d,id:`${n}-result-variants`,PaperProps:{sx:{borderRadius:`${i.shape.borderRadiusLarge}px`}},onClose:l,anchorEl:o,anchorOrigin:{vertical:`bottom`,horizontal:-320},children:(0,Z.jsx)(Dr,{variants:t,selectedVariant:e})})]})})]})},jr=({features:e})=>{let t=S(u().breakpoints.down(`sm`)),n=Object.keys(e[0].context).map(e=>({Header:R(e),accessor:t=>t.context[e],minWidth:160,Cell:d})),r=(0,Y.useMemo)(()=>[...n,{Header:`Variant`,id:`variant`,accessor:`variant.name`,sortType:`alphanumeric`,filterName:`variant`,maxWidth:200,Cell:({value:e,row:{original:{variant:t,feature:n,variants:r,isEnabled:i}}})=>(0,Z.jsx)(Ar,{variant:t?.enabled?e:``,variants:r,feature:n,isEnabled:i})},{id:`isEnabled`,Header:`isEnabled`,filterName:`isEnabled`,accessor:e=>e?.isEnabled?`true`:e?.strategies?.result===`unknown`?`unknown`:`false`,Cell:({row:e})=>(0,Z.jsx)(Zn,{feature:e.original}),sortType:`playgroundResultState`,maxWidth:120,sortInverted:!0},{Header:``,maxWidth:70,id:`info`,Cell:({row:e})=>(0,Z.jsx)(Sr,{feature:e.original,input:{environment:e.original.environment,context:e.original.context}})}],[]),{headerGroups:i,rows:a,prepareRow:o,setHiddenColumns:s}=(0,Q.useTable)({columns:r,data:e,sortTypes:p,autoResetGlobalFilter:!1,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0},Q.useGlobalFilter,Q.useFlexLayout,Q.useSortBy);m([{condition:t,columns:[`variant`]}],s,r);let c=(0,Y.useRef)(null);return(0,Z.jsx)(P,{ref:c,sx:{overflow:`auto`,maxHeight:`800px`},children:(0,Z.jsx)(z,{parentRef:c,rows:a,headerGroups:i,prepareRow:o})})},Mr=G(`div`,{})(({theme:e})=>({flexGrow:0,...Re,justifyContent:`flex-start`,margin:e.spacing(0,1.5)})),Nr=G(P)(({theme:e})=>({display:`flex`,flexDirection:`row`,gap:e.spacing(1)})),Pr=({value:e})=>{let t=u(),[n,r]=(0,Y.useState)(null),i=e=>r(e.currentTarget),o=()=>r(null),s=!!n,c=(e||[]).filter(e=>e.isEnabled),l=(e||[]).filter(e=>!e.isEnabled);return(0,Z.jsxs)(Mr,{children:[(0,Z.jsxs)(Nr,{children:[(0,Z.jsx)(a,{condition:c.length>0,show:(0,Z.jsx)($,{enabled:!0,label:`${c.length}`,showIcon:!0})}),(0,Z.jsx)(a,{condition:l.length>0,show:(0,Z.jsx)($,{enabled:!1,label:`${l.length}`,showIcon:!0})})]}),(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(L,{onClick:i,children:(0,Z.jsx)(V,{})}),(0,Z.jsxs)(_,{open:s,id:`${e}-result-details`,PaperProps:{sx:{borderRadius:`${t.shape.borderRadiusLarge}px`,padding:t.spacing(3)}},onClose:o,anchorEl:n,anchorOrigin:{vertical:`bottom`,horizontal:-320},children:[(0,Z.jsx)(H,{variant:`subtitle2`,sx:{mb:3},children:e[0].environment}),(0,Z.jsx)(jr,{features:e})]})]})]})},Fr=({features:e})=>{let t=Object.keys(e),n=e[t[0]],r=n[0].context,i=(0,Y.useMemo)(()=>n.map((n,r)=>({...Object.fromEntries(t.map(t=>[t,e[t][r]]))})),[JSON.stringify(e)]),a=Object.keys(r).map(e=>({Header:R(e),accessor:n=>n[t[0]].context[e],minWidth:160,Cell:d})),o=t.map(e=>({Header:e,accessor:t=>t[e]?.isEnabled?`true`:t[e]?.strategies?.result===`unknown`?`unknown`:`false`,Cell:({row:t})=>(0,Z.jsxs)(P,{sx:{display:`flex`},children:[(0,Z.jsx)(Zn,{feature:t.original[e]}),(0,Z.jsx)(Sr,{feature:t.original[e],input:{environment:t.original[e].environment,context:t.original[e].context}})]}),sortType:`playgroundResultState`,maxWidth:140})),{headerGroups:s,rows:c,prepareRow:l}=(0,Q.useTable)({columns:(0,Y.useMemo)(()=>[...a,...o],[]),data:i,sortTypes:p,autoResetGlobalFilter:!1,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0},Q.useGlobalFilter,Q.useFlexLayout,Q.useSortBy),u=(0,Y.useRef)(null);return(0,Z.jsx)(P,{ref:u,sx:{overflow:`auto`,maxHeight:`800px`},children:(0,Z.jsx)(z,{parentRef:u,rows:c,headerGroups:s,prepareRow:l})})},Ir=G(`div`,{})(({theme:e})=>({flexGrow:0,...Re,justifyContent:`flex-start`,margin:e.spacing(0,1.5)})),Lr=G(F)(({theme:e})=>({textAlign:`left`,textDecorationStyle:`dotted`,textDecorationLine:`underline`,textUnderlineOffset:e.spacing(.75),color:e.palette.neutral.dark,padding:0,fontWeight:`normal`})),Rr=({value:e})=>{let t=u(),[n,r]=(0,Y.useState)(null);return(0,Z.jsx)(Ir,{children:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Lr,{variant:`text`,onClick:e=>r(e.currentTarget),children:`View diff`}),(0,Z.jsxs)(_,{open:!!n,id:`${e}-result-details`,PaperProps:{sx:{borderRadius:`${t.shape.borderRadiusLarge}px`,padding:t.spacing(3)}},onClose:()=>r(null),anchorEl:n,anchorOrigin:{vertical:`bottom`,horizontal:-320},children:[(0,Z.jsx)(H,{variant:`subtitle2`,sx:{mb:3},children:`Environments diff`}),(0,Z.jsx)(Fr,{features:e})]})]})})},zr=e=>e.reduce((e,t)=>e+Object.values(t.environments).flatMap(e=>Object.keys(e)).length,0),Br=e=>e<0?`invalid bucket`:e>=2e4?`20000+`:e>=1e4?`10000-20000`:e>=1e3?`1000-10000`:e>=100?`100-1000`:`0-100`,{value:Vr,setValue:Hr}=Be(`AdvancedPlaygroundResultsTable:v1`,{id:`name`}),Ur=({features:e,input:t,loading:n})=>{let{trackEvent:r}=w();e&&r(`playground`,{props:{eventType:`number-of-combinations`,count:Br(zr(e))}});let[i,o]=ue(),s=ne(n),[c,l]=(0,Y.useState)(i.get(`search`)||``),f=S(u().breakpoints.down(`md`)),h=e&&e.length>0?Object.keys(e[0].environments).length:0,g=(0,Y.useMemo)(()=>[{Header:`Name`,accessor:`name`,searchable:!0,minWidth:160,Cell:({value:e,row:{original:t}})=>(0,Z.jsx)(ae,{title:e,to:`/projects/${t?.projectId}/features/${e}`})},{Header:`Project ID`,accessor:`projectId`,sortType:`alphanumeric`,filterName:`projectId`,searchable:!0,minWidth:150,Cell:({value:e})=>(0,Z.jsx)(ae,{title:e,to:`/projects/${e}`})},...t?.environments?.map(e=>({Header:n?()=>``:R(e),maxWidth:150,id:`environments.${e}`,align:`flex-start`,Cell:({row:t})=>(0,Z.jsx)(Pr,{value:t.original.environments[e]})}))||[],...h>1?[{Header:`Diff`,minWidth:150,id:`diff`,align:`left`,Cell:({row:e})=>(0,Z.jsx)(Rr,{value:e.original.environments})}]:[]],[t]),{data:_,getSearchText:y,getSearchContext:b}=ee(g,c,e||[]),x=(0,Y.useMemo)(()=>n?[,,,,,].fill({name:`Feature name`,projectId:`Feature Project`,environments:{name:`Feature Environments`,variants:[]},enabled:!0}):_,[_,n]),[C]=(0,Y.useState)(()=>({sortBy:[{id:i.get(`sort`)||Vr.id,desc:i.has(`order`)?i.get(`order`)===`desc`:Vr.desc}]})),{headerGroups:T,rows:E,state:{sortBy:D},prepareRow:O,setHiddenColumns:k}=(0,Q.useTable)({initialState:C,columns:g,data:x,sortTypes:p,autoResetGlobalFilter:!1,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0,defaultColumn:{Cell:d}},Q.useGlobalFilter,Q.useFlexLayout,Q.useSortBy);return m([{condition:f,columns:[`projectId`]}],k,g),(0,Y.useEffect)(()=>{if(n)return;let e=Object.fromEntries(i);e.sort=D[0].id,D[0].desc?e.order=`desc`:e.order&&delete e.order,c?e.search=c:delete e.search,o(e,{replace:!0}),Hr({id:D[0].id,desc:D[0].desc||!1})},[n,D,c]),(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(P,{sx:{display:`flex`,justifyContent:`space-between`,alignItems:`center`,mb:3},children:[(0,Z.jsx)(H,{variant:`subtitle1`,sx:{ml:1},children:e!==void 0&&!n?`Results (${E.length<x.length?`${E.length} of ${x.length}`:x.length})`:`Results`}),(0,Z.jsx)(v,{initialValue:c,onChange:l,hasFilters:!0,getSearchContext:b,disabled:n,containerStyles:{marginLeft:`1rem`,maxWidth:`400px`}})]}),(0,Z.jsx)(a,{condition:!n&&!x,show:()=>(0,Z.jsx)(U,{children:x===void 0?`None of the feature flags were evaluated yet.`:`No results found.`}),elseShow:()=>(0,Z.jsxs)(P,{ref:s,sx:{overflow:`auto`},children:[(0,Z.jsx)(de,{value:y(c),children:(0,Z.jsx)(z,{rows:E,headerGroups:T,prepareRow:O})}),(0,Z.jsx)(a,{condition:x.length===0&&c?.length>0,show:(0,Z.jsxs)(U,{children:[`No feature flags found matching “`,c,`”`]})}),(0,Z.jsx)(a,{condition:x&&x.length===0&&!c,show:(0,Z.jsx)(U,{children:`No features flags to display`})})]})})]})},Wr=G(B)(({theme:e})=>({marginBottom:e.spacing(3)})),Gr=({response:e})=>{let t=e?.warnings?.invalidContextProperties;return t&&t.length>0?(t.sort(),(0,Z.jsx)(Wr,{severity:`warning`,children:(0,Z.jsxs)(G(`details`)(({theme:e})=>({"* + *":{marginBlockStart:e.spacing(1)}})),{children:[(0,Z.jsx)(`summary`,{children:`Some context properties were not taken into account during evaluation`}),(0,Z.jsx)(`p`,{children:`The context you provided for this query contained top-level properties with invalid values. These properties were not taken into consideration when evaluating your query. The properties are:`}),(0,Z.jsx)(`ul`,{children:t.map(e=>(0,Z.jsx)(`li`,{"data-testid":`context-warning-list-element`,children:(0,Z.jsx)(`code`,{children:e})},e))}),(0,Z.jsxs)(`p`,{children:[`Remember that context fields (with the exception of the`,` `,(0,Z.jsx)(`code`,{children:`properties`}),` object) must be strings.`]}),(0,Z.jsx)(`p`,{children:`Because we didn't take these properties into account during the feature flag evaluation, they will not appear in the results table.`})]})})):null},Kr=({FormComponent:e=Rn})=>{let{value:t,setValue:n}=Be(`AdvancedPlayground