@aquera/data-visualizer-sdk 0.0.16 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{chunk-BWOCVRQM.js → chunk-2XS4ITEC.js} +1 -1
- package/{chunk-O6T6EAR2.js → chunk-A6TQPIGW.js} +1 -1
- package/{chunk-L764UFCZ.js → chunk-MMBRIJCB.js} +1 -1
- package/{chunk-YVK6OFZS.js → chunk-NMSXBPGE.js} +2 -2
- package/{chunk-FPLJWD4X.js → chunk-SJNARYMB.js} +1 -1
- package/{chunk-CJKWIGF2.js → chunk-VXVC3XC7.js} +1 -1
- package/{chunk-6HSEFISY.js → chunk-W7OTNCH6.js} +2 -2
- package/main.js +1 -1
- package/package.json +1 -1
|
@@ -40480,7 +40480,7 @@ ${t.error.stack}</pre
|
|
|
40480
40480
|
class="mf-viz mf-viz--heat"
|
|
40481
40481
|
style=${`background:${p5t[s]};color:${Mat[s]}`}
|
|
40482
40482
|
>${FV(r,t,o)}</span
|
|
40483
|
-
>`}let a=`mf-viz__num${E5t(t)}`;return j`<span class=${a}>${FV(r,t,o)}</span>`}})})}var pm=null;function HV(i){let e=i.shadowRoot;e&&(pm||(pm=new CSSStyleSheet,pm.replaceSync(L5t)),!e.adoptedStyleSheets.includes(pm)&&(e.adoptedStyleSheets=[...e.adoptedStyleSheets,pm]))}function F2(i){if(Array.isArray(i))return i.map(e=>{let t=e;return Array.isArray(t.columns)?_(x({},t),{columns:F2(t.columns)}):t.cell||!t.accessorKey||t.type==="checkbox"||t.type==="select"?t:_(x({},t),{cell:M=>{if(M.value===void 0||M.value===null||M.value==="")return"";let n=String(M.value);return j`<span class="mf-text" title=${n}>${M.value}</span>`}})})}var JV=CJ??kJ;JV.addBinaryOp?.("~=",6);var G2=JV,f5t=new Set(["==","!=","<","<=",">",">=","~="]);function H2(i){return!!i&&i.type==="Identifier"}function S5t(i){return!!i&&i.type==="CallExpression"}function w5t(i){return S5t(i)&&H2(i.callee)&&i.callee.name==="in"}function J2(i,e){if(!(!i||typeof i!="object")){if(i.type==="BinaryExpression"){let t=i;f5t.has(t.operator)&&(H2(t.left)&&e(t.left.name),J2(t.left,e),J2(t.right,e));return}if(i.type==="Compound"){nat(i.body,e);return}}}function nat(i,e){let t=0;for(;t<i.length;){let M=i[t];if(H2(M)){let n=t+1;if(H2(i[n])&&i[n].name==="not"&&(n+=1),w5t(i[n])){e(M.name),t=n+1;continue}t+=1;continue}J2(M,e),t+=1}}function C5t(i,e){let t;try{t=JV(i)}catch{return}t.type==="Compound"?nat(t.body,e):J2(t,e)}function $2(i,e){let t=new Set,M=[],n=r=>{!r||t.has(r)||(t.add(r),M.push(r))};for(let r of Object.values(i||{}))typeof r!="string"||r.trim()===""||C5t(r,n);return M.map(r=>({field:r,label:e(r)||r}))}var Om=["==","!=","<","<=",">",">=","~="],Zh={"==":"is","!=":"is not","~=":"contains","<":"less than","<=":"at most",">":"greater than",">=":"at least",in:"is any of","not in":"is none of",between:"between"},k5t=/int|decimal|numeric|float|double|real|number|long|money/,b5t=/^(boolean|bool|bit)$/,Q5t=/^(date|datetime2?|datetimeoffset|smalldatetime|timestamptz|timestamp)\b/;function IA(i){return!!i&&k5t.test(i.toLowerCase())}function U5t(i){return!!i&&b5t.test(i.toLowerCase())}function mm(i){return!!i&&Q5t.test(i.trim().toLowerCase())}var v5t=["==","!=","in","not in"],Y5t=["~=","==","!=","in"],Z5t=["==","!=",">","<",">=","<=","between"],_5t=["==","<",">","between"],W5t=["=="];function aat(i,e){switch(i){case"number":return[...Z5t];case"date":return[..._5t];case"boolean":return[...W5t];case"string":return e==="list"?[...v5t]:[...Y5t];default:return[...Om]}}var P5t=new Set(["==","!=","<","<=",">",">=","~=","in","not in","between"]);function q2(i){let e=(i.operators??[]).filter(t=>P5t.has(t));return e.length?e:aat(i.fieldType,Em(i))}function XV(i){let e=q2(i);return e.find(t=>t!=="between")??e[0]??"=="}function Em(i){return i.valueMode?i.valueMode:i.fieldType==="boolean"||i.enumerable||i.sampleValues?.length?"list":"free"}var R5t=1e4,V5t=/(password|passwd|secret|credential|api[_-]?key|access[_-]?key|private[_-]?key|token|_enc$|_encrypted$|magic[_-]?link|magic[_-]?token|ssn|social[_-]?security)/i;function K2(i){return i.suggestible===!1||i.piiExcluded===!0?!1:i.suggestible===!0?!0:![i.id,i.name,i.label].some(e=>typeof e=="string"&&V5t.test(e))}function rat(i){return[i.id,i.name,i.label].filter(e=>!!e)}function B5t(i){return!(Em(i)==="free"||typeof i.cardinality=="number"&&i.cardinality>R5t)}function sat(i,e){let t=(e??"").trim().toLowerCase();return t?[i.label,i.name,i.id,i.semanticType].some(M=>typeof M=="string"&&M.toLowerCase().includes(t)):!0}function e3(i,e={}){let t=new Set(e.onDashboard??[]),M=e.recentlyUsed??[],n=l=>{let N=1/0;for(let D of rat(l)){let c=M.indexOf(D);c!==-1&&c<N&&(N=c)}return N},r=l=>rat(l).some(N=>t.has(N)),o=l=>r(l)?0:n(l)!==1/0?1:B5t(l)?2:3,a=i.map((l,N)=>({a:l,i:N,tier:o(l),rec:n(l)}));if(!a.some(l=>l.tier<=1))return i.slice();let s=l=>(l.label??"").toLowerCase();return a.sort((l,N)=>{if(l.tier!==N.tier)return l.tier-N.tier;if(l.tier===1&&l.rec!==N.rec)return l.rec-N.rec;let D=s(l.a).localeCompare(s(N.a));return D!==0?D:l.i-N.i}).map(l=>l.a)}function F5t(i){return i.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function X2(i){return typeof i=="number"||typeof i=="boolean"?String(i):`"${F5t(i)}"`}function H5t(i){let e=String(i);return/^[\w.]+$/.test(e)?e:`'${e.replace(/'/g,"\\'")}'`}function lat(i){let e=String(i).trim();return e.length>=2&&e.startsWith("'")&&e.endsWith("'")?e.slice(1,-1).replace(/\\'/g,"'"):e}function $V(i){let{op:e,value:t}=i,M=H5t(i.field);return e==="between"&&Array.isArray(t)&&t.length===2?`${M} >= ${X2(t[0])} and ${M} <= ${X2(t[1])}`:(e==="in"||e==="not in")&&Array.isArray(t)?`${M} ${e} (${t.map(X2).join(", ")})`:`${M} ${e} ${X2(t)}`}function wI(i){if(!i.length)return"";let e=$V(i[0]);for(let t=1;t<i.length;t++)e+=` ${i[t].connector??"and"} ${$V(i[t])}`;return e}var J5t={"==":"==","=":"==",eq:"==",equals:"==","!=":"!=","<>":"!=",ne:"!=",neq:"!=",">":">",gt:">",">=":">=",gte:">=","<":"<",lt:"<","<=":"<=",lte:"<=","~=":"~=",contains:"~=",like:"~=",in:"in","not in":"not in",notin:"not in",between:"between"};function G5t(i){if(typeof i=="string"||typeof i=="number"||typeof i=="boolean")return i;if(Array.isArray(i)){let e=i.filter(t=>typeof t=="string"||typeof t=="number");return e.length?e:void 0}}function fm(i){let e=[];for(let t of i){let M=t.operation?J5t[t.operation.trim().toLowerCase()]:void 0,n=G5t(t.value);if(!t.field||!M||n===void 0)continue;let r=Array.isArray(n);M==="between"&&!(r&&n.length===2)||(M==="in"||M==="not in")&&!r||M!=="between"&&M!=="in"&&M!=="not in"&&r||e.push({field:t.field,op:M,value:n})}return e}function qV(i){return i.op==="between"&&Array.isArray(i.value)?`${i.value[0]} \u2013 ${i.value[1]}`:Array.isArray(i.value)?i.value.join(", "):String(i.value)}function KV(i,e){let t=r=>`${r.field}\0${r.op}\0${JSON.stringify(r.value)}`,M=new Set(i.map(t)),n=[...i];for(let r of e){let o=t(r);M.has(o)||(M.add(o),n.push(r))}return n}var eB=[{id:"today",label:"Today"},{id:"yesterday",label:"Yesterday"},{id:"last_7_days",label:"Last 7 days"},{id:"last_30_days",label:"Last 30 days"},{id:"last_90_days",label:"Last 90 days"},{id:"wtd",label:"Week to date"},{id:"mtd",label:"Month to date"},{id:"qtd",label:"Quarter to date"},{id:"ytd",label:"Year to date"},{id:"this_week",label:"This week"},{id:"last_week",label:"Last week"},{id:"this_month",label:"This month"},{id:"last_month",label:"Last month"},{id:"this_quarter",label:"This quarter"},{id:"last_quarter",label:"Last quarter"},{id:"this_year",label:"This year"},{id:"last_year",label:"Last year"}];function xM(i){let e=i.getFullYear(),t=String(i.getMonth()+1).padStart(2,"0"),M=String(i.getDate()).padStart(2,"0");return`${e}-${t}-${M}`}function Ej(i,e){let t=new Date(i);return t.setDate(t.getDate()+e),t}function GV(i){let e=new Date(i.getFullYear(),i.getMonth(),i.getDate()),t=(e.getDay()+6)%7;return Ej(e,-t)}function t3(i,e=new Date){let t=new Date(e.getFullYear(),e.getMonth(),e.getDate()),M=t.getFullYear(),n=t.getMonth(),r=Math.floor(n/3);switch(i){case"today":return{min:xM(t),max:xM(t)};case"yesterday":{let o=Ej(t,-1);return{min:xM(o),max:xM(o)}}case"last_7_days":return{min:xM(Ej(t,-6)),max:xM(t)};case"last_30_days":return{min:xM(Ej(t,-29)),max:xM(t)};case"last_90_days":return{min:xM(Ej(t,-89)),max:xM(t)};case"wtd":return{min:xM(GV(t)),max:xM(t)};case"this_week":{let o=GV(t);return{min:xM(o),max:xM(Ej(o,6))}}case"last_week":{let o=Ej(GV(t),-7);return{min:xM(o),max:xM(Ej(o,6))}}case"mtd":return{min:xM(new Date(M,n,1)),max:xM(t)};case"this_month":return{min:xM(new Date(M,n,1)),max:xM(new Date(M,n+1,0))};case"last_month":return{min:xM(new Date(M,n-1,1)),max:xM(new Date(M,n,0))};case"qtd":return{min:xM(new Date(M,r*3,1)),max:xM(t)};case"this_quarter":return{min:xM(new Date(M,r*3,1)),max:xM(new Date(M,r*3+3,0))};case"last_quarter":{let o=r===0?{yr:M-1,qi:3}:{yr:M,qi:r-1};return{min:xM(new Date(o.yr,o.qi*3,1)),max:xM(new Date(o.yr,o.qi*3+3,0))}}case"ytd":return{min:xM(new Date(M,0,1)),max:xM(t)};case"this_year":return{min:xM(new Date(M,0,1)),max:xM(new Date(M,11,31))};case"last_year":return{min:xM(new Date(M-1,0,1)),max:xM(new Date(M-1,11,31))};default:return null}}function tB(i){return i==="custom_range"||t3(i)!=null}function gat(i){return!!i&&i.type==="Identifier"}function $5t(i){if(gat(i))return i.name;if(i?.type==="Literal"){let e=i.value;if(typeof e=="string"&&e)return e}return null}function X5t(i){if(!i||i.type!=="BinaryExpression")return null;let e=i,t=$5t(e.left);if(!Om.includes(e.operator)||t==null)return null;let M=e.right,n=!1;if(M?.type==="UnaryExpression"){let o=M;if(o.operator!=="-")return null;n=!0,M=o.argument}if(M?.type!=="Literal")return null;let r=M.value;return typeof r!="string"&&typeof r!="number"||n&&typeof r!="number"?null:{field:t,op:e.operator,value:n?-r:r}}function iB(i){let e=i.trim();if(!e)return[];let t;try{t=G2(e)}catch{return null}let M=t.type==="Compound"?t.body:[t];if(M.length%2===0)return null;let n=[],r="and";for(let o=0;o<M.length;o++){if(o%2===1){if(!gat(M[o]))return null;let s=M[o].name;if(s!=="and"&&s!=="or")return null;r=s;continue}let a=X5t(M[o]);if(!a)return null;n.push(n.length===0||r==="and"?a:_(x({},a),{connector:r})),r="and"}return n}function Sm(i){let e=String(i??"").trim();if(!e)return!0;let t=e.replace(/"[^"]*"|'[^']*'/g,"");if(/\bor\b/i.test(t)||/\bnot\b/i.test(t.replace(/\bnot\s+in\b/gi," ")))return!1;let M=/\b(?:contains|startsWith|between|isEmpty|isNotEmpty|in)\s*\([^()]*\)/gi,n;do n=t,t=t.replace(M," ");while(t!==n);return!/[()]/.test(t)}function oat(i){return i.toLowerCase().replace(/[^a-z0-9]/g,"")}var q5t=new Set(["terms","multi_terms","date_histogram","histogram","range","date_range","significant_terms"]);function K5t(i){return i.endsWith(".keyword")?i.slice(0,-8):i}function eUt(i){let e=new Map,t=M=>{if(!(!M||typeof M!="object"))for(let[n,r]of Object.entries(M)){if(!r||typeof r!="object")continue;let o=r;for(let[a,s]of Object.entries(o))if(q5t.has(a)&&s&&typeof s=="object"&&typeof s.field=="string"){e.set(n,K5t(s.field));break}t(o.aggs)}};return t(i?.aggs),e}function MB(i,e){let t=(e?.columns??[]).filter(D=>typeof D.column=="string"&&!!D.column);if(!t.length||!i.pointName)return[];let M=e?.adapterType==="opensearch",n=M&&e?.dsl?eUt(e.dsl):null,r=i.seriesName?oat(i.seriesName):"",o=r?t.find(D=>oat(D.column)===r):void 0,a=t.filter(D=>D!==o),s=a.find(D=>!IA(D.dataType)&&!U5t(D.dataType))??a[0],l=[];if(s){let D=n?.get(s.column)??s.column,c=IA(s.dataType)&&Number.isFinite(Number(i.pointName));l.push({field:D,op:"==",value:c?Number(i.pointName):i.pointName})}let N=o??t.find(D=>D!==s&&IA(D.dataType));return!M&&N&&typeof i.pointY=="number"&&Number.isFinite(i.pointY)&&l.push({field:N.column,op:"==",value:i.pointY}),l}function Nat(i){return i.toLowerCase().replace(/[^a-z0-9]/g,"")}function tUt(i){return!!i&&/^(boolean|bool|bit)$/.test(i.toLowerCase())}function uat(i,e,t){i.set(e,[...i.get(e)??[],...t])}function Dat(i){let e=(i??[]).filter(M=>typeof M.column=="string"&&!!M.column);return e.length?(e.find(M=>!IA(M.dataType)&&!tUt(M.dataType))??e[0])?.column??null:null}function cat(i){if(i?.adapterType==="opensearch")return null;let e=(i?.columns??[]).filter(o=>typeof o.column=="string"&&!!o.column);if(!e.length)return null;let t=o=>o.sourceColumn??o.column;if(mm(e[0].dataType))return t(e[0]);let M=e.filter(o=>mm(o.dataType));if(M.length===1)return t(M[0]);let n=Dat(e),r=n?e.find(o=>o.column===n):void 0;return r&&mm(r.dataType)?t(r):null}function Iat(i){let e=new Map;for(let t of i??[]){let M=t?.queryMeta,n=Dat(M?.columns);if(!n)continue;let o=(t?.config?.chart?.data??[]).map(a=>a?.name).filter(a=>typeof a=="string"&&a!==""||typeof a=="number"&&!Number.isNaN(a));o.length&&uat(e,n,o)}return e}function i3(i,e){let t=(e?.columns??[]).filter(r=>typeof r.column=="string"&&!!r.column),M=new Map(t.map(r=>[Nat(r.column),r.column])),n=new Map;for(let r of i??[])if(!(!r||typeof r!="object"))for(let[o,a]of Object.entries(r)){let s=M.get(Nat(o));s&&(typeof a=="string"&&a!==""||typeof a=="number"&&!Number.isNaN(a))&&uat(n,s,[a])}return n}var fj=class i{byField=new Map;publish(e){for(let[t,M]of e){let n=this.byField.get(t);n||(n=new Set,this.byField.set(t,n));for(let r of M)n.add(r)}}getObserved(e){return[...this.byField.get(e)??[]]}fields(){return[...this.byField.keys()]}match(e,t){let M=this.getObserved(e),n=(t??"").trim().toLowerCase();return n?M.filter(r=>String(r).toLowerCase().includes(n)):M}has(e,t){let M=this.byField.get(e);return!!M&&[...M].some(n=>String(n)===String(t))}clear(){this.byField.clear()}static \u0275fac=function(t){return new(t||i)};static \u0275prov=Yt({token:i,factory:i.\u0275fac})};var iUt=["nileChart"],MUt=["*"],nUt=(i,e)=>e.label;function rUt(i,e){i&1&&Ot(0,"nile-glyph",10)}function oUt(i,e){if(i&1){let t=Ee();C(0,"nile-menu-item",8),Te("click",function(){let n=R(t).$index,r=p(3);return V(r.selectMasterDetailVariant(n))}),xe(1,rUt,1,0,"nile-glyph",10),v(2),k()}if(i&2){let t=e.$implicit,M=e.$index,n=p(3);m(),pe(M===n.masterDetailVariantIndex?1:-1),m(),hi(" ",t.label," ")}}function aUt(i,e){if(i&1){let t=Ee();C(0,"nile-dropdown",3)(1,"button",4),Ot(2,"nile-glyph",5),k(),C(3,"nile-menu",6),xt(4,oUt,3,2,"nile-menu-item",null,nUt),Ot(6,"div",7),C(7,"nile-menu-item",8),Te("click",function(){R(t);let n=p(2);return V(n.resetMasterDetailView())}),Ot(8,"nile-glyph",9),v(9," Reset view "),k()()()}if(i&2){let t=p(2);m(4),pt(t.masterDetailVariants)}}function sUt(i,e){if(i&1&&(C(0,"nile-chart",1,0)(2,"div",2),xe(3,aUt,10,0,"nile-dropdown",3),nd(4),k()()),i&2){let t=p();m(3),pe(t.isMasterDetailChart?3:-1)}}var CI=class i{constructor(e,t,M=null,n=null){this.zone=e;this.cd=t;this.gridPageFetcher=M;this.observed=n}zone;cd;gridPageFetcher;observed;config;widgetId=null;widgetTitle=null;loading=!1;drilldownBy;menu=null;dashboardFilters=null;resolvedFilters=null;dashboardId=null;conversationId=null;cellFilterEnabled=Et(!1);_filterMode="prompt";_filterSeed=null;aiSend=new ni;sortChange=new ni;filterSubmit=new ni;filterChange=new ni;chartClick=new ni;chartSelection=new ni;chartSelectionReset=new ni;gridFilterVerdict=new ni;menuAction=new ni;cellFilter=rM();dataViewFilterChange=new ni;chartRef;static MASTER_DETAIL_VARIANTS=[{label:"Default view",overrides:null},{label:"Collapsible overview",overrides:{detailType:"spline",masterType:"column",masterCollapsible:!0}},{label:"Styled navigator",overrides:{detailType:"areaspline",masterType:"area",maskFill:"rgba(37,99,235,0.12)",detailTitle:"Detail view",masterTitle:"Overview (drag to select)"}},{label:"Master only (zoomable)",overrides:{masterOnly:!0,masterType:"column"}}];static DEFAULT_VARIANT_INDEX=3;masterDetailVariantIndex=i.DEFAULT_VARIANT_INDEX;mounted=!0;viewReady=!1;sessionId=globalThis.crypto?.randomUUID?.()??`${Date.now()}-${Math.random()}`;aiSendHandler=e=>this.handleAiSend(e);sortChangeHandler=e=>this.handleSortChange(e);nileChangeHandler=e=>this.handleNileChange(e);filterKeydownHandler=e=>this.handleFilterKeydown(e);filterFocusHandler=()=>this.handleFilterFocus();filterClearHandler=()=>this.handleFilterClear();chartClickHandler=e=>this.handleChartClick(e);chartSelectionHandler=e=>this.handleChartSelection(e);resetZoomClickHandler=e=>this.handleResetZoomClick(e);lastForwardedSelection=null;static SELECTION_DEDUP_MS=1e3;static GRID_FULL_FETCH_ROWS=500;masterDetailZoomWindow=null;menuChangeHandler=e=>this.handleMenuChange(e);paginationChangeHandler=e=>this.handleGridPaginationChange(e);filterChangeHandler=e=>this.handleGridFilterChange(e);cellFilterHandler=(e,t)=>this.zone.run(()=>this.cellFilter.emit({widgetId:this.widgetId,field:e,value:t}));filterDebounce=null;noopFilterFn=()=>!0;gridState=Ye(null);_pendingDashboardFilterRefresh=!1;_dashboardFilterRefetching=!1;_dashboardFilterSeq=0;injector=Be(Ml);lastClickCoords={x:0,y:0};mouseDownHandler=e=>{this.lastClickCoords={x:e.clientX,y:e.clientY}};latestFilterPayload=null;suppressPaginationEvents=!1;staticGridPageIndex=0;staticGridPageSize=10;staticGridRowCount=0;ngAfterViewInit(){this.viewReady=!0,this.attachAiListener(),this.applyLoading(),this.applyMenu(),this.config&&this.applyConfig()}ngOnChanges(e){if(!this.viewReady)return;e.loading&&this.applyLoading(),e.menu&&this.applyMenu();let t=e.dashboardFilters&&!e.dashboardFilters.firstChange,M=e.resolvedFilters&&!e.resolvedFilters.firstChange;if((t||M)&&this.handleDashboardFilterChange(),!e.config&&!e.drilldownBy)return;let n=e.config?.previousValue,r=e.config?.currentValue;e.config&&this.needsRemount(n,r)?this.remount():this.applyConfig()}ngOnDestroy(){this.detachAiListener()}pushAiResponse(e){this.chartRef?.nativeElement?.addAiResponse?.(e)}get isMasterDetailChart(){return this.config?.chart?.type==="master-detail"}get masterDetailVariants(){return i.MASTER_DETAIL_VARIANTS}selectMasterDetailVariant(e){if(!this.isMasterDetailChart)return;let t=i.MASTER_DETAIL_VARIANTS.length;e<0||e>=t||e===this.masterDetailVariantIndex||(this.masterDetailVariantIndex=e,this.remount())}resetMasterDetailView(){this.isMasterDetailChart&&(this.masterDetailVariantIndex=i.DEFAULT_VARIANT_INDEX,this.masterDetailZoomWindow=null,this.remount())}patchControlSuggestions(e,t){let M=this.chartRef?.nativeElement;if(!M)return;let n=M.shadowRoot?.querySelector("nile-filter-chart"),r=n?.selectedValues?.get(e),o=M.config?.chart?.controls;if(!o)return;let a=o.find(s=>s.id===e);a&&(a.suggestions=[...t],typeof r=="string"&&(a.value=r),n?.requestUpdate?.())}getLiveExpression(){let e=this.getPromptControlId(this.config);return e?{controlId:e,value:this.readLiveFilterValue(e)}:null}setFilterExpression(e){let t=this.chartRef?.nativeElement,M=this.getPromptControlId(this.config);if(!t||!M)return;let r=t.config?.chart?.controls?.find(a=>a.id===M);r&&(r.value=e);let o=t.shadowRoot?.querySelector("nile-filter-chart");o?.setValue?.(M,e),o?.requestUpdate?.()}getPromptControlId(e){let t=e?.chart?.controls;for(let M of t??[])if((M.variant==="prompt"||M.variant==="expression"||M.variant==="hybrid")&&M.id)return M.id;return null}setFilterMode(e,t){this._filterMode=e,this._filterSeed=t??null,this.applyConfig()}openAiChat(){let e=this.chartRef?.nativeElement;e&&id(()=>{e.chatOpen=!0},{injector:this.injector})}handleChartClick(e){let t=e.detail??{},M=String(t.name??t.point?.name??t.category??t.point?.category??""),n=typeof t.value=="number"?t.value:typeof t.point?.y=="number"?t.point.y:null,r=t.seriesName??t.point?.series?.name??null;this.zone.run(()=>this.chartClick.emit({widgetId:this.widgetId,point:t.point??null,pointName:M,pointY:n,seriesName:r,x:this.lastClickCoords.x,y:this.lastClickCoords.y}))}handleChartSelection(e){let{min:t,max:M}=e.detail??{};if(typeof t!="number"||typeof M!="number")return;if(M<=t){let s=this.chartPointStep();if(!s)return;t-=s/2,M+=s/2}let n=this.chartXExtent();if(n&&t<=n.min&&M>=n.max){this.masterDetailZoomWindow=null;return}this.masterDetailZoomWindow={min:t,max:M};let r=`${t}:${M}`,o=Date.now(),a=this.lastForwardedSelection;a?.key===r&&o-a.at<i.SELECTION_DEDUP_MS||(this.lastForwardedSelection={key:r,at:o},this.zone.run(()=>this.chartSelection.emit({widgetId:this.widgetId,min:t,max:M})))}handleResetZoomClick(e){e.composedPath().some(M=>M instanceof Element&&(M.classList.contains("nile-chart-reset-zoom")||M.getAttribute("part")==="reset-zoom"))&&(this.masterDetailZoomWindow=null,this.lastForwardedSelection=null,this.zone.run(()=>this.chartSelectionReset.emit({widgetId:this.widgetId})))}chartPointStep(){let e=this.chartRef?.nativeElement,t=e?this.findHighchartsInstance(e):null,M=[],n=t?.series??[];for(let a of n)for(let s of a.points??[])typeof s.x=="number"&&M.push(s.x);if(M.length<2){let a=this.config?.chart?.data;for(let s of Array.isArray(a)?a:[])s&&typeof s=="object"&&typeof s.x=="number"&&M.push(s.x)}if(M.length<2)return 0;let r=[...new Set(M)].sort((a,s)=>a-s),o=1/0;for(let a=1;a<r.length;a++)o=Math.min(o,r[a]-r[a-1]);return Number.isFinite(o)&&o>0?o:0}chartXExtent(){let e=this.chartRef?.nativeElement,M=(e?this.findHighchartsInstance(e):null)?.xAxis?.[0];if(M&&typeof M.dataMin=="number"&&typeof M.dataMax=="number")return{min:M.dataMin,max:M.dataMax};let n=[],r=this.config?.chart?.data;for(let o of Array.isArray(r)?r:[]){o&&typeof o=="object"&&typeof o.x=="number"&&n.push(o.x);let a=o?.data;if(Array.isArray(a))for(let s of a)Array.isArray(s)&&typeof s[0]=="number"?n.push(s[0]):s&&typeof s=="object"&&typeof s.x=="number"&&n.push(s.x)}return n.length?{min:Math.min(...n),max:Math.max(...n)}:null}drillIntoSeries(e,t){let M=this.chartRef?.nativeElement?this.findHighchartsInstance(this.chartRef.nativeElement):null;M&&(M.addSingleSeriesAsDrilldown(e,{id:t.id,name:t.name,type:t.type==="donut"?"pie":t.type??"pie",data:t.data}),M.applyDrilldown())}findHighchartsInstance(e){let t=e.shadowRoot;if(!t)return null;for(let M of Array.from(t.querySelectorAll("*"))){let n=M.chart;if(n&&typeof n.addSingleSeriesAsDrilldown=="function"&&typeof n.applyDrilldown=="function")return n}return null}needsRemount(e,t){return this.sparklineVisibilityChanged(e,t)||this.kpiVariantChangedWithSparkline(e,t)||this.semiCircleChanged(e,t)||this.widgetFamilyChanged(e,t)||this.seriesColorChanged(e,t)||this.plotShapeChanged(e,t)}plotShapeChanged(e,t){let M=e?.chart,n=t?.chart;if(!M||!n)return!1;let r=N=>Array.isArray(N)?N.length:-1;if(r(M.categories)!==r(n.categories))return!0;let o=Array.isArray(M.data)?M.data:null,a=Array.isArray(n.data)?n.data:null;if(o&&a&&o.length===a.length)for(let N=0;N<o.length;N++){let D=o[N],c=a[N];if(r(D?.data)!==r(c?.data))return!0}let s=M.options?.series,l=n.options?.series;if(r(s)!==r(l))return!0;if(Array.isArray(s)&&Array.isArray(l))for(let N=0;N<s.length;N++){let D=s[N],c=l[N];if(r(D?.data)!==r(c?.data))return!0}for(let N of["lineSeries","columnSeries"]){let D=M[N],c=n[N];if(r(D?.data)!==r(c?.data))return!0}return!1}seriesColorChanged(e,t){let M=e?.chart?.data,n=t?.chart?.data;return!Array.isArray(M)||!Array.isArray(n)?!1:M.length!==n.length?!0:M.some((r,o)=>{let a=r,s=n[o];return(a?.color??null)!==(s?.color??null)})}widgetFamilyChanged(e,t){return this.chartFamily(e)!==this.chartFamily(t)}chartFamily(e){let t=e?.chart?.type;return t==="kpi"?"kpi":t==="grid"?"grid":t==="filter"?"filter":"chart"}sparklineVisibilityChanged(e,t){return this.hasSparkline(e)!==this.hasSparkline(t)}kpiVariantChangedWithSparkline(e,t){let M=e?.chart?.variant,n=t?.chart?.variant;return M!==n&&this.hasSparkline(t)}semiCircleChanged(e,t){let M=e?.chart?.type;if(t?.chart?.type!=="donut"&&M!=="donut")return!1;let r=!!e?.chart?.semiCircle,o=!!t?.chart?.semiCircle;return r!==o}hasSparkline(e){let t=e?.chart?.sparkline;return Array.isArray(t)&&t.length>0}remount(){this.detachAiListener(),this.mounted=!1,this.cd.detectChanges(),this.mounted=!0,this.cd.detectChanges(),this.attachAiListener(),this.applyConfig()}applyConfig(){let e=this.chartRef?.nativeElement;if(!this.config||!e)return;let t=this.isGridConfig(this.config);if(t&&this.isServerGrid(this.config)){this.applyServerGrid(e);return}e.config=this.buildChartConfig(t),this.afterChildRendered(e,t,()=>{this.applyCardStyle(e),t&&(this.fixGridDisplay(e),this.reassertStaticGridPage(e))})}reassertStaticGridPage(e){if(this.staticGridPageIndex===0||this.isServerGrid(this.config))return;let t=e.shadowRoot?.querySelector("nile-data-grid");if(!t)return;this.suppressPaginationEvents=!0;let M=this.staticGridPageIndex,n=this.staticGridPageSize;(t.updateComplete??Promise.resolve()).then(()=>{t.pagination={pageIndex:M,pageSize:n},(t.updateComplete??Promise.resolve()).then(()=>{this.suppressPaginationEvents=!1})})}isGridConfig(e){return e?.chart?.type==="grid"}buildChartConfig(e){let t=Yh(this.config,this.drilldownBy),Z=t.chart??{},{height:M}=Z,n=$e(Z,["height"]),r=n.type==="bar";r&&(n.type="column");let o=n.type==="stacked",a=n.type==="cluster";(o||a)&&(n.type="column");let s=e&&n.stickyHeader===void 0?{stickyHeader:!0}:{},l=e?{height:"100%"}:{},N=e?this.normalizeGridColumns(n.columns):void 0,D=e?B2(N)??N:N,c=e?Lm(D)??D:D,I=e?F2(c)??c:c,d=e&&this.cellFilterEnabled()?V2(I,this.cellFilterHandler)??I:I,y={};if(e){let ne=Array.isArray(n.data)?n.data:[];ne.length!==this.staticGridRowCount&&(this.staticGridRowCount=ne.length,this.staticGridPageIndex=0),y={paginationEnabled:!0,pagination:{pageIndex:this.staticGridPageIndex,pageSize:this.staticGridPageSize}}}let A=n.type==="kpi",$=t.aq??{},{ai:z,switchable:E}=$,S=$e($,["ai","switchable"]),L=A?S:x(x({},S),z!==void 0?{ai:z}:{});if(!L.chartTitle&&!n.chartTitle&&this.widgetTitle&&(L.chartTitle=this.widgetTitle),n.type==="filter"){n.chartTitle=hm,delete n.chartSubtitle,delete n.summary,L.chartTitle=hm,delete L.chartSubtitle,delete L.summary;let ne=n.controls;if(Array.isArray(ne)){let ae=this.chartRef?.nativeElement?.config?.chart?.controls,he=this.getPromptControlId(this.config),ie=this._filterSeed;this._filterSeed=null,n.controls=ne.map(ce=>{let Ie=ce.id,Oe=Ie?this.readLiveFilterValue(Ie):"",Qe=Ie?ae?.find(le=>le.id===Ie):void 0,ve=Array.isArray(Qe?.suggestions)&&Qe.suggestions.length?{suggestions:Qe.suggestions}:{},F=x(x(_(x({},ce),{showClearIcon:!0}),ve),Oe?{value:Oe}:{});if(Ie&&Ie===he){let le=ie!=null?{value:ie}:{};return this._filterMode==="expression"?x(_(x({},F),{variant:"expression",queryLanguage:_(x({engine:"filtrex",mode:"strict",validateOn:"change"},ce.queryLanguage??{}),{enabled:!0}),placeholders:[PV],expressionPlaceholders:[PV]}),le):x(_(x({},F),{placeholders:[RV],promptPlaceholders:[RV]}),le)}return F})}}let U=n.type??"",Y=n.categories,B=Array.isArray(Y)&&Y.length>0&&U!=="invertedarea"&&!r,X=n.options??{},W=Object.keys(X).length?{options:X}:{};if(B){let ne=X.xAxis??{},ae=ne.labels??{},he=Y.length,ie=he>8?Math.ceil(he/8):void 0,ce=Y.reduce((ve,F)=>Math.max(ve,String(F??"").length),0),Oe=(ie?Math.ceil(he/ie):he)*(ce*7+12),Qe={chart:{spacingLeft:48},xAxis:{labels:{rotation:-45,align:"right",y:12}}};W={options:_(x({},X),{xAxis:_(x({},ne),{labels:x(x({autoRotation:[-45,-90],style:{textOverflow:"none",whiteSpace:"nowrap"}},ie?{step:ie}:{}),ae)}),responsive:{rules:[{condition:{maxWidth:Oe},chartOptions:Qe},...X.responsive?.rules??[]]}})}}if(o){let ne=W.options??X,ae=ne.plotOptions??{},he=ae.series??{};W={options:_(x({},ne),{plotOptions:_(x({},ae),{series:_(x({},he),{stacking:n.stackMode||"normal"})})})}}if(r){let ne=W.options??X,ae=ne.chart??{};W={options:_(x({},ne),{chart:_(x({},ae),{inverted:!0})})}}let Ne=U==="master-detail"?x(x({},this.masterDetailVariantIndex>0?i.MASTER_DETAIL_VARIANTS[this.masterDetailVariantIndex].overrides??{}:{}),this.masterDetailZoomWindow?{selectionMin:this.masterDetailZoomWindow.min,selectionMax:this.masterDetailZoomWindow.max}:{}):{};return _(x({},t),{chart:x(x(x(x(x(x(x(x({},s),n),e?{variant:"sleek-condensed",columnResizingEnabled:!0,columnResizeMode:"onChange",columnReorderingEnabled:!0}:{}),d?{columns:d}:{}),W),Ne),l),y),aq:L})}isServerGrid(e){let t=e?.chart;return t?.serverPagination===!0&&typeof t?.gridId=="string"}applyServerGrid(e){let t=this.config.chart??{},M=t.gridId,n=Number(t.pagination?.pageSize)||10,r=this.gridState();if(r?.gridId===M&&r.loaded){this._dashboardFilterRefetching||this.renderServerGrid(e);return}this.gridState.set({gridId:M,total:0,pageIndex:0,pageSize:n,columns:[],aq:{},chartConfig:{},rows:[],loadedPages:[],loaded:!1,fullyLoaded:!1,filters:[]}),e.loading=!0,this.fetchGridPage(M,0,i.GRID_FULL_FETCH_ROWS).then(o=>{if(!o||this.gridState()?.gridId!==M){this._pendingDashboardFilterRefresh=!1;return}this.emitGridFilterVerdict(o);let a=o.config?.chart??{},s=Array.isArray(a.data)?a.data:[],l=Math.min(Number(o.total)||s.length,i.GRID_FULL_FETCH_ROWS);if(this.observed?.publish(i3(s,o.queryMeta)),this.gridState.set({gridId:M,total:l,pageIndex:0,pageSize:n,columns:Array.isArray(a.columns)?a.columns:[],aq:o.config?.aq??{},chartConfig:a,rows:s,loadedPages:[0],loaded:!0,fullyLoaded:!0,filters:Array.isArray(a.filters)?a.filters:[]}),e.loading=!1,this.renderServerGrid(e),this._pendingDashboardFilterRefresh){this._pendingDashboardFilterRefresh=!1;let N=this.gridState();N&&N.gridId===M&&this.applyServerFilters(M,N.filters)}}).catch(o=>{console.error("[nile-chart-widget] initial grid page fetch failed",o),e.loading=!1,this._pendingDashboardFilterRefresh=!1})}emitGridFilterVerdict(e){let t=e?.dashboardFilter;t&&this.gridFilterVerdict.emit({widgetId:this.widgetId,applied:t.applied===!0,reason:t.reason})}renderServerGrid(e){let t=this.gridState();if(!t)return;let M=x({},t.aq);!M.chartTitle&&!t.chartConfig.chartTitle&&this.widgetTitle&&(M.chartTitle=this.widgetTitle);let n=(this.normalizeGridColumns(t.columns)??t.columns).map(s=>_(x({},s),{filterFn:this.noopFilterFn})),r=B2(n)??n,o=Lm(r)??r,a=F2(o)??o;e.config={chart:_(x({stickyHeader:!0},t.chartConfig),{variant:"sleek-condensed",columnResizingEnabled:!0,columnResizeMode:"onChange",columnReorderingEnabled:!0,type:"grid",columns:this.cellFilterEnabled()?V2(a,this.cellFilterHandler)??a:a,data:[...t.rows],paginationEnabled:!0,pagination:{pageIndex:t.pageIndex,pageSize:t.pageSize},height:"100%"}),aq:M},this.afterChildRendered(e,!0,()=>{this.applyCardStyle(e),this.fixGridDisplay(e)})}normalizeGridColumns(e){if(Array.isArray(e))return e.map(t=>{let M=t,n=M.header??M.headerName;if(Array.isArray(M.columns)){let D=M,{field:I,headerName:d,columns:y}=D,A=$e(D,["field","headerName","columns"]);return _(x(x({},A),n!==void 0?{header:n}:{}),{columns:this.normalizeGridColumns(M.columns)})}let r=M.accessorKey??M.field,o=M.enableFiltering??!0,a=typeof M.cell=="function"?M.cell:null,c=M,{field:s,headerName:l}=c,N=$e(c,["field","headerName"]);return _(x(x(x({},N),r!==void 0?{accessorKey:r}:{}),n!==void 0?{header:n}:{}),{enableFiltering:o,cell:I=>{let d=a?a(I):I.value;return d==null||d===""?"-":d}})})}afterChildRendered(e,t,M){let n=()=>{if(!t){M();return}let r=0,o=()=>{e.shadowRoot?.querySelector("nile-data-grid")||++r>30?M():requestAnimationFrame(o)};o()};e.updateComplete?e.updateComplete.then(n):customElements.whenDefined("nile-chart").then(()=>{let r=e.updateComplete;r?r.then(n):requestAnimationFrame(n)})}applyCardStyle(e){let t=e.shadowRoot?.querySelector(".nile-chart-card");if(!t)return;let M=this.config?.chart??{},n=(r,o)=>{o?t.style.setProperty(r,o):t.style.removeProperty(r)};n("background",M.chartBg),n("border",M.chartBorder),n("border-radius",M.chartBorderRadius),n("box-shadow",M.chartShadow),n("padding",M.chartPadding),n("min-height",M.chartMinHeight)}fixGridDisplay(e){let t=e.shadowRoot?.querySelector("nile-data-grid");if(!t)return;t.style.display="flex",t.style.flexDirection="column";let M=this.config?.chart?.chartBg;M?t.style.setProperty("--nile-data-grid-surface",M):t.style.removeProperty("--nile-data-grid-surface"),BV(t),HV(t),this.injectCellFilterStyle(t)}gridStyleSheet=null;injectCellFilterStyle(e){if(!this.cellFilterEnabled())return;let t=e.shadowRoot;t&&(this.gridStyleSheet||(this.gridStyleSheet=new CSSStyleSheet,this.gridStyleSheet.replaceSync(eat)),!t.adoptedStyleSheets.includes(this.gridStyleSheet)&&(t.adoptedStyleSheets=[...t.adoptedStyleSheets,this.gridStyleSheet]))}applyLoading(){let e=this.chartRef?.nativeElement;e&&(e.loading=this.loading)}applyMenu(){let e=this.chartRef?.nativeElement;e&&(e.menu=this.menu)}attachAiListener(){let e=this.chartRef?.nativeElement;e?.addEventListener("nile-chart-ai-send",this.aiSendHandler),e?.addEventListener("nile-sort-change",this.sortChangeHandler),e?.addEventListener("nile-chart-click",this.chartClickHandler),e?.addEventListener("nile-chart-selection",this.chartSelectionHandler),e?.addEventListener("click",this.resetZoomClickHandler,!0),e?.addEventListener("nile-menu-change",this.menuChangeHandler),e?.addEventListener("nile-pagination-change",this.paginationChangeHandler),e?.addEventListener("nile-filter-change",this.filterChangeHandler),e?.addEventListener("mousedown",this.mouseDownHandler,!0),this.isFilterConfig(this.config)&&(e?.addEventListener("nile-change",this.nileChangeHandler),e?.addEventListener("keydown",this.filterKeydownHandler,!0),e?.addEventListener("focusin",this.filterFocusHandler),e?.addEventListener("click",this.filterFocusHandler,!0),e?.addEventListener("nile-clear",this.filterClearHandler))}detachAiListener(){let e=this.chartRef?.nativeElement;e?.removeEventListener("nile-chart-ai-send",this.aiSendHandler),e?.removeEventListener("nile-sort-change",this.sortChangeHandler),e?.removeEventListener("nile-chart-click",this.chartClickHandler),e?.removeEventListener("nile-chart-selection",this.chartSelectionHandler),e?.removeEventListener("click",this.resetZoomClickHandler,!0),e?.removeEventListener("nile-menu-change",this.menuChangeHandler),e?.removeEventListener("nile-pagination-change",this.paginationChangeHandler),e?.removeEventListener("nile-filter-change",this.filterChangeHandler),e?.removeEventListener("mousedown",this.mouseDownHandler,!0),e?.removeEventListener("nile-change",this.nileChangeHandler),e?.removeEventListener("keydown",this.filterKeydownHandler,!0),e?.removeEventListener("focusin",this.filterFocusHandler),e?.removeEventListener("click",this.filterFocusHandler,!0),e?.removeEventListener("nile-clear",this.filterClearHandler)}handleMenuChange(e){let t=e.detail?.id;t&&this.zone.run(()=>this.menuAction.emit(t))}handleGridPaginationChange(e){let t=e.detail;if(this.suppressPaginationEvents)return;let M=this.gridState();if(!M?.loaded){if(this.isGridConfig(this.config)&&!this.isServerGrid(this.config)){let N=t?.pagination;this.staticGridPageIndex=Number(N?.pageIndex)||0,this.staticGridPageSize=Number(N?.pageSize)||this.staticGridPageSize}return}let n=t?.pagination,r=Number(n?.pageIndex)||0,o=Number(n?.pageSize)||M.pageSize;if(M.fullyLoaded){(r!==M.pageIndex||o!==M.pageSize)&&this.gridState.set(_(x({},M),{pageIndex:r,pageSize:o}));return}let a=r*o,s=o!==M.pageSize;if(!(s||!M.loadedPages.includes(r))){r!==M.pageIndex&&this.gridState.set(_(x({},M),{pageIndex:r}));return}this.suppressPaginationEvents=!0,this.fetchGridPage(M.gridId,r,o).then(N=>{let D=this.gridState();if(D?.gridId!==M.gridId){this.suppressPaginationEvents=!1;return}let c=N?.config?.chart??{},I=Array.isArray(c.data)?c.data:[],d=s?Array.from({length:D.total},()=>({})):D.rows.slice();I.forEach((z,E)=>{d[a+E]=z});let y=s?[r]:[...D.loadedPages,r];this.gridState.set(_(x({},D),{rows:d,loadedPages:y,pageIndex:r,pageSize:o})),this.observed?.publish(i3(I,N?.queryMeta)),this.pushGridData();let A=this.chartRef?.nativeElement?.shadowRoot?.querySelector("nile-data-grid");(A?.updateComplete??Promise.resolve()).then(()=>{A&&(A.pagination={pageIndex:r,pageSize:o}),(A?.updateComplete??Promise.resolve()).then(()=>{this.suppressPaginationEvents=!1})})}).catch(N=>{this.suppressPaginationEvents=!1,console.error("[nile-chart-widget] page fetch failed",N)})}handleGridFilterChange(e){let t=this.gridState(),M=e.detail?.filters??[];if(this.isServerGrid(this.config)&&t?.loaded&&this.config.chart.gridId===t.gridId){this.filterDebounce&&clearTimeout(this.filterDebounce),this.filterDebounce=setTimeout(()=>this.applyServerFilters(t.gridId,M),300);return}this.dataViewFilterChange.emit(M)}applyServerFilters(e,t){let M=this.gridState();if(!M||M.gridId!==e)return;let n=++this._dashboardFilterSeq,r=this._dashboardFilterRefetching;this.fetchGridPage(e,0,i.GRID_FULL_FETCH_ROWS,t).then(o=>{if(n!==this._dashboardFilterSeq)return;let a=this.gridState();if(!o||a?.gridId!==e)return;this.emitGridFilterVerdict(o);let s=o.config?.chart??{},l=Array.isArray(s.data)?s.data:[],N=Math.min(Number(o.total)||l.length,i.GRID_FULL_FETCH_ROWS);this.observed?.publish(i3(l,o.queryMeta)),this.gridState.set(_(x({},a),{filters:t,total:N,rows:l,pageIndex:0,loadedPages:[0],loaded:!0,fullyLoaded:!0}));let D=this.chartRef?.nativeElement;r&&D?(D.loading=!1,this.renderServerGrid(D)):this.pushGridData(l)}).catch(o=>{console.error("[nile-chart-widget] filter fetch failed",o)}).finally(()=>{if(n===this._dashboardFilterSeq&&(this._dashboardFilterRefetching=!1,r)){let o=this.chartRef?.nativeElement;o&&(o.loading=!1)}})}fetchGridPage(e,t,M,n){if(!this.gridPageFetcher)return Promise.resolve(null);let r=this.dashboardFilters&&Object.keys(this.dashboardFilters).length?this.dashboardFilters:void 0,o=this.resolvedFilters&&this.resolvedFilters.length?this.resolvedFilters:void 0;return Promise.resolve(this.gridPageFetcher(e,t,M,n,r,this.dashboardId,o,this.conversationId))}handleDashboardFilterChange(){let e=this.gridState();if(!e||!this.isServerGrid(this.config)||this.config.chart?.gridId!==e.gridId)return;if(!e.loaded){this._pendingDashboardFilterRefresh=!0;return}this._dashboardFilterRefetching=!0;let t=this.chartRef?.nativeElement;t&&(t.loading=!0),this.applyServerFilters(e.gridId,e.filters)}pushGridData(e){let t=this.chartRef?.nativeElement?.shadowRoot?.querySelector("nile-data-grid");if(!t)return;if(e)t.data=e;else{let n=this.gridState();n&&(t.data=[...n.rows])}let M=()=>{BV(t),HV(t),this.injectCellFilterStyle(t)};t.updateComplete?t.updateComplete.then(M):M()}isFilterConfig(e){return e?.chart?.type==="filter"}getExpressionControl(e){let t=e?.chart?.controls;if(!t)return null;for(let M of t)if((M.variant==="expression"||M.variant==="hybrid")&&M.id)return{id:M.id,variant:M.variant};return null}handleAiSend(e){let t=e.detail,M=t?.message??t?.text??"",n=this.widgetId;if(!M||!n)return;let r=e.composedPath()[0];this.zone.run(()=>{this.aiSend.emit({widgetId:n,message:M,sessionId:this.sessionId,chartEl:r})})}handleSortChange(e){let t=e.detail?.sorting??[];this.zone.run(()=>{this.sortChange.emit({widgetId:this.widgetId,sorting:t})})}handleNileChange(e){let t=e.detail??{},M=t.filters??{},n=t.errors??{};this.latestFilterPayload={filters:M,errors:n};let r=this.getExpressionControl(this.config);if(!r)return;let o=M[r.id];if(r.variant==="hybrid"){let s=typeof o=="object"&&o!==null,l=n[r.id]!==void 0;if(!s&&!l)return}let a=typeof o=="string"?o:o?.source??"";this.zone.run(()=>{this.filterChange.emit({widgetId:this.widgetId,controlId:r.id,query:a})})}readLiveFilterValue(e){let t=this.chartRef?.nativeElement?.shadowRoot?.querySelector("nile-filter-chart"),M=t?.shadowRoot?.querySelector(`#fc-prompt-${CSS.escape(e)}`);if(M&&typeof M.value=="string")return M.value;let n=t?.selectedValues?.get(e);return typeof n=="string"?n:n&&typeof n=="object"?String(n.source??""):""}lastFilterFocusTs=0;handleFilterFocus(){let e=Date.now();if(e-this.lastFilterFocusTs<120)return;this.lastFilterFocusTs=e;let t=this.getExpressionControl(this.config);if(!t)return;let M=this.readLiveFilterValue(t.id);this.zone.run(()=>{this.filterChange.emit({widgetId:this.widgetId,controlId:t.id,query:M})})}handleFilterKeydown(e){let t=e;if(t.key!=="Enter"||t.shiftKey||t.isComposing)return;let M=this.getPromptControlId(this.config);if(!M)return;let n=this.readLiveFilterValue(M),r=this._filterMode;this.zone.run(()=>{this.filterSubmit.emit(x({widgetId:this.widgetId,filters:{[M]:n},errors:{},mode:r},r==="prompt"?{prompt:n}:{}))})}handleFilterClear(){this.zone.run(()=>{this.filterSubmit.emit({widgetId:this.widgetId,filters:{},errors:{}})})}static \u0275fac=function(t){return new(t||i)(ui(nl),ui(ll),ui(L2,8),ui(fj,8))};static \u0275cmp=oM({type:i,selectors:[["shared-nile-chart-widget"]],viewQuery:function(t,M){if(t&1&&rd(iUt,5),t&2){let n;Ic(n=dc())&&(M.chartRef=n.first)}},inputs:{config:"config",widgetId:"widgetId",widgetTitle:"widgetTitle",loading:"loading",drilldownBy:"drilldownBy",menu:"menu",dashboardFilters:"dashboardFilters",resolvedFilters:"resolvedFilters",dashboardId:"dashboardId",conversationId:"conversationId",cellFilterEnabled:[1,"cellFilterEnabled"]},outputs:{aiSend:"aiSend",sortChange:"sortChange",filterSubmit:"filterSubmit",filterChange:"filterChange",chartClick:"chartClick",chartSelection:"chartSelection",chartSelectionReset:"chartSelectionReset",gridFilterVerdict:"gridFilterVerdict",menuAction:"menuAction",cellFilter:"cellFilter",dataViewFilterChange:"dataViewFilterChange"},features:[Ro],ngContentSelectors:MUt,decls:1,vars:1,consts:[["nileChart",""],["fit",""],["slot","header-actions",1,"projected-actions"],["hoist","","placement","bottom-end"],["slot","trigger","type","button","aria-label","Switch chart view",1,"md-variant-toggle"],["name","ng-switch-horizontal-01","method","stroke","size","16"],[1,"md-variant-menu"],[1,"md-variant-divider"],[3,"click"],["slot","prefix","name","ng-refresh-ccw","method","stroke","size","14"],["slot","prefix","name","ng-check","method","stroke","size","14"]],template:function(t,M){t&1&&(ay(),xe(0,sUt,5,1,"nile-chart",1)),t&2&&pe(M.mounted?0:-1)},dependencies:[Pa],styles:["[_nghost-%COMP%]{display:block;width:100%;height:100%;overflow:hidden}nile-chart[_ngcontent-%COMP%]{display:block;width:100%;height:100%}nile-chart[_ngcontent-%COMP%]::part(ai-trigger){display:none}nile-chart[_ngcontent-%COMP%]::part(chart-card){border-bottom-left-radius:unset;border-bottom-right-radius:unset;border:unset}.projected-actions[_ngcontent-%COMP%]{display:flex;gap:12px;align-items:center}.md-variant-toggle[_ngcontent-%COMP%]{display:inline-flex;align-items:center;justify-content:center;padding:var(--ng-spacing-1);border:none;border-radius:var(--ng-radius-md);background:transparent;color:var(--ng-colors-fg-quaternary-400);cursor:pointer}.md-variant-toggle[_ngcontent-%COMP%]:hover{background:var(--ng-colors-bg-secondary);color:var(--ng-colors-text-primary-900)}.md-variant-divider[_ngcontent-%COMP%]{height:1px;margin:4px 8px;background:var(--ng-colors-border-secondary, #e9eaeb)}"]})};function wm(i){switch(i?.reason){case"no_applicable_field":return"Filter not applicable to this widget";case"execution_error":case"execution_error_fallback":return"Couldn't apply filter here";case"not_filterable_in_memory":return"Filtered on loaded data only";case"or_unsupported_for_widget":return"This widget can't combine those filters with OR";case"kpi_value_ambiguous":return"Couldn't identify this KPI's value under the filter";default:return"Filter not applied"}}var lUt=["bar"],nB=(i,e)=>e.id??e.label,jat=(i,e)=>e.id;function gUt(i,e){if(i&1){let t=Ee();C(0,"nile-menu-item",10),Te("click",function(){let n=R(t).$implicit,r=p();return V(r.addRow(n.id??n.name??n.label))}),v(1),k()}if(i&2){let t=e.$implicit;m(),hi(" ",t.label," ")}}function NUt(i,e){i&1&&Ot(0,"nile-skeleton-loader",8)}function uUt(i,e){if(i&1){let t=Ee();C(0,"button",28),Te("click",function(){R(t);let n=p().$implicit,r=p();return V(r.toggleConnector(n))}),v(1),k()}if(i&2){let t=p().$implicit,M=p();ji("mf-conn--disabled",M.disabled()),be("title",t.connector==="or"?"Matches EITHER side \u2014 click for AND":"Matches BOTH sides \u2014 click for OR"),mt("aria-label","Change join to previous filter (currently "+(t.connector==="or"?"OR":"AND")+")"),m(),it(t.connector==="or"?"OR":"AND")}}function DUt(i,e){if(i&1){let t=Ee();C(0,"nile-menu-item",10),Te("click",function(){let n=R(t).$implicit,r=p().$implicit,o=p();return V(o.changeOp(r,n))}),v(1),k()}if(i&2){let t=e.$implicit,M=p(2);m(),it(M.operatorLabels[t])}}function cUt(i,e){if(i&1){let t=Ee();C(0,"nile-select",29),Te("nile-change",function(n){R(t);let r=p().$implicit,o=p();return V(o.setScalar(r,n.target.value))}),C(1,"nile-option",30),v(2,"true"),k(),C(3,"nile-option",31),v(4,"false"),k()()}if(i&2){let t=p().$implicit;be("value",t.value)}}function IUt(i,e){if(i&1){let t=Ee();C(0,"nile-date-picker",34),Te("nile-change",function(n){R(t);let r=p(2).$implicit,o=p();return V(o.setRangeDate(r,n.detail))}),Ot(1,"nile-input",35),k()}if(i&2){let t=p(2).$implicit,M=p();be("dateFormat",M.dateFormatFor(t)),m(),be("value",M.rangeTriggerText(t))}}function dUt(i,e){if(i&1){let t=Ee();C(0,"nile-date-picker",36),Te("nile-change",function(n){R(t);let r=p(2).$implicit,o=p();return V(o.setSingleDate(r,n.detail))}),Ot(1,"nile-input",37),k()}if(i&2){let t=p(2).$implicit,M=p();be("dateFormat",M.dateFormatFor(t)),m(),be("value",M.singleTriggerText(t))}}function jUt(i,e){if(i&1&&xe(0,IUt,2,2,"nile-date-picker",32)(1,dUt,2,2,"nile-date-picker",33),i&2){let t=p().$implicit,M=p();pe(M.isBetween(t)?0:1)}}function yUt(i,e){if(i&1){let t=Ee();C(0,"div",19)(1,"nile-input",38),Te("nile-change",function(n){R(t);let r=p().$implicit,o=p();return V(o.setRangeMin(r,n.detail.value))}),k(),C(2,"span",39),v(3,"\u2013"),k(),C(4,"nile-input",40),Te("nile-change",function(n){R(t);let r=p().$implicit,o=p();return V(o.setRangeMax(r,n.detail.value))}),k()()}if(i&2){let t=p().$implicit;m(),be("value",t.rangeMin),m(3),be("value",t.rangeMax)}}function TUt(i,e){if(i&1){let t=Ee();C(0,"nile-input",41),Te("nile-change",function(n){R(t);let r=p().$implicit,o=p();return V(o.setScalar(r,n.detail==null?null:n.detail.value))}),k()}if(i&2){let t=p().$implicit;be("value",t.value)}}function AUt(i,e){if(i&1){let t=Ee();C(0,"nile-combobox",42),Te("nile-focus",function(){R(t);let n=p().$implicit,r=p();return V(r.listUsesFetcher(n)&&r.onTypeaheadSearch(n,""))})("nile-change",function(n){R(t);let r=p().$implicit,o=p();return V(o.isMulti(r)?o.setMulti(r,n.detail==null?null:n.detail.value):o.setScalar(r,n.detail==null?null:n.detail.value))}),k()}if(i&2){let t=p().$implicit,M=p();be("multiple",M.isMulti(t))("value",M.valueForControl(t))("autoCompleteOptions",M.listComboOptionsFor(t))("renderItemConfig",M.typeaheadRenderConfig)}}function zUt(i,e){if(i&1){let t=Ee();C(0,"nile-combobox",43),Te("nile-focus",function(){R(t);let n=p().$implicit,r=p();return V(r.onTypeaheadSearch(n,""))})("nile-search",function(n){R(t);let r=p().$implicit,o=p();return V(o.onTypeaheadSearchDebounced(r,(n.detail==null?null:n.detail.query)??""))})("nile-change",function(n){R(t);let r=p().$implicit,o=p();return V(o.isMulti(r)?o.setMulti(r,n.detail==null?null:n.detail.value):o.setScalar(r,n.detail==null?null:n.detail.value))}),k()}if(i&2){let t=p().$implicit,M=p();be("multiple",M.isMulti(t))("value",M.valueForControl(t))("autoCompleteOptions",M.typeaheadOptionsFor(t))("renderItemConfig",M.typeaheadRenderConfig)}}function hUt(i,e){if(i&1){let t=Ee();C(0,"nile-combobox",44),Te("nile-change",function(n){R(t);let r=p().$implicit,o=p();return V(o.setMulti(r,n.detail==null?null:n.detail.value))}),k()}if(i&2){let t=p().$implicit;be("value",t.values)}}function xUt(i,e){if(i&1){let t=Ee();C(0,"nile-combobox",45),Te("nile-change",function(n){R(t);let r=p().$implicit,o=p();return V(o.setScalar(r,n.detail==null?null:n.detail.value))}),k()}if(i&2){let t=p().$implicit,M=p();be("value",t.value)("autoCompleteOptions",M.listOptionsFor(t))}}function pUt(i,e){if(i&1){let t=Ee();C(0,"nile-menu-item",10),Te("click",function(){let n=R(t).$implicit,r=p(2).$implicit,o=p();return V(o.applyPreset(r,n.id))}),v(1),k()}if(i&2){let t=e.$implicit;m(),it(t.label)}}function LUt(i,e){if(i&1&&(C(0,"nile-dropdown",25)(1,"button",46),Ot(2,"nile-glyph",47),k(),C(3,"nile-menu"),xt(4,pUt,2,1,"nile-menu-item",null,jat),k()()),i&2){let t=p().$implicit,M=p();m(4),pt(M.relativePresetsFor(t))}}function OUt(i,e){if(i&1){let t=Ee();xe(0,uUt,2,5,"button",11),C(1,"div",12)(2,"span",13),v(3),k(),C(4,"nile-dropdown",14)(5,"button",15)(6,"span"),v(7),k(),Ot(8,"nile-glyph",16),k(),C(9,"nile-menu"),xt(10,DUt,2,1,"nile-menu-item",null,da),k()(),C(12,"div",17),xe(13,cUt,5,1,"nile-select",18)(14,jUt,2,1)(15,yUt,5,2,"div",19)(16,TUt,1,1,"nile-input",20)(17,AUt,1,4,"nile-combobox",21)(18,zUt,1,4,"nile-combobox",22)(19,hUt,1,1,"nile-combobox",23)(20,xUt,1,2,"nile-combobox",24),k(),xe(21,LUt,6,0,"nile-dropdown",25),C(22,"button",26),Te("click",function(){let n=R(t).$implicit,r=p();return V(r.removeRow(n))}),Ot(23,"nile-glyph",27),k()()}if(i&2){let t=e.$implicit,M=e.$index,n=p();pe(M>0?0:-1),m(3),it(n.labelFor(t.field)),m(4),it(n.operatorLabels[t.op]),m(3),pt(n.operatorsFor(t.field)),m(3),pe(n.isBoolean(t)?13:n.isDate(t)?14:n.isBetween(t)?15:n.fieldTypeFor(t.field)==="number"&&!n.isMulti(t)?16:n.valueModeOf(t)==="list"?17:n.usesTypeahead(t)?18:n.isMulti(t)?19:20),m(8),pe(n.relativePresetsFor(t).length?21:-1)}}function mUt(i,e){if(i&1){let t=Ee();C(0,"nile-menu-item",10),Te("click",function(){let n=R(t).$implicit,r=p(2);return V(r.addRow(n.id??n.name??n.label,"or"))}),v(1),k()}if(i&2){let t=e.$implicit;m(),it(t.label)}}function EUt(i,e){if(i&1){let t=Ee();C(0,"nile-menu-item",10),Te("click",function(){let n=R(t).$implicit,r=p(2);return V(r.addRow(n.id??n.name??n.label,"and"))}),v(1),k()}if(i&2){let t=e.$implicit;m(),it(t.label)}}function fUt(i,e){if(i&1){let t=Ee();C(0,"div",9)(1,"nile-dropdown",48)(2,"span",49)(3,"span",50),Ot(4,"nile-glyph",51),k(),v(5," OR "),k(),C(6,"nile-menu",7),Te("nile-search-value",function(n){R(t);let r=p();return V(r.attrSearch.set((n.detail==null?null:n.detail.value)??""))}),xt(7,mUt,2,1,"nile-menu-item",null,nB),k()(),C(9,"nile-dropdown",48)(10,"span",49)(11,"span",50),Ot(12,"nile-glyph",51),k(),v(13," AND "),k(),C(14,"nile-menu",7),Te("nile-search-value",function(n){R(t);let r=p();return V(r.attrSearch.set((n.detail==null?null:n.detail.value)??""))}),xt(15,EUt,2,1,"nile-menu-item",null,nB),k()(),C(17,"button",52),Te("click",function(){R(t);let n=p();return V(n.clearAll())}),Ot(18,"nile-glyph",27),v(19," Clear "),k()()}if(i&2){let t=p();m(2),ji("mf-conn-add__btn--disabled",t.disabled()),m(5),pt(t.menuAttributes()),m(3),ji("mf-conn-add__btn--disabled",t.disabled()),m(5),pt(t.menuAttributes())}}var SUt=/^-?\d+(\.\d+)?$/,wUt=0,CUt=()=>`mf-row-${++wUt}`,M3=class i{catalog=Et([]);conditions=Et([]);catalogLoading=Et(!1);disabled=Et(!1);valueFetcher=Et(null);onDashboardFields=Et([]);recentlyUsedFields=Et([]);attrSearch=Ye("");conditionsChange=rM();operatorLabels=Zh;expanded=Et(!1);contentHeight=rM();overflowCountChange=rM();overflowCount=-1;lastContentHeight=0;barRef=rf("bar");resizeObs;rows=Ye([]);typeaheadRowId=Ye(null);typeaheadOptions=Ye([]);typeaheadLoading=Ye(!1);static LOADING_VALUE="\0__loading__";static LOADING_ROW={value:"\0__loading__",label:"Loading\u2026"};typeaheadSeq=0;static TYPEAHEAD_DEBOUNCE_MS=250;typeaheadDebounce=null;inFlightFetchKey=null;lastEmittedKey="";constructor(){Co(()=>{let e=this.conditions(),t=wI(e);t!==this.lastEmittedKey&&(this.lastEmittedKey=t,this.rows.set(e.map(M=>this.conditionToRow(M))))},{allowSignalWrites:!0}),id(()=>{let e=this.barRef()?.nativeElement;!e||typeof ResizeObserver>"u"||(this.resizeObs=new ResizeObserver(()=>this.measureOverflow()),this.resizeObs.observe(e),this.measureOverflow())})}ngOnDestroy(){this.resizeObs?.disconnect(),this.typeaheadDebounce&&clearTimeout(this.typeaheadDebounce)}measureOverflow(){let e=this.barRef()?.nativeElement;if(!e)return;let t=Array.from(e.querySelectorAll(".mf-pill")),n=[...new Set(t.map(a=>Math.round(a.offsetTop)))].sort((a,s)=>a-s)[1],r=n===void 0?0:t.filter(a=>Math.round(a.offsetTop)>n).length;r!==this.overflowCount&&(this.overflowCount=r,this.overflowCountChange.emit(r));let o=e.scrollHeight;o!==this.lastContentHeight&&(this.lastContentHeight=o,this.contentHeight.emit(o))}attributes=Ft(()=>e3(this.catalog().filter(e=>e.type==="attribute").filter(e=>K2(e)),{onDashboard:this.onDashboardFields(),recentlyUsed:this.recentlyUsedFields()}));menuAttributes=Ft(()=>{let e=this.attrSearch(),t=this.attributes();return e?t.filter(M=>sat(M,e)):t});onDashboardSet=Ft(()=>new Set(this.onDashboardFields()));isOnDashboard(e){let t=this.onDashboardSet();return[e.id,e.name,e.label].some(M=>!!M&&t.has(M))}attrFor(e){return this.attributes().find(t=>t.id===e||t.name===e||t.label===e)}labelFor(e){return this.attrFor(e)?.label??e}fieldTypeFor(e){return this.attrFor(e)?.fieldType}operatorsFor(e){return q2(this.attrFor(e)??{})}defaultOperatorFor(e){return XV(this.attrFor(e)??{})}valueModeFor(e){let t=this.attrFor(e);return t?Em(t):"free"}isBetween(e){return e.op==="between"}isMulti(e){return e.op==="in"||e.op==="not in"}isDate(e){return this.fieldTypeFor(e.field)==="date"||/(^|[_\s])(date|time|timestamp|datetime)|_(at|on)$/i.test(e.field)?!0:(e.op==="between"?[e.rangeMin,e.rangeMax]:[e.value]).some(M=>typeof M=="string"&&/^\d{4}-\d{2}-\d{2}[T ]/.test(M.trim()))}isBoolean(e){return this.fieldTypeFor(e.field)==="boolean"}valueModeOf(e){return this.valueModeFor(e.field)}usesTypeahead(e){return this.valueModeOf(e)==="search"&&!!this.valueFetcher()}listOptionsFor(e){let M=this.attrFor(e.field)?.sampleValues;return M?.length?M.map(n=>({value:n,label:n})):this.catalog().filter(n=>n.type==="value"&&(!n.id||n.id===e.field)).map(n=>({value:n.label,label:n.label}))}listComboOptionsFor(e){let t=this.typeaheadOptionsFor(e);return t.length?t:this.listOptionsFor(e)}listUsesFetcher(e){return this.valueModeOf(e)==="list"&&!!this.valueFetcher()}relativePresetsFor(e){if(this.fieldTypeFor(e.field)!=="date")return[];let t=this.attrFor(e.field)?.relativePresets;return(t?.length?t:eB).filter(n=>tB(n.id))}dateFormatFor(e){return this.attrFor(e.field)?.format??"YYYY-MM-DD"}fmtDateHour(e){let t=String(e??"").trim();if(!t)return"";let M=new Date(t);return Number.isNaN(M.getTime())?t:M.toISOString().slice(0,16).replace("T"," ")}rangeTriggerText(e){let t=this.fmtDateHour(e.rangeMin),M=this.fmtDateHour(e.rangeMax);return t&&M?`${t} \u2013 ${M}`:t||M}singleTriggerText(e){return this.fmtDateHour(e.value)}typeaheadOptionsFor(e){if(this.typeaheadRowId()!==e.id)return[];let t=this.typeaheadOptions();return t.length===0&&this.typeaheadLoading()?[i.LOADING_ROW]:t}typeaheadRenderConfig={getDisplayText:e=>e.label,getSuffix:()=>""};addRow(e,t="and"){if(this.disabled())return;let M=this.blankRow(e,t);this.rows.update(n=>[...n,M]),this.commit()}toggleConnector(e){this.disabled()||this.patch(e,{connector:e.connector==="or"?"and":"or"})}changeOp(e,t){this.rows.update(M=>M.map(n=>{if(n.id!==e.id)return n;let r=_(x({},n),{op:t}),o=!this.opIsMulti(n.op)&&!this.opIsBetween(n.op),a=!this.opIsMulti(t)&&!this.opIsBetween(t);return o&&a||(r.value=this.fieldTypeFor(n.field)==="boolean"?"true":"",r.values=[],r.rangeMin="",r.rangeMax=""),r})),this.commit()}setScalar(e,t){let M=Array.isArray(t)?t[0]??"":t??"";M!==i.LOADING_VALUE&&this.patch(e,{value:M})}setMulti(e,t){let n=(Array.isArray(t)?t:t?[t]:[]).filter(r=>r!=null&&r!==""&&r!==i.LOADING_VALUE);this.patch(e,{values:n})}setRangeMin(e,t){this.patch(e,{rangeMin:t})}setRangeMax(e,t){this.patch(e,{rangeMax:t})}setSingleDate(e,t){this.patch(e,{value:this.toDateString(t?.value??t?.startDate)})}setRangeDate(e,t){this.patch(e,{rangeMin:this.toDateString(t?.startDate),rangeMax:this.toDateString(t?.endDate??t?.startDate)})}applyPreset(e,t){let M=t3(t);M&&this.patch(e,{op:"between",rangeMin:M.min,rangeMax:M.max})}removeRow(e){this.rows.update(t=>t.filter(M=>M.id!==e.id)),this.commit()}clearAll(){this.disabled()||(this.rows.set([]),this.commit())}onTypeaheadSearchDebounced(e,t){this.typeaheadDebounce&&clearTimeout(this.typeaheadDebounce),this.typeaheadDebounce=setTimeout(()=>{this.typeaheadDebounce=null,this.onTypeaheadSearch(e,t)},i.TYPEAHEAD_DEBOUNCE_MS)}async onTypeaheadSearch(e,t){this.typeaheadDebounce&&(clearTimeout(this.typeaheadDebounce),this.typeaheadDebounce=null);let M=this.valueFetcher();if(!M||!e.field)return;let n=`${e.id}\0${(t??"").trim()}`;if(n===this.inFlightFetchKey)return;this.inFlightFetchKey=n,this.typeaheadRowId()!==e.id&&this.typeaheadOptions.set([]),this.typeaheadRowId.set(e.id);let r=++this.typeaheadSeq;this.typeaheadLoading.set(!0);try{let o=await M(e.field,t??"");if(r!==this.typeaheadSeq)return;this.typeaheadOptions.set(o.map(a=>({value:String(a.value),label:a.label??String(a.value),observed:a.observed})))}catch{r===this.typeaheadSeq&&this.typeaheadOptions.set([])}finally{this.inFlightFetchKey===n&&(this.inFlightFetchKey=null),r===this.typeaheadSeq&&this.typeaheadLoading.set(!1)}}patch(e,t){this.rows.update(M=>M.map(n=>n.id===e.id?x(x({},n),t):n)),this.commit()}blankRow(e,t="and",M=CUt()){let n=lat(e),r=this.defaultOperatorFor(n),o=this.fieldTypeFor(n)==="boolean"?"true":"";return{id:M,field:n,op:r,value:o,values:[],rangeMin:"",rangeMax:"",connector:t}}opIsMulti(e){return e==="in"||e==="not in"}opIsBetween(e){return e==="between"}rowValid(e){if(!e.field)return!1;if(this.opIsBetween(e.op)){let t=e.rangeMin.trim(),M=e.rangeMax.trim();if(t===""||M==="")return!1;if(this.fieldTypeFor(e.field)==="number"){let n=Number(t),r=Number(M);if(Number.isFinite(n)&&Number.isFinite(r)&&n>r)return!1}else if(this.fieldTypeFor(e.field)==="date"&&t>M)return!1;return!0}return this.opIsMulti(e.op)?e.values.length>0:e.value.trim()!==""}rowToCondition(e){let t=this.fieldTypeFor(e.field),M={field:e.field,connector:e.connector};return this.opIsBetween(e.op)?_(x({},M),{op:"between",value:[this.coerce(e.rangeMin,t),this.coerce(e.rangeMax,t)]}):this.opIsMulti(e.op)?_(x({},M),{op:e.op,value:e.values.map(n=>this.coerce(n,t))}):t==="boolean"?_(x({},M),{op:"==",value:e.value==="true"}):_(x({},M),{op:e.op,value:this.coerce(e.value,t)})}conditionToRow(e){let t=this.blankRow(e.field,e.connector??"and");return t.op=e.op,e.op==="between"&&Array.isArray(e.value)?(t.rangeMin=String(e.value[0]??""),t.rangeMax=String(e.value[1]??"")):(e.op==="in"||e.op==="not in")&&Array.isArray(e.value)?t.values=e.value.map(M=>String(M)):t.value=String(e.value),t}commit(){let e=this.rows().filter(M=>this.rowValid(M)).map(M=>this.rowToCondition(M)),t=wI(e);t!==this.lastEmittedKey&&(this.lastEmittedKey=t,this.conditionsChange.emit(e))}coerce(e,t){return t==="date"?e:(t==="number"||t===void 0)&&SUt.test(e)?Number(e):e}toDateString(e){if(!e)return"";if(typeof e=="string"){let o=e.match(/^(\d{4})-(\d{2})-(\d{2})/);if(o)return`${o[1]}-${o[2]}-${o[3]}`}let t=new Date(e);if(isNaN(t.getTime()))return typeof e=="string"?e:"";let M=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${M}-${n}-${r}`}valueForControl(e){return this.isMulti(e)?e.values:e.value}static \u0275fac=function(t){return new(t||i)};static \u0275cmp=oM({type:i,selectors:[["shared-manual-filter-panel"]],viewQuery:function(t,M){t&1&&Mf(M.barRef,lUt,5),t&2&&nf()},inputs:{catalog:[1,"catalog"],conditions:[1,"conditions"],catalogLoading:[1,"catalogLoading"],disabled:[1,"disabled"],valueFetcher:[1,"valueFetcher"],onDashboardFields:[1,"onDashboardFields"],recentlyUsedFields:[1,"recentlyUsedFields"],expanded:[1,"expanded"]},outputs:{conditionsChange:"conditionsChange",contentHeight:"contentHeight",overflowCountChange:"overflowCountChange"},decls:15,vars:6,consts:[["bar",""],[1,"mf-panel"],[1,"mf-panel__clip"],[1,"mf-panel__bar"],["hoist","","placement","bottom-start",1,"mf-add"],["slot","trigger",1,"mf-add__btn"],["name","ng-list-filter","method","stroke","size","14","color","#155EEFFF"],["searchEnabled","","customSearch","",3,"nile-search-value"],["variant","rounded","width","200","height","34"],[1,"mf-actions"],[3,"click"],["type","button",1,"mf-conn","mf-conn--toggle",3,"mf-conn--disabled","title"],[1,"mf-pill"],[1,"mf-seg","mf-seg--field"],["hoist","","placement","bottom-start",1,"mf-pill__menu"],["slot","trigger","type","button",1,"mf-seg","mf-seg--op"],["name","ng-chevron-down","method","stroke","size","12"],[1,"mf-seg","mf-seg--value"],["size","small","hoist","",3,"value"],[1,"mf-range"],["size","small","type","number","placeholder","Value",3,"value"],["size","small","hoist","","portal","","clearable","","allowCustomValue","","placeholder","Value",3,"multiple","value","autoCompleteOptions","renderItemConfig"],["size","small","hoist","","portal","","clearable","","allowCustomValue","","disableLocalSearch","","placeholder","Search\u2026",3,"multiple","value","autoCompleteOptions","renderItemConfig"],["size","small","hoist","","portal","","clearable","","allowCustomValue","","multiple","","placeholder","Add values",3,"value"],["size","small","hoist","","portal","","clearable","","allowCustomValue","","placeholder","Value","noDataMessage","Type a value",3,"value","autoCompleteOptions"],["hoist","","placement","bottom-start",1,"mf-pill__menu","borders"],["type","button","aria-label","Remove filter",1,"mf-pill__x",3,"click"],["name","ng-x-close","method","stroke","size","12"],["type","button",1,"mf-conn","mf-conn--toggle",3,"click","title"],["size","small","hoist","",3,"nile-change","value"],["value","true"],["value","false"],["range","","allowClear","",3,"dateFormat"],["allowClear","",3,"dateFormat"],["range","","allowClear","",3,"nile-change","dateFormat"],["slot","trigger","size","small","placeholder","Date range",3,"value"],["allowClear","",3,"nile-change","dateFormat"],["slot","trigger","size","small","placeholder","Pick a date",3,"value"],["size","small","type","number","placeholder","Min",3,"nile-change","value"],[1,"mf-range__sep"],["size","small","type","number","placeholder","Max",3,"nile-change","value"],["size","small","type","number","placeholder","Value",3,"nile-change","value"],["size","small","hoist","","portal","","clearable","","allowCustomValue","","placeholder","Value",3,"nile-focus","nile-change","multiple","value","autoCompleteOptions","renderItemConfig"],["size","small","hoist","","portal","","clearable","","allowCustomValue","","disableLocalSearch","","placeholder","Search\u2026",3,"nile-focus","nile-search","nile-change","multiple","value","autoCompleteOptions","renderItemConfig"],["size","small","hoist","","portal","","clearable","","allowCustomValue","","multiple","","placeholder","Add values",3,"nile-change","value"],["size","small","hoist","","portal","","clearable","","allowCustomValue","","placeholder","Value","noDataMessage","Type a value",3,"nile-change","value","autoCompleteOptions"],["slot","trigger","type","button","title","Relative date",1,"mf-seg","mf-seg--preset"],["name","ng-calendar","method","stroke","size","12"],["hoist","","placement","bottom-end",1,"mf-conn-add"],["slot","trigger",1,"mf-conn-add__btn"],[1,"mf-conn-add__ring"],["name","ng-plus","method","stroke","size","10"],["type","button",1,"mf-clear",3,"click"]],template:function(t,M){t&1&&(C(0,"div",1)(1,"div",2)(2,"div",3,0)(4,"nile-dropdown",4)(5,"span",5),Ot(6,"nile-glyph",6),v(7," Add filter "),k(),C(8,"nile-menu",7),Te("nile-search-value",function(r){return M.attrSearch.set((r.detail==null?null:r.detail.value)??"")}),xt(9,gUt,2,1,"nile-menu-item",null,nB),k()(),xe(11,NUt,1,0,"nile-skeleton-loader",8),xt(12,OUt,24,5,null,null,jat),xe(14,fUt,20,4,"div",9),k()()()),t&2&&(m(),ji("mf-panel__clip--collapsed",!M.expanded()),m(4),ji("mf-add__btn--disabled",M.disabled()),m(4),pt(M.menuAttributes()),m(2),pe(M.catalogLoading()&&!M.rows().length?11:-1),m(),pt(M.rows()),m(2),pe(M.rows().length?14:-1))},dependencies:[Pa],styles:["[_nghost-%COMP%]{display:flex;width:100%;height:100%;overflow:visible}.mf-panel[_ngcontent-%COMP%]{position:relative;display:flex;flex-direction:column;width:100%;height:100%;padding:var(--ng-spacing-4) var(--ng-spacing-5) 0 var(--ng-spacing-5)}.mf-panel__bar[_ngcontent-%COMP%]{position:relative;display:flex;flex-wrap:wrap;align-items:center;gap:var(--ng-spacing-2);min-width:0;padding-right:200px}.mf-pill[_ngcontent-%COMP%]{display:inline-flex;align-items:stretch;height:34px;border:1px solid var(--ng-colors-border-secondary);border-radius:var(--ng-radius-md);background:var(--ng-colors-bg-primary);overflow:hidden}.mf-pill__menu[_ngcontent-%COMP%]{display:inline-flex}.borders[_ngcontent-%COMP%]{border-right:1px solid var(--ng-colors-border-secondary)}.mf-seg[_ngcontent-%COMP%]{display:inline-flex;align-items:center;gap:var(--ng-spacing-1);height:100%;padding:0 var(--ng-spacing-2);border:none;background:transparent;font:inherit;font-size:13px;color:var(--ng-colors-text-primary-900);white-space:nowrap;cursor:pointer}.mf-seg--field[_ngcontent-%COMP%]{font-weight:500;border-right:1px solid var(--ng-colors-border-primary);cursor:default}.mf-seg--op[_ngcontent-%COMP%]:hover, .mf-seg--preset[_ngcontent-%COMP%]:hover{background:var(--ng-colors-bg-secondary)}.mf-seg[_ngcontent-%COMP%] nile-glyph[_ngcontent-%COMP%]{color:var(--ng-colors-fg-quaternary-400)}.mf-seg--value[_ngcontent-%COMP%]{padding:0;cursor:default}.mf-seg--value[_ngcontent-%COMP%] nile-input[_ngcontent-%COMP%], .mf-seg--value[_ngcontent-%COMP%] nile-combobox[_ngcontent-%COMP%], .mf-seg--value[_ngcontent-%COMP%] nile-select[_ngcontent-%COMP%], .mf-seg--value[_ngcontent-%COMP%] nile-date-picker[_ngcontent-%COMP%]{--nile-input-border-color: transparent;min-width:120px}.mf-seg--value[_ngcontent-%COMP%] nile-date-picker[_ngcontent-%COMP%]{--nile-input-standard-border-color: transparent;--nile-input-standard-background-color: transparent}.mf-seg--value[_ngcontent-%COMP%] nile-date-picker[_ngcontent-%COMP%] nile-input[_ngcontent-%COMP%]{min-width:280px}.mf-range[_ngcontent-%COMP%]{display:inline-flex;align-items:center;gap:var(--ng-spacing-1)}.mf-range[_ngcontent-%COMP%] nile-input[_ngcontent-%COMP%]{min-width:72px}.mf-range__sep[_ngcontent-%COMP%]{color:var(--ng-colors-text-secondary-700)}.mf-pill__x[_ngcontent-%COMP%]{display:inline-flex;align-items:center;justify-content:center;padding:0 var(--ng-spacing-2);border:none;background:transparent;color:var(--ng-colors-fg-quaternary-400);cursor:pointer}.mf-pill__x[_ngcontent-%COMP%]:hover{color:var(--ng-colors-fg-error-primary);background:var(--ng-colors-bg-error-primary)}.mf-add[_ngcontent-%COMP%]{display:inline-flex}.mf-add__btn[_ngcontent-%COMP%]{display:inline-flex;align-items:center;gap:var(--ng-spacing-1);height:34px;font:inherit;font-size:14px;font-weight:500;color:var(--ng-colors-fg-brand-primary-600);cursor:pointer}.mf-add__btn[_ngcontent-%COMP%] nile-glyph[_ngcontent-%COMP%]{color:var(--ng-colors-fg-quaternary-400)}.mf-add__btn--disabled[_ngcontent-%COMP%]{pointer-events:none;opacity:.5}.mf-clear[_ngcontent-%COMP%]{display:inline-flex;align-items:center;gap:var(--ng-spacing-1);height:34px;padding:0 var(--ng-spacing-3);border:1px solid var(--ng-colors-border-secondary);border-radius:var(--ng-radius-md);background:var(--ng-colors-bg-primary);font:inherit;font-size:13px;font-weight:500;color:var(--ng-colors-text-secondary-700);cursor:pointer}.mf-clear[_ngcontent-%COMP%]:hover{color:var(--ng-colors-fg-error-primary)}.mf-panel__clip--collapsed[_ngcontent-%COMP%]{max-height:calc(68px + var(--ng-spacing-2));overflow:hidden}.mf-actions[_ngcontent-%COMP%]{position:absolute;top:0;right:0;display:inline-flex;align-items:center;gap:var(--ng-spacing-2)}.mf-conn-add__btn[_ngcontent-%COMP%]{display:inline-flex;align-items:center;gap:var(--ng-spacing-1);height:34px;font-size:14px;font-weight:500;color:var(--ng-colors-fg-brand-primary-600);cursor:pointer}.mf-conn-add__btn[_ngcontent-%COMP%] nile-glyph[_ngcontent-%COMP%]{color:var(--ng-colors-fg-brand-primary-600)}.mf-conn-add__ring[_ngcontent-%COMP%]{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;border:1px solid currentColor;border-radius:50%}.mf-conn-add__btn--disabled[_ngcontent-%COMP%]{pointer-events:none;opacity:.5}.mf-conn[_ngcontent-%COMP%]{display:inline-flex;align-items:center;font-size:11px;font-weight:600;color:var(--ng-colors-text-tertiary-600)}.mf-conn--toggle[_ngcontent-%COMP%]{padding:2px var(--ng-spacing-1);border:1px solid transparent;border-radius:var(--ng-radius-xs, 4px);background:none;font:inherit;font-size:11px;font-weight:600;line-height:1;color:var(--ng-colors-text-tertiary-600);cursor:pointer}.mf-conn--toggle[_ngcontent-%COMP%]:hover, .mf-conn--toggle[_ngcontent-%COMP%]:focus-visible{border-color:var(--ng-colors-border-brand-solid, currentColor);color:var(--ng-colors-fg-brand-primary-600)}.mf-conn--toggle[_ngcontent-%COMP%]:focus-visible{outline:none}.mf-conn--disabled[_ngcontent-%COMP%]{pointer-events:none;opacity:.5}"]})};var kUt=(i,e)=>e.mode,bUt=(i,e)=>e.label,QUt=(i,e)=>e.id,UUt=(i,e)=>e.op;function vUt(i,e){if(i&1){let t=Ee();q(0,"button",17),Fe("click",function(){let n=R(t).$implicit,r=p(),o=GA(3);return r.pickMode(n.mode),V(o.hide())}),It(1,"nile-glyph",18),q(2,"span",19)(3,"span",20),v(4),Me(),q(5,"span",21),v(6),Me()(),q(7,"span",22),v(8),Me()()}if(i&2){let t=e.$implicit,M=p();ji("is-active",t.mode===M.activeMode().mode),mt("aria-checked",t.mode===M.activeMode().mode),m(),Lt("name",t.icon),m(3),it(t.label),m(2),it(t.desc),m(2),it(t.mode===M.activeMode().mode?"\u2713":"")}}function YUt(i,e){if(i&1){let t=Ee();q(0,"button",31),Fe("click",function(){R(t);let n=p().$index,r=p(2);return V(r.toggleJoin(n))}),v(1),Me()}if(i&2){let t=p().$implicit,M=p(2);Lt("disabled",M.busy()),mt("aria-label","Join with "+(t.connector==="or"?"OR":"AND")+" \u2014 click to change"),m(),it(t.connector==="or"?"OR":"AND")}}function ZUt(i,e){if(i&1){let t=Ee();xe(0,YUt,2,3,"button",25),q(1,"span",26)(2,"span",27),v(3),Me(),q(4,"span",28),v(5),Me(),q(6,"span",29),v(7),Me(),q(8,"button",30),Fe("click",function(){let n=R(t).$index,r=p(2);return V(r.removeChip(n))}),v(9,"\u2715"),Me()()}if(i&2){let t=e.$implicit,M=e.$index,n=p(2);pe(M>0?0:-1),m(3),it(n.fieldLabel(t.field)),m(2),it(n.opLabel(t.op)),m(2),it(n.valueLabel(t)),m(),Lt("disabled",n.busy()),mt("aria-label","Remove filter "+n.fieldLabel(t.field))}}function _Ut(i,e){if(i&1){let t=Ee();q(0,"div",12),xt(1,ZUt,10,6,null,null,Yr),q(3,"span",23)(4,"nile-button",24),Fe("click",function(){R(t);let n=p();return V(n.openCondPop())}),v(5," + Add filter "),Me()()()}if(i&2){let t=p();m(),pt(t.conditions()),m(3),mt("disabled",t.busy()?"":null)}}function WUt(i,e){if(i&1&&(q(0,"span",43),v(1),Me()),i&2){let t=p(2);ji("is-error",!!t.exprState().error)("is-warn",t.exprState().partial),m(),it(t.exprState().error?"!":t.exprState().partial?"~":"\u2713")}}function PUt(i,e){if(i&1&&It(0,"span",46),i&2){let t=e.$implicit;dM("width",t,"%")}}function RUt(i,e){if(i&1&&(xt(0,PUt,1,2,"span",44,da),q(2,"span",45),v(3,"Loading values\u2026"),Me()),i&2){let t=p(3);pt(t.skeletonRows)}}function VUt(i,e){if(i&1){let t=Ee();q(0,"button",48),Fe("click",function(){let n=R(t).$implicit,r=p(4);return V(r.applySuggestion(n.insert))}),q(1,"span",49),v(2),Me(),q(3,"span",50),v(4),Me()()}if(i&2){let t=e.$implicit;m(2),it(t.label),m(),ji("is-badge",t.hint==="CONNECTOR"||t.hint==="KEYWORD"||t.hint==="value"),m(),it(t.hint)}}function BUt(i,e){if(i&1&&xt(0,VUt,5,4,"button",47,bUt),i&2){let t=p(3);pt(t.suggestions())}}function FUt(i,e){if(i&1&&(q(0,"span",37),xe(1,RUt,4,0)(2,BUt,2,0),Me()),i&2){let t=p(2);mt("aria-busy",t.suggestLoading()),m(),pe(t.suggestLoading()?1:2)}}function HUt(i,e){if(i&1&&(q(0,"span",39),v(1),Me()),i&2){let t=p(2);m(),it(t.exprState().error)}}function JUt(i,e){i&1&&(q(0,"span",40),v(1,"Valid, but "),q(2,"code"),v(3,"or"),Me(),v(4," / bare "),q(5,"code"),v(6,"not"),Me(),v(7," / grouping are dropped on apply."),Me())}function GUt(i,e){i&1&&(q(0,"span",41),v(1,"Valid"),Me())}function $Ut(i,e){if(i&1){let t=Ee();q(0,"span",32)(1,"span",33),It(2,"nile-glyph",34),Me(),q(3,"input",35),Fe("ngModelChange",function(n){R(t);let r=p();return r.exprDraft.set(n),V(r.suggestDismissed.set(!1))})("focus",function(){R(t);let n=p();return V(n.suggestDismissed.set(!1))})("keydown",function(n){R(t);let r=p();return V(r.onExprKeydown(n))}),Me(),xe(4,WUt,2,5,"span",36),xe(5,FUt,3,2,"span",37),Me(),q(6,"span",38),xe(7,HUt,2,1,"span",39)(8,JUt,8,0,"span",40)(9,GUt,2,0,"span",41),Me(),q(10,"nile-button",42),Fe("click",function(){R(t);let n=p();return V(n.runExpression())}),v(11,"Run"),Me()}if(i&2){let t=p();ji("is-error",t.exprState().error),m(3),Lt("disabled",t.busy())("ngModel",t.exprDraft()),mt("aria-expanded",t.suggestions().length>0),m(),pe(t.exprState().empty?-1:4),m(),pe(t.suggestLoading()||t.suggestions().length?5:-1),m(2),pe(t.exprState().error?7:t.exprState().partial?8:t.exprState().ok?9:-1),m(3),mt("disabled",t.busy()||!t.exprState().ok?"":null)}}function XUt(i,e){if(i&1){let t=Ee();q(0,"span",51)(1,"span",52),It(2,"nile-glyph",53),Me(),q(3,"input",54),Fe("ngModelChange",function(n){R(t);let r=p();return V(r.promptDraft.set(n))})("keydown",function(n){R(t);let r=p();return V(r.onPromptKeydown(n))}),Me()(),q(4,"nile-button",42),Fe("click",function(){R(t);let n=p();return V(n.askPrompt())}),v(5,"Ask"),Me()}if(i&2){let t=p();m(3),Lt("disabled",t.busy())("ngModel",t.promptDraft()),m(),mt("disabled",t.busy()||!t.promptDraft().trim()?"":null)}}function qUt(i,e){if(i&1&&(q(0,"span",14),v(1),Me()),i&2){let t=p();m(),Bo("",t.chipCount()," ",t.chipCount()===1?"filter":"filters")}}function KUt(i,e){if(i&1&&(q(0,"nile-option",60),v(1),Me()),i&2){let t=e.$implicit;Lt("value",t.id),m(),it(t.label)}}function evt(i,e){if(i&1&&(q(0,"nile-option",60),v(1),Me()),i&2){let t=e.$implicit;Lt("value",t.op),m(),it(t.label)}}function tvt(i,e){i&1&&(q(0,"span",62),It(1,"span",69),Me())}function ivt(i,e){if(i&1&&(q(0,"nile-option",60),v(1),Me()),i&2){let t=e.$implicit;Lt("value",t),m(),it(t)}}function Mvt(i,e){if(i&1){let t=Ee();q(0,"nile-select",70),Fe("nile-change",function(n){R(t);let r=p(2);return V(r.draftValue.set(n.target.value))}),xt(1,ivt,2,2,"nile-option",60,da),Me()}if(i&2){let t=p(2);Lt("value",t.draftValue()),m(),pt(t.draftValueOptions())}}function nvt(i,e){if(i&1){let t=Ee();q(0,"nile-input",71),Fe("nile-change",function(n){R(t);let r=p(2);return V(r.draftValue.set(n.target.value))}),Me()}if(i&2){let t=p(2);Lt("value",t.draftValue())}}function rvt(i,e){if(i&1){let t=Ee();q(0,"div",65)(1,"span",72),v(2,"Join with"),Me(),q(3,"div",73)(4,"button",74),Fe("click",function(){R(t);let n=p(2);return V(n.draftJoin.set("and"))}),v(5,"AND"),Me(),q(6,"button",74),Fe("click",function(){R(t);let n=p(2);return V(n.draftJoin.set("or"))}),v(7,"OR"),Me()()()}if(i&2){let t=p(2);m(4),ji("is-active",t.draftJoin()==="and"),m(2),ji("is-active",t.draftJoin()==="or")}}function ovt(i,e){if(i&1){let t=Ee();q(0,"div",16)(1,"div",55)(2,"span",56),v(3,"Add condition"),Me(),q(4,"span",57),v(5,"Manual filters"),Me()(),q(6,"div",58)(7,"nile-select",59),Fe("nile-change",function(n){R(t);let r=p();return V(r.onDraftFieldChange(n.target.value))}),xt(8,KUt,2,2,"nile-option",60,QUt),Me(),q(10,"nile-select",61),Fe("nile-change",function(n){R(t);let r=p();return V(r.onDraftOpChange(n.target.value))}),xt(11,evt,2,2,"nile-option",60,UUt),Me(),xe(13,tvt,2,0,"span",62)(14,Mvt,3,1,"nile-select",63)(15,nvt,1,1,"nile-input",64),Me(),xe(16,rvt,8,4,"div",65),q(17,"div",66)(18,"nile-button",67),Fe("click",function(){R(t);let n=p();return V(n.condPopOpen.set(!1))}),v(19,"Cancel"),Me(),q(20,"nile-button",68),Fe("click",function(){R(t);let n=p();return V(n.applyDraft())}),v(21,"Apply filter"),Me()()()}if(i&2){let t=p();m(7),Lt("value",t.draftField()),m(),pt(t.fields()),m(2),Lt("value",t.draftOp()),m(),pt(t.operators),m(2),pe(t.draftValuesLoading()?13:t.draftValueOptions().length?14:15),m(3),pe(t.conditions().length?16:-1),m(4),mt("disabled",t.canApplyDraft()?null:"")}}var avt=new Set(["NILE-SELECT","NILE-OPTION","NILE-INPUT"]);function svt(i){let t=(i instanceof Error?i.message:String(i)).split(`
|
|
40483
|
+
>`}let a=`mf-viz__num${E5t(t)}`;return j`<span class=${a}>${FV(r,t,o)}</span>`}})})}var pm=null;function HV(i){let e=i.shadowRoot;e&&(pm||(pm=new CSSStyleSheet,pm.replaceSync(L5t)),!e.adoptedStyleSheets.includes(pm)&&(e.adoptedStyleSheets=[...e.adoptedStyleSheets,pm]))}function F2(i){if(Array.isArray(i))return i.map(e=>{let t=e;return Array.isArray(t.columns)?_(x({},t),{columns:F2(t.columns)}):t.cell||!t.accessorKey||t.type==="checkbox"||t.type==="select"?t:_(x({},t),{cell:M=>{if(M.value===void 0||M.value===null||M.value==="")return"";let n=String(M.value);return j`<span class="mf-text" title=${n}>${M.value}</span>`}})})}var JV=CJ??kJ;JV.addBinaryOp?.("~=",6);var G2=JV,f5t=new Set(["==","!=","<","<=",">",">=","~="]);function H2(i){return!!i&&i.type==="Identifier"}function S5t(i){return!!i&&i.type==="CallExpression"}function w5t(i){return S5t(i)&&H2(i.callee)&&i.callee.name==="in"}function J2(i,e){if(!(!i||typeof i!="object")){if(i.type==="BinaryExpression"){let t=i;f5t.has(t.operator)&&(H2(t.left)&&e(t.left.name),J2(t.left,e),J2(t.right,e));return}if(i.type==="Compound"){nat(i.body,e);return}}}function nat(i,e){let t=0;for(;t<i.length;){let M=i[t];if(H2(M)){let n=t+1;if(H2(i[n])&&i[n].name==="not"&&(n+=1),w5t(i[n])){e(M.name),t=n+1;continue}t+=1;continue}J2(M,e),t+=1}}function C5t(i,e){let t;try{t=JV(i)}catch{return}t.type==="Compound"?nat(t.body,e):J2(t,e)}function $2(i,e){let t=new Set,M=[],n=r=>{!r||t.has(r)||(t.add(r),M.push(r))};for(let r of Object.values(i||{}))typeof r!="string"||r.trim()===""||C5t(r,n);return M.map(r=>({field:r,label:e(r)||r}))}var Om=["==","!=","<","<=",">",">=","~="],Zh={"==":"is","!=":"is not","~=":"contains","<":"less than","<=":"at most",">":"greater than",">=":"at least",in:"is any of","not in":"is none of",between:"between"},k5t=/int|decimal|numeric|float|double|real|number|long|money/,b5t=/^(boolean|bool|bit)$/,Q5t=/^(date|datetime2?|datetimeoffset|smalldatetime|timestamptz|timestamp)\b/;function IA(i){return!!i&&k5t.test(i.toLowerCase())}function U5t(i){return!!i&&b5t.test(i.toLowerCase())}function mm(i){return!!i&&Q5t.test(i.trim().toLowerCase())}var v5t=["==","!=","in","not in"],Y5t=["~=","==","!=","in"],Z5t=["==","!=",">","<",">=","<=","between"],_5t=["==","<",">","between"],W5t=["=="];function aat(i,e){switch(i){case"number":return[...Z5t];case"date":return[..._5t];case"boolean":return[...W5t];case"string":return e==="list"?[...v5t]:[...Y5t];default:return[...Om]}}var P5t=new Set(["==","!=","<","<=",">",">=","~=","in","not in","between"]);function q2(i){let e=(i.operators??[]).filter(t=>P5t.has(t));return e.length?e:aat(i.fieldType,Em(i))}function XV(i){let e=q2(i);return e.find(t=>t!=="between")??e[0]??"=="}function Em(i){return i.valueMode?i.valueMode:i.fieldType==="boolean"||i.enumerable||i.sampleValues?.length?"list":"free"}var R5t=1e4,V5t=/(password|passwd|secret|credential|api[_-]?key|access[_-]?key|private[_-]?key|token|_enc$|_encrypted$|magic[_-]?link|magic[_-]?token|ssn|social[_-]?security)/i;function K2(i){return i.suggestible===!1||i.piiExcluded===!0?!1:i.suggestible===!0?!0:![i.id,i.name,i.label].some(e=>typeof e=="string"&&V5t.test(e))}function rat(i){return[i.id,i.name,i.label].filter(e=>!!e)}function B5t(i){return!(Em(i)==="free"||typeof i.cardinality=="number"&&i.cardinality>R5t)}function sat(i,e){let t=(e??"").trim().toLowerCase();return t?[i.label,i.name,i.id,i.semanticType].some(M=>typeof M=="string"&&M.toLowerCase().includes(t)):!0}function e3(i,e={}){let t=new Set(e.onDashboard??[]),M=e.recentlyUsed??[],n=l=>{let N=1/0;for(let D of rat(l)){let c=M.indexOf(D);c!==-1&&c<N&&(N=c)}return N},r=l=>rat(l).some(N=>t.has(N)),o=l=>r(l)?0:n(l)!==1/0?1:B5t(l)?2:3,a=i.map((l,N)=>({a:l,i:N,tier:o(l),rec:n(l)}));if(!a.some(l=>l.tier<=1))return i.slice();let s=l=>(l.label??"").toLowerCase();return a.sort((l,N)=>{if(l.tier!==N.tier)return l.tier-N.tier;if(l.tier===1&&l.rec!==N.rec)return l.rec-N.rec;let D=s(l.a).localeCompare(s(N.a));return D!==0?D:l.i-N.i}).map(l=>l.a)}function F5t(i){return i.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function X2(i){return typeof i=="number"||typeof i=="boolean"?String(i):`"${F5t(i)}"`}function H5t(i){let e=String(i);return/^[\w.]+$/.test(e)?e:`'${e.replace(/'/g,"\\'")}'`}function lat(i){let e=String(i).trim();return e.length>=2&&e.startsWith("'")&&e.endsWith("'")?e.slice(1,-1).replace(/\\'/g,"'"):e}function $V(i){let{op:e,value:t}=i,M=H5t(i.field);return e==="between"&&Array.isArray(t)&&t.length===2?`${M} >= ${X2(t[0])} and ${M} <= ${X2(t[1])}`:(e==="in"||e==="not in")&&Array.isArray(t)?`${M} ${e} (${t.map(X2).join(", ")})`:`${M} ${e} ${X2(t)}`}function wI(i){if(!i.length)return"";let e=$V(i[0]);for(let t=1;t<i.length;t++)e+=` ${i[t].connector??"and"} ${$V(i[t])}`;return e}var J5t={"==":"==","=":"==",eq:"==",equals:"==","!=":"!=","<>":"!=",ne:"!=",neq:"!=",">":">",gt:">",">=":">=",gte:">=","<":"<",lt:"<","<=":"<=",lte:"<=","~=":"~=",contains:"~=",like:"~=",in:"in","not in":"not in",notin:"not in",between:"between"};function G5t(i){if(typeof i=="string"||typeof i=="number"||typeof i=="boolean")return i;if(Array.isArray(i)){let e=i.filter(t=>typeof t=="string"||typeof t=="number");return e.length?e:void 0}}function fm(i){let e=[];for(let t of i){let M=t.operation?J5t[t.operation.trim().toLowerCase()]:void 0,n=G5t(t.value);if(!t.field||!M||n===void 0)continue;let r=Array.isArray(n);M==="between"&&!(r&&n.length===2)||(M==="in"||M==="not in")&&!r||M!=="between"&&M!=="in"&&M!=="not in"&&r||e.push({field:t.field,op:M,value:n})}return e}function qV(i){return i.op==="between"&&Array.isArray(i.value)?`${i.value[0]} \u2013 ${i.value[1]}`:Array.isArray(i.value)?i.value.join(", "):String(i.value)}function KV(i,e){let t=r=>`${r.field}\0${r.op}\0${JSON.stringify(r.value)}`,M=new Set(i.map(t)),n=[...i];for(let r of e){let o=t(r);M.has(o)||(M.add(o),n.push(r))}return n}var eB=[{id:"today",label:"Today"},{id:"yesterday",label:"Yesterday"},{id:"last_7_days",label:"Last 7 days"},{id:"last_30_days",label:"Last 30 days"},{id:"last_90_days",label:"Last 90 days"},{id:"wtd",label:"Week to date"},{id:"mtd",label:"Month to date"},{id:"qtd",label:"Quarter to date"},{id:"ytd",label:"Year to date"},{id:"this_week",label:"This week"},{id:"last_week",label:"Last week"},{id:"this_month",label:"This month"},{id:"last_month",label:"Last month"},{id:"this_quarter",label:"This quarter"},{id:"last_quarter",label:"Last quarter"},{id:"this_year",label:"This year"},{id:"last_year",label:"Last year"}];function xM(i){let e=i.getFullYear(),t=String(i.getMonth()+1).padStart(2,"0"),M=String(i.getDate()).padStart(2,"0");return`${e}-${t}-${M}`}function Ej(i,e){let t=new Date(i);return t.setDate(t.getDate()+e),t}function GV(i){let e=new Date(i.getFullYear(),i.getMonth(),i.getDate()),t=(e.getDay()+6)%7;return Ej(e,-t)}function t3(i,e=new Date){let t=new Date(e.getFullYear(),e.getMonth(),e.getDate()),M=t.getFullYear(),n=t.getMonth(),r=Math.floor(n/3);switch(i){case"today":return{min:xM(t),max:xM(t)};case"yesterday":{let o=Ej(t,-1);return{min:xM(o),max:xM(o)}}case"last_7_days":return{min:xM(Ej(t,-6)),max:xM(t)};case"last_30_days":return{min:xM(Ej(t,-29)),max:xM(t)};case"last_90_days":return{min:xM(Ej(t,-89)),max:xM(t)};case"wtd":return{min:xM(GV(t)),max:xM(t)};case"this_week":{let o=GV(t);return{min:xM(o),max:xM(Ej(o,6))}}case"last_week":{let o=Ej(GV(t),-7);return{min:xM(o),max:xM(Ej(o,6))}}case"mtd":return{min:xM(new Date(M,n,1)),max:xM(t)};case"this_month":return{min:xM(new Date(M,n,1)),max:xM(new Date(M,n+1,0))};case"last_month":return{min:xM(new Date(M,n-1,1)),max:xM(new Date(M,n,0))};case"qtd":return{min:xM(new Date(M,r*3,1)),max:xM(t)};case"this_quarter":return{min:xM(new Date(M,r*3,1)),max:xM(new Date(M,r*3+3,0))};case"last_quarter":{let o=r===0?{yr:M-1,qi:3}:{yr:M,qi:r-1};return{min:xM(new Date(o.yr,o.qi*3,1)),max:xM(new Date(o.yr,o.qi*3+3,0))}}case"ytd":return{min:xM(new Date(M,0,1)),max:xM(t)};case"this_year":return{min:xM(new Date(M,0,1)),max:xM(new Date(M,11,31))};case"last_year":return{min:xM(new Date(M-1,0,1)),max:xM(new Date(M-1,11,31))};default:return null}}function tB(i){return i==="custom_range"||t3(i)!=null}function gat(i){return!!i&&i.type==="Identifier"}function $5t(i){if(gat(i))return i.name;if(i?.type==="Literal"){let e=i.value;if(typeof e=="string"&&e)return e}return null}function X5t(i){if(!i||i.type!=="BinaryExpression")return null;let e=i,t=$5t(e.left);if(!Om.includes(e.operator)||t==null)return null;let M=e.right,n=!1;if(M?.type==="UnaryExpression"){let o=M;if(o.operator!=="-")return null;n=!0,M=o.argument}if(M?.type!=="Literal")return null;let r=M.value;return typeof r!="string"&&typeof r!="number"||n&&typeof r!="number"?null:{field:t,op:e.operator,value:n?-r:r}}function iB(i){let e=i.trim();if(!e)return[];let t;try{t=G2(e)}catch{return null}let M=t.type==="Compound"?t.body:[t];if(M.length%2===0)return null;let n=[],r="and";for(let o=0;o<M.length;o++){if(o%2===1){if(!gat(M[o]))return null;let s=M[o].name;if(s!=="and"&&s!=="or")return null;r=s;continue}let a=X5t(M[o]);if(!a)return null;n.push(n.length===0||r==="and"?a:_(x({},a),{connector:r})),r="and"}return n}function Sm(i){let e=String(i??"").trim();if(!e)return!0;let t=e.replace(/"[^"]*"|'[^']*'/g,"");if(/\bor\b/i.test(t)||/\bnot\b/i.test(t.replace(/\bnot\s+in\b/gi," ")))return!1;let M=/\b(?:contains|startsWith|between|isEmpty|isNotEmpty|in)\s*\([^()]*\)/gi,n;do n=t,t=t.replace(M," ");while(t!==n);return!/[()]/.test(t)}function oat(i){return i.toLowerCase().replace(/[^a-z0-9]/g,"")}var q5t=new Set(["terms","multi_terms","date_histogram","histogram","range","date_range","significant_terms"]);function K5t(i){return i.endsWith(".keyword")?i.slice(0,-8):i}function eUt(i){let e=new Map,t=M=>{if(!(!M||typeof M!="object"))for(let[n,r]of Object.entries(M)){if(!r||typeof r!="object")continue;let o=r;for(let[a,s]of Object.entries(o))if(q5t.has(a)&&s&&typeof s=="object"&&typeof s.field=="string"){e.set(n,K5t(s.field));break}t(o.aggs)}};return t(i?.aggs),e}function MB(i,e){let t=(e?.columns??[]).filter(D=>typeof D.column=="string"&&!!D.column);if(!t.length||!i.pointName)return[];let M=e?.adapterType==="opensearch",n=M&&e?.dsl?eUt(e.dsl):null,r=i.seriesName?oat(i.seriesName):"",o=r?t.find(D=>oat(D.column)===r):void 0,a=t.filter(D=>D!==o),s=a.find(D=>!IA(D.dataType)&&!U5t(D.dataType))??a[0],l=[];if(s){let D=n?.get(s.column)??s.column,c=IA(s.dataType)&&Number.isFinite(Number(i.pointName));l.push({field:D,op:"==",value:c?Number(i.pointName):i.pointName})}let N=o??t.find(D=>D!==s&&IA(D.dataType));return!M&&N&&typeof i.pointY=="number"&&Number.isFinite(i.pointY)&&l.push({field:N.column,op:"==",value:i.pointY}),l}function Nat(i){return i.toLowerCase().replace(/[^a-z0-9]/g,"")}function tUt(i){return!!i&&/^(boolean|bool|bit)$/.test(i.toLowerCase())}function uat(i,e,t){i.set(e,[...i.get(e)??[],...t])}function Dat(i){let e=(i??[]).filter(M=>typeof M.column=="string"&&!!M.column);return e.length?(e.find(M=>!IA(M.dataType)&&!tUt(M.dataType))??e[0])?.column??null:null}function cat(i){if(i?.adapterType==="opensearch")return null;let e=(i?.columns??[]).filter(o=>typeof o.column=="string"&&!!o.column);if(!e.length)return null;let t=o=>o.sourceColumn??o.column;if(mm(e[0].dataType))return t(e[0]);let M=e.filter(o=>mm(o.dataType));if(M.length===1)return t(M[0]);let n=Dat(e),r=n?e.find(o=>o.column===n):void 0;return r&&mm(r.dataType)?t(r):null}function Iat(i){let e=new Map;for(let t of i??[]){let M=t?.queryMeta,n=Dat(M?.columns);if(!n)continue;let o=(t?.config?.chart?.data??[]).map(a=>a?.name).filter(a=>typeof a=="string"&&a!==""||typeof a=="number"&&!Number.isNaN(a));o.length&&uat(e,n,o)}return e}function i3(i,e){let t=(e?.columns??[]).filter(r=>typeof r.column=="string"&&!!r.column),M=new Map(t.map(r=>[Nat(r.column),r.column])),n=new Map;for(let r of i??[])if(!(!r||typeof r!="object"))for(let[o,a]of Object.entries(r)){let s=M.get(Nat(o));s&&(typeof a=="string"&&a!==""||typeof a=="number"&&!Number.isNaN(a))&&uat(n,s,[a])}return n}var fj=class i{byField=new Map;publish(e){for(let[t,M]of e){let n=this.byField.get(t);n||(n=new Set,this.byField.set(t,n));for(let r of M)n.add(r)}}getObserved(e){return[...this.byField.get(e)??[]]}fields(){return[...this.byField.keys()]}match(e,t){let M=this.getObserved(e),n=(t??"").trim().toLowerCase();return n?M.filter(r=>String(r).toLowerCase().includes(n)):M}has(e,t){let M=this.byField.get(e);return!!M&&[...M].some(n=>String(n)===String(t))}clear(){this.byField.clear()}static \u0275fac=function(t){return new(t||i)};static \u0275prov=Yt({token:i,factory:i.\u0275fac})};var iUt=["nileChart"],MUt=["*"],nUt=(i,e)=>e.label;function rUt(i,e){i&1&&Ot(0,"nile-glyph",10)}function oUt(i,e){if(i&1){let t=Ee();C(0,"nile-menu-item",8),Te("click",function(){let n=R(t).$index,r=p(3);return V(r.selectMasterDetailVariant(n))}),xe(1,rUt,1,0,"nile-glyph",10),v(2),k()}if(i&2){let t=e.$implicit,M=e.$index,n=p(3);m(),pe(M===n.masterDetailVariantIndex?1:-1),m(),hi(" ",t.label," ")}}function aUt(i,e){if(i&1){let t=Ee();C(0,"nile-dropdown",3)(1,"button",4),Ot(2,"nile-glyph",5),k(),C(3,"nile-menu",6),xt(4,oUt,3,2,"nile-menu-item",null,nUt),Ot(6,"div",7),C(7,"nile-menu-item",8),Te("click",function(){R(t);let n=p(2);return V(n.resetMasterDetailView())}),Ot(8,"nile-glyph",9),v(9," Reset view "),k()()()}if(i&2){let t=p(2);m(4),pt(t.masterDetailVariants)}}function sUt(i,e){if(i&1&&(C(0,"nile-chart",1,0)(2,"div",2),xe(3,aUt,10,0,"nile-dropdown",3),nd(4),k()()),i&2){let t=p();m(3),pe(t.isMasterDetailChart?3:-1)}}var CI=class i{constructor(e,t,M=null,n=null){this.zone=e;this.cd=t;this.gridPageFetcher=M;this.observed=n}zone;cd;gridPageFetcher;observed;config;widgetId=null;widgetTitle=null;loading=!1;drilldownBy;menu=null;dashboardFilters=null;resolvedFilters=null;dashboardId=null;conversationId=null;cellFilterEnabled=Et(!1);_filterMode="prompt";_filterSeed=null;aiSend=new ni;sortChange=new ni;filterSubmit=new ni;filterChange=new ni;chartClick=new ni;chartSelection=new ni;chartSelectionReset=new ni;gridFilterVerdict=new ni;menuAction=new ni;cellFilter=rM();dataViewFilterChange=new ni;chartRef;static MASTER_DETAIL_VARIANTS=[{label:"Default view",overrides:null},{label:"Collapsible overview",overrides:{detailType:"spline",masterType:"column",masterCollapsible:!0}},{label:"Styled navigator",overrides:{detailType:"areaspline",masterType:"area",maskFill:"rgba(37,99,235,0.12)",detailTitle:"Detail view",masterTitle:"Overview (drag to select)"}},{label:"Master only (zoomable)",overrides:{masterOnly:!0,masterType:"column"}}];static DEFAULT_VARIANT_INDEX=3;masterDetailVariantIndex=i.DEFAULT_VARIANT_INDEX;mounted=!0;viewReady=!1;sessionId=globalThis.crypto?.randomUUID?.()??`${Date.now()}-${Math.random()}`;aiSendHandler=e=>this.handleAiSend(e);sortChangeHandler=e=>this.handleSortChange(e);nileChangeHandler=e=>this.handleNileChange(e);filterKeydownHandler=e=>this.handleFilterKeydown(e);filterFocusHandler=()=>this.handleFilterFocus();filterClearHandler=()=>this.handleFilterClear();chartClickHandler=e=>this.handleChartClick(e);chartSelectionHandler=e=>this.handleChartSelection(e);resetZoomClickHandler=e=>this.handleResetZoomClick(e);lastForwardedSelection=null;static SELECTION_DEDUP_MS=1e3;static GRID_FULL_FETCH_ROWS=500;masterDetailZoomWindow=null;menuChangeHandler=e=>this.handleMenuChange(e);paginationChangeHandler=e=>this.handleGridPaginationChange(e);filterChangeHandler=e=>this.handleGridFilterChange(e);cellFilterHandler=(e,t)=>this.zone.run(()=>this.cellFilter.emit({widgetId:this.widgetId,field:e,value:t}));filterDebounce=null;noopFilterFn=()=>!0;gridState=Ye(null);_pendingDashboardFilterRefresh=!1;_dashboardFilterRefetching=!1;_dashboardFilterSeq=0;injector=Be(Ml);lastClickCoords={x:0,y:0};mouseDownHandler=e=>{this.lastClickCoords={x:e.clientX,y:e.clientY}};latestFilterPayload=null;suppressPaginationEvents=!1;staticGridPageIndex=0;staticGridPageSize=10;staticGridRowCount=0;ngAfterViewInit(){this.viewReady=!0,this.attachAiListener(),this.applyLoading(),this.applyMenu(),this.config&&this.applyConfig()}ngOnChanges(e){if(!this.viewReady)return;e.loading&&this.applyLoading(),e.menu&&this.applyMenu();let t=e.dashboardFilters&&!e.dashboardFilters.firstChange,M=e.resolvedFilters&&!e.resolvedFilters.firstChange;if((t||M)&&this.handleDashboardFilterChange(),!e.config&&!e.drilldownBy)return;let n=e.config?.previousValue,r=e.config?.currentValue;e.config&&this.needsRemount(n,r)?this.remount():this.applyConfig()}ngOnDestroy(){this.detachAiListener()}pushAiResponse(e){this.chartRef?.nativeElement?.addAiResponse?.(e)}get isMasterDetailChart(){return this.config?.chart?.type==="master-detail"}get masterDetailVariants(){return i.MASTER_DETAIL_VARIANTS}selectMasterDetailVariant(e){if(!this.isMasterDetailChart)return;let t=i.MASTER_DETAIL_VARIANTS.length;e<0||e>=t||e===this.masterDetailVariantIndex||(this.masterDetailVariantIndex=e,this.remount())}resetMasterDetailView(){this.isMasterDetailChart&&(this.masterDetailVariantIndex=i.DEFAULT_VARIANT_INDEX,this.masterDetailZoomWindow=null,this.remount())}patchControlSuggestions(e,t){let M=this.chartRef?.nativeElement;if(!M)return;let n=M.shadowRoot?.querySelector("nile-filter-chart"),r=n?.selectedValues?.get(e),o=M.config?.chart?.controls;if(!o)return;let a=o.find(s=>s.id===e);a&&(a.suggestions=[...t],typeof r=="string"&&(a.value=r),n?.requestUpdate?.())}getLiveExpression(){let e=this.getPromptControlId(this.config);return e?{controlId:e,value:this.readLiveFilterValue(e)}:null}setFilterExpression(e){let t=this.chartRef?.nativeElement,M=this.getPromptControlId(this.config);if(!t||!M)return;let r=t.config?.chart?.controls?.find(a=>a.id===M);r&&(r.value=e);let o=t.shadowRoot?.querySelector("nile-filter-chart");o?.setValue?.(M,e),o?.requestUpdate?.()}getPromptControlId(e){let t=e?.chart?.controls;for(let M of t??[])if((M.variant==="prompt"||M.variant==="expression"||M.variant==="hybrid")&&M.id)return M.id;return null}setFilterMode(e,t){this._filterMode=e,this._filterSeed=t??null,this.applyConfig()}openAiChat(){let e=this.chartRef?.nativeElement;e&&id(()=>{e.chatOpen=!0},{injector:this.injector})}handleChartClick(e){let t=e.detail??{},M=String(t.name??t.point?.name??t.category??t.point?.category??""),n=typeof t.value=="number"?t.value:typeof t.point?.y=="number"?t.point.y:null,r=t.seriesName??t.point?.series?.name??null;this.zone.run(()=>this.chartClick.emit({widgetId:this.widgetId,point:t.point??null,pointName:M,pointY:n,seriesName:r,x:this.lastClickCoords.x,y:this.lastClickCoords.y}))}handleChartSelection(e){let{min:t,max:M}=e.detail??{};if(typeof t!="number"||typeof M!="number")return;if(M<=t){let s=this.chartPointStep();if(!s)return;t-=s/2,M+=s/2}let n=this.chartXExtent();if(n&&t<=n.min&&M>=n.max){this.masterDetailZoomWindow=null;return}this.masterDetailZoomWindow={min:t,max:M};let r=`${t}:${M}`,o=Date.now(),a=this.lastForwardedSelection;a?.key===r&&o-a.at<i.SELECTION_DEDUP_MS||(this.lastForwardedSelection={key:r,at:o},this.zone.run(()=>this.chartSelection.emit({widgetId:this.widgetId,min:t,max:M})))}handleResetZoomClick(e){e.composedPath().some(M=>M instanceof Element&&(M.classList.contains("nile-chart-reset-zoom")||M.getAttribute("part")==="reset-zoom"))&&(this.masterDetailZoomWindow=null,this.lastForwardedSelection=null,this.zone.run(()=>this.chartSelectionReset.emit({widgetId:this.widgetId})))}chartPointStep(){let e=this.chartRef?.nativeElement,t=e?this.findHighchartsInstance(e):null,M=[],n=t?.series??[];for(let a of n)for(let s of a.points??[])typeof s.x=="number"&&M.push(s.x);if(M.length<2){let a=this.config?.chart?.data;for(let s of Array.isArray(a)?a:[])s&&typeof s=="object"&&typeof s.x=="number"&&M.push(s.x)}if(M.length<2)return 0;let r=[...new Set(M)].sort((a,s)=>a-s),o=1/0;for(let a=1;a<r.length;a++)o=Math.min(o,r[a]-r[a-1]);return Number.isFinite(o)&&o>0?o:0}chartXExtent(){let e=this.chartRef?.nativeElement,M=(e?this.findHighchartsInstance(e):null)?.xAxis?.[0];if(M&&typeof M.dataMin=="number"&&typeof M.dataMax=="number")return{min:M.dataMin,max:M.dataMax};let n=[],r=this.config?.chart?.data;for(let o of Array.isArray(r)?r:[]){o&&typeof o=="object"&&typeof o.x=="number"&&n.push(o.x);let a=o?.data;if(Array.isArray(a))for(let s of a)Array.isArray(s)&&typeof s[0]=="number"?n.push(s[0]):s&&typeof s=="object"&&typeof s.x=="number"&&n.push(s.x)}return n.length?{min:Math.min(...n),max:Math.max(...n)}:null}drillIntoSeries(e,t){let M=this.chartRef?.nativeElement?this.findHighchartsInstance(this.chartRef.nativeElement):null;M&&(M.addSingleSeriesAsDrilldown(e,{id:t.id,name:t.name,type:t.type==="donut"?"pie":t.type??"pie",data:t.data}),M.applyDrilldown())}findHighchartsInstance(e){let t=e.shadowRoot;if(!t)return null;for(let M of Array.from(t.querySelectorAll("*"))){let n=M.chart;if(n&&typeof n.addSingleSeriesAsDrilldown=="function"&&typeof n.applyDrilldown=="function")return n}return null}needsRemount(e,t){return this.sparklineVisibilityChanged(e,t)||this.kpiVariantChangedWithSparkline(e,t)||this.semiCircleChanged(e,t)||this.widgetFamilyChanged(e,t)||this.seriesColorChanged(e,t)||this.plotShapeChanged(e,t)}plotShapeChanged(e,t){let M=e?.chart,n=t?.chart;if(!M||!n)return!1;let r=N=>Array.isArray(N)?N.length:-1;if(r(M.categories)!==r(n.categories))return!0;let o=Array.isArray(M.data)?M.data:null,a=Array.isArray(n.data)?n.data:null;if(o&&a&&o.length===a.length)for(let N=0;N<o.length;N++){let D=o[N],c=a[N];if(r(D?.data)!==r(c?.data))return!0}let s=M.options?.series,l=n.options?.series;if(r(s)!==r(l))return!0;if(Array.isArray(s)&&Array.isArray(l))for(let N=0;N<s.length;N++){let D=s[N],c=l[N];if(r(D?.data)!==r(c?.data))return!0}for(let N of["lineSeries","columnSeries"]){let D=M[N],c=n[N];if(r(D?.data)!==r(c?.data))return!0}return!1}seriesColorChanged(e,t){let M=e?.chart?.data,n=t?.chart?.data;return!Array.isArray(M)||!Array.isArray(n)?!1:M.length!==n.length?!0:M.some((r,o)=>{let a=r,s=n[o];return(a?.color??null)!==(s?.color??null)})}widgetFamilyChanged(e,t){return this.chartFamily(e)!==this.chartFamily(t)}chartFamily(e){let t=e?.chart?.type;return t==="kpi"?"kpi":t==="grid"?"grid":t==="filter"?"filter":"chart"}sparklineVisibilityChanged(e,t){return this.hasSparkline(e)!==this.hasSparkline(t)}kpiVariantChangedWithSparkline(e,t){let M=e?.chart?.variant,n=t?.chart?.variant;return M!==n&&this.hasSparkline(t)}semiCircleChanged(e,t){let M=e?.chart?.type;if(t?.chart?.type!=="donut"&&M!=="donut")return!1;let r=!!e?.chart?.semiCircle,o=!!t?.chart?.semiCircle;return r!==o}hasSparkline(e){let t=e?.chart?.sparkline;return Array.isArray(t)&&t.length>0}remount(){this.detachAiListener(),this.mounted=!1,this.cd.detectChanges(),this.mounted=!0,this.cd.detectChanges(),this.attachAiListener(),this.applyConfig()}applyConfig(){let e=this.chartRef?.nativeElement;if(!this.config||!e)return;let t=this.isGridConfig(this.config);if(t&&this.isServerGrid(this.config)){this.applyServerGrid(e);return}e.config=this.buildChartConfig(t),this.afterChildRendered(e,t,()=>{this.applyCardStyle(e),t&&(this.fixGridDisplay(e),this.reassertStaticGridPage(e))})}reassertStaticGridPage(e){if(this.staticGridPageIndex===0||this.isServerGrid(this.config))return;let t=e.shadowRoot?.querySelector("nile-data-grid");if(!t)return;this.suppressPaginationEvents=!0;let M=this.staticGridPageIndex,n=this.staticGridPageSize;(t.updateComplete??Promise.resolve()).then(()=>{t.pagination={pageIndex:M,pageSize:n},(t.updateComplete??Promise.resolve()).then(()=>{this.suppressPaginationEvents=!1})})}isGridConfig(e){return e?.chart?.type==="grid"}buildChartConfig(e){let t=Yh(this.config,this.drilldownBy),Z=t.chart??{},{height:M}=Z,n=$e(Z,["height"]),r=n.type==="bar";r&&(n.type="column");let o=n.type==="stacked",a=n.type==="cluster";(o||a)&&(n.type="column");let s=e&&n.stickyHeader===void 0?{stickyHeader:!0}:{},l=e?{height:"100%"}:{},N=e?this.normalizeGridColumns(n.columns):void 0,D=e?B2(N)??N:N,c=e?Lm(D)??D:D,I=e?F2(c)??c:c,d=e&&this.cellFilterEnabled()?V2(I,this.cellFilterHandler)??I:I,y={};if(e){let ne=Array.isArray(n.data)?n.data:[];ne.length!==this.staticGridRowCount&&(this.staticGridRowCount=ne.length,this.staticGridPageIndex=0),y={paginationEnabled:!0,pagination:{pageIndex:this.staticGridPageIndex,pageSize:this.staticGridPageSize}}}let A=n.type==="kpi",$=t.aq??{},{ai:z,switchable:E}=$,S=$e($,["ai","switchable"]),L=A?S:x(x({},S),z!==void 0?{ai:z}:{});if(!L.chartTitle&&!n.chartTitle&&this.widgetTitle&&(L.chartTitle=this.widgetTitle),n.type==="filter"){n.chartTitle=hm,delete n.chartSubtitle,delete n.summary,L.chartTitle=hm,delete L.chartSubtitle,delete L.summary;let ne=n.controls;if(Array.isArray(ne)){let ae=this.chartRef?.nativeElement?.config?.chart?.controls,he=this.getPromptControlId(this.config),ie=this._filterSeed;this._filterSeed=null,n.controls=ne.map(ce=>{let Ie=ce.id,Oe=Ie?this.readLiveFilterValue(Ie):"",Qe=Ie?ae?.find(le=>le.id===Ie):void 0,ve=Array.isArray(Qe?.suggestions)&&Qe.suggestions.length?{suggestions:Qe.suggestions}:{},F=x(x(_(x({},ce),{showClearIcon:!0}),ve),Oe?{value:Oe}:{});if(Ie&&Ie===he){let le=ie!=null?{value:ie}:{};return this._filterMode==="expression"?x(_(x({},F),{variant:"expression",queryLanguage:_(x({engine:"filtrex",mode:"strict",validateOn:"change"},ce.queryLanguage??{}),{enabled:!0}),placeholders:[PV],expressionPlaceholders:[PV]}),le):x(_(x({},F),{placeholders:[RV],promptPlaceholders:[RV]}),le)}return F})}}let U=n.type??"",Y=n.categories,B=Array.isArray(Y)&&Y.length>0&&U!=="invertedarea"&&!r,X=n.options??{},W=Object.keys(X).length?{options:X}:{};if(B){let ne=X.xAxis??{},ae=ne.labels??{},he=Y.length,ie=he>8?Math.ceil(he/8):void 0,ce=Y.reduce((ve,F)=>Math.max(ve,String(F??"").length),0),Oe=(ie?Math.ceil(he/ie):he)*(ce*7+12),Qe={chart:{spacingLeft:48},xAxis:{labels:{rotation:-45,align:"right",y:12}}};W={options:_(x({},X),{xAxis:_(x({},ne),{labels:x(x({autoRotation:[-45,-90],style:{textOverflow:"none",whiteSpace:"nowrap"}},ie?{step:ie}:{}),ae)}),responsive:{rules:[{condition:{maxWidth:Oe},chartOptions:Qe},...X.responsive?.rules??[]]}})}}if(o){let ne=W.options??X,ae=ne.plotOptions??{},he=ae.series??{};W={options:_(x({},ne),{plotOptions:_(x({},ae),{series:_(x({},he),{stacking:n.stackMode||"normal"})})})}}if(r){let ne=W.options??X,ae=ne.chart??{};W={options:_(x({},ne),{chart:_(x({},ae),{inverted:!0})})}}let Ne=U==="master-detail"?x(x({},this.masterDetailVariantIndex>0?i.MASTER_DETAIL_VARIANTS[this.masterDetailVariantIndex].overrides??{}:{}),this.masterDetailZoomWindow?{selectionMin:this.masterDetailZoomWindow.min,selectionMax:this.masterDetailZoomWindow.max}:{}):{};return _(x({},t),{chart:x(x(x(x(x(x(x(x({},s),n),e?{variant:"sleek-condensed",columnResizingEnabled:!0,columnResizeMode:"onChange",columnReorderingEnabled:!0}:{}),d?{columns:d}:{}),W),Ne),l),y),aq:L})}isServerGrid(e){let t=e?.chart;return t?.serverPagination===!0&&typeof t?.gridId=="string"}applyServerGrid(e){let t=this.config.chart??{},M=t.gridId,n=Number(t.pagination?.pageSize)||10,r=this.gridState();if(r?.gridId===M&&r.loaded){this._dashboardFilterRefetching||this.renderServerGrid(e);return}this.gridState.set({gridId:M,total:0,pageIndex:0,pageSize:n,columns:[],aq:{},chartConfig:{},rows:[],loadedPages:[],loaded:!1,fullyLoaded:!1,filters:[]}),e.loading=!0,this.fetchGridPage(M,0,i.GRID_FULL_FETCH_ROWS).then(o=>{if(!o||this.gridState()?.gridId!==M){this._pendingDashboardFilterRefresh=!1;return}this.emitGridFilterVerdict(o);let a=o.config?.chart??{},s=Array.isArray(a.data)?a.data:[],l=Math.min(Number(o.total)||s.length,i.GRID_FULL_FETCH_ROWS);if(this.observed?.publish(i3(s,o.queryMeta)),this.gridState.set({gridId:M,total:l,pageIndex:0,pageSize:n,columns:Array.isArray(a.columns)?a.columns:[],aq:o.config?.aq??{},chartConfig:a,rows:s,loadedPages:[0],loaded:!0,fullyLoaded:!0,filters:Array.isArray(a.filters)?a.filters:[]}),e.loading=!1,this.renderServerGrid(e),this._pendingDashboardFilterRefresh){this._pendingDashboardFilterRefresh=!1;let N=this.gridState();N&&N.gridId===M&&this.applyServerFilters(M,N.filters)}}).catch(o=>{console.error("[nile-chart-widget] initial grid page fetch failed",o),e.loading=!1,this._pendingDashboardFilterRefresh=!1})}emitGridFilterVerdict(e){let t=e?.dashboardFilter;t&&this.gridFilterVerdict.emit({widgetId:this.widgetId,applied:t.applied===!0,reason:t.reason})}renderServerGrid(e){let t=this.gridState();if(!t)return;let M=x({},t.aq);!M.chartTitle&&!t.chartConfig.chartTitle&&this.widgetTitle&&(M.chartTitle=this.widgetTitle);let n=(this.normalizeGridColumns(t.columns)??t.columns).map(s=>_(x({},s),{filterFn:this.noopFilterFn})),r=B2(n)??n,o=Lm(r)??r,a=F2(o)??o;e.config={chart:_(x({stickyHeader:!0},t.chartConfig),{variant:"sleek-condensed",columnResizingEnabled:!0,columnResizeMode:"onChange",columnReorderingEnabled:!0,type:"grid",columns:this.cellFilterEnabled()?V2(a,this.cellFilterHandler)??a:a,data:[...t.rows],paginationEnabled:!0,pagination:{pageIndex:t.pageIndex,pageSize:t.pageSize},height:"100%"}),aq:M},this.afterChildRendered(e,!0,()=>{this.applyCardStyle(e),this.fixGridDisplay(e)})}normalizeGridColumns(e){if(Array.isArray(e))return e.map(t=>{let M=t,n=M.header??M.headerName;if(Array.isArray(M.columns)){let D=M,{field:I,headerName:d,columns:y}=D,A=$e(D,["field","headerName","columns"]);return _(x(x({},A),n!==void 0?{header:n}:{}),{columns:this.normalizeGridColumns(M.columns)})}let r=M.accessorKey??M.field,o=M.enableFiltering??!0,a=typeof M.cell=="function"?M.cell:null,c=M,{field:s,headerName:l}=c,N=$e(c,["field","headerName"]);return _(x(x(x({},N),r!==void 0?{accessorKey:r}:{}),n!==void 0?{header:n}:{}),{enableFiltering:o,cell:I=>{let d=a?a(I):I.value;return d==null||d===""?"-":d}})})}afterChildRendered(e,t,M){let n=()=>{if(!t){M();return}let r=0,o=()=>{e.shadowRoot?.querySelector("nile-data-grid")||++r>30?M():requestAnimationFrame(o)};o()};e.updateComplete?e.updateComplete.then(n):customElements.whenDefined("nile-chart").then(()=>{let r=e.updateComplete;r?r.then(n):requestAnimationFrame(n)})}applyCardStyle(e){let t=e.shadowRoot?.querySelector(".nile-chart-card");if(!t)return;let M=this.config?.chart??{},n=(r,o)=>{o?t.style.setProperty(r,o):t.style.removeProperty(r)};n("background",M.chartBg),n("border",M.chartBorder),n("border-radius",M.chartBorderRadius),n("box-shadow",M.chartShadow),n("padding",M.chartPadding),n("min-height",M.chartMinHeight)}fixGridDisplay(e){let t=e.shadowRoot?.querySelector("nile-data-grid");if(!t)return;t.style.display="flex",t.style.flexDirection="column";let M=this.config?.chart?.chartBg;M?t.style.setProperty("--nile-data-grid-surface",M):t.style.removeProperty("--nile-data-grid-surface"),BV(t),HV(t),this.injectCellFilterStyle(t)}gridStyleSheet=null;injectCellFilterStyle(e){if(!this.cellFilterEnabled())return;let t=e.shadowRoot;t&&(this.gridStyleSheet||(this.gridStyleSheet=new CSSStyleSheet,this.gridStyleSheet.replaceSync(eat)),!t.adoptedStyleSheets.includes(this.gridStyleSheet)&&(t.adoptedStyleSheets=[...t.adoptedStyleSheets,this.gridStyleSheet]))}applyLoading(){let e=this.chartRef?.nativeElement;e&&(e.loading=this.loading)}applyMenu(){let e=this.chartRef?.nativeElement;e&&(e.menu=this.menu)}attachAiListener(){let e=this.chartRef?.nativeElement;e?.addEventListener("nile-chart-ai-send",this.aiSendHandler),e?.addEventListener("nile-sort-change",this.sortChangeHandler),e?.addEventListener("nile-chart-click",this.chartClickHandler),e?.addEventListener("nile-chart-selection",this.chartSelectionHandler),e?.addEventListener("click",this.resetZoomClickHandler,!0),e?.addEventListener("nile-menu-change",this.menuChangeHandler),e?.addEventListener("nile-pagination-change",this.paginationChangeHandler),e?.addEventListener("nile-filter-change",this.filterChangeHandler),e?.addEventListener("mousedown",this.mouseDownHandler,!0),this.isFilterConfig(this.config)&&(e?.addEventListener("nile-change",this.nileChangeHandler),e?.addEventListener("keydown",this.filterKeydownHandler,!0),e?.addEventListener("focusin",this.filterFocusHandler),e?.addEventListener("click",this.filterFocusHandler,!0),e?.addEventListener("nile-clear",this.filterClearHandler))}detachAiListener(){let e=this.chartRef?.nativeElement;e?.removeEventListener("nile-chart-ai-send",this.aiSendHandler),e?.removeEventListener("nile-sort-change",this.sortChangeHandler),e?.removeEventListener("nile-chart-click",this.chartClickHandler),e?.removeEventListener("nile-chart-selection",this.chartSelectionHandler),e?.removeEventListener("click",this.resetZoomClickHandler,!0),e?.removeEventListener("nile-menu-change",this.menuChangeHandler),e?.removeEventListener("nile-pagination-change",this.paginationChangeHandler),e?.removeEventListener("nile-filter-change",this.filterChangeHandler),e?.removeEventListener("mousedown",this.mouseDownHandler,!0),e?.removeEventListener("nile-change",this.nileChangeHandler),e?.removeEventListener("keydown",this.filterKeydownHandler,!0),e?.removeEventListener("focusin",this.filterFocusHandler),e?.removeEventListener("click",this.filterFocusHandler,!0),e?.removeEventListener("nile-clear",this.filterClearHandler)}handleMenuChange(e){let t=e.detail?.id;t&&this.zone.run(()=>this.menuAction.emit(t))}handleGridPaginationChange(e){let t=e.detail;if(this.suppressPaginationEvents)return;let M=this.gridState();if(!M?.loaded){if(this.isGridConfig(this.config)&&!this.isServerGrid(this.config)){let N=t?.pagination;this.staticGridPageIndex=Number(N?.pageIndex)||0,this.staticGridPageSize=Number(N?.pageSize)||this.staticGridPageSize}return}let n=t?.pagination,r=Number(n?.pageIndex)||0,o=Number(n?.pageSize)||M.pageSize;if(M.fullyLoaded){(r!==M.pageIndex||o!==M.pageSize)&&this.gridState.set(_(x({},M),{pageIndex:r,pageSize:o}));return}let a=r*o,s=o!==M.pageSize;if(!(s||!M.loadedPages.includes(r))){r!==M.pageIndex&&this.gridState.set(_(x({},M),{pageIndex:r}));return}this.suppressPaginationEvents=!0,this.fetchGridPage(M.gridId,r,o).then(N=>{let D=this.gridState();if(D?.gridId!==M.gridId){this.suppressPaginationEvents=!1;return}let c=N?.config?.chart??{},I=Array.isArray(c.data)?c.data:[],d=s?Array.from({length:D.total},()=>({})):D.rows.slice();I.forEach((z,E)=>{d[a+E]=z});let y=s?[r]:[...D.loadedPages,r];this.gridState.set(_(x({},D),{rows:d,loadedPages:y,pageIndex:r,pageSize:o})),this.observed?.publish(i3(I,N?.queryMeta)),this.pushGridData();let A=this.chartRef?.nativeElement?.shadowRoot?.querySelector("nile-data-grid");(A?.updateComplete??Promise.resolve()).then(()=>{A&&(A.pagination={pageIndex:r,pageSize:o}),(A?.updateComplete??Promise.resolve()).then(()=>{this.suppressPaginationEvents=!1})})}).catch(N=>{this.suppressPaginationEvents=!1,console.error("[nile-chart-widget] page fetch failed",N)})}handleGridFilterChange(e){let t=this.gridState(),M=e.detail?.filters??[];if(this.isServerGrid(this.config)&&t?.loaded&&this.config.chart.gridId===t.gridId){this.filterDebounce&&clearTimeout(this.filterDebounce),this.filterDebounce=setTimeout(()=>this.applyServerFilters(t.gridId,M),300);return}this.dataViewFilterChange.emit(M)}applyServerFilters(e,t){let M=this.gridState();if(!M||M.gridId!==e)return;let n=++this._dashboardFilterSeq,r=this._dashboardFilterRefetching;this.fetchGridPage(e,0,i.GRID_FULL_FETCH_ROWS,t).then(o=>{if(n!==this._dashboardFilterSeq)return;let a=this.gridState();if(!o||a?.gridId!==e)return;this.emitGridFilterVerdict(o);let s=o.config?.chart??{},l=Array.isArray(s.data)?s.data:[],N=Math.min(Number(o.total)||l.length,i.GRID_FULL_FETCH_ROWS);this.observed?.publish(i3(l,o.queryMeta)),this.gridState.set(_(x({},a),{filters:t,total:N,rows:l,pageIndex:0,loadedPages:[0],loaded:!0,fullyLoaded:!0}));let D=this.chartRef?.nativeElement;r&&D?(D.loading=!1,this.renderServerGrid(D)):this.pushGridData(l)}).catch(o=>{console.error("[nile-chart-widget] filter fetch failed",o)}).finally(()=>{if(n===this._dashboardFilterSeq&&(this._dashboardFilterRefetching=!1,r)){let o=this.chartRef?.nativeElement;o&&(o.loading=!1)}})}fetchGridPage(e,t,M,n){if(!this.gridPageFetcher)return Promise.resolve(null);let r=this.dashboardFilters&&Object.keys(this.dashboardFilters).length?this.dashboardFilters:void 0,o=this.resolvedFilters&&this.resolvedFilters.length?this.resolvedFilters:void 0;return Promise.resolve(this.gridPageFetcher(e,t,M,n,r,this.dashboardId,o,this.conversationId))}handleDashboardFilterChange(){let e=this.gridState();if(!e||!this.isServerGrid(this.config)||this.config.chart?.gridId!==e.gridId)return;if(!e.loaded){this._pendingDashboardFilterRefresh=!0;return}this._dashboardFilterRefetching=!0;let t=this.chartRef?.nativeElement;t&&(t.loading=!0),this.applyServerFilters(e.gridId,e.filters)}pushGridData(e){let t=this.chartRef?.nativeElement?.shadowRoot?.querySelector("nile-data-grid");if(!t)return;if(e)t.data=e;else{let n=this.gridState();n&&(t.data=[...n.rows])}let M=()=>{BV(t),HV(t),this.injectCellFilterStyle(t)};t.updateComplete?t.updateComplete.then(M):M()}isFilterConfig(e){return e?.chart?.type==="filter"}getExpressionControl(e){let t=e?.chart?.controls;if(!t)return null;for(let M of t)if((M.variant==="expression"||M.variant==="hybrid")&&M.id)return{id:M.id,variant:M.variant};return null}handleAiSend(e){let t=e.detail,M=t?.message??t?.text??"",n=this.widgetId;if(!M||!n)return;let r=e.composedPath()[0];this.zone.run(()=>{this.aiSend.emit({widgetId:n,message:M,sessionId:this.sessionId,chartEl:r})})}handleSortChange(e){let t=e.detail?.sorting??[];this.zone.run(()=>{this.sortChange.emit({widgetId:this.widgetId,sorting:t})})}handleNileChange(e){let t=e.detail??{},M=t.filters??{},n=t.errors??{};this.latestFilterPayload={filters:M,errors:n};let r=this.getExpressionControl(this.config);if(!r)return;let o=M[r.id];if(r.variant==="hybrid"){let s=typeof o=="object"&&o!==null,l=n[r.id]!==void 0;if(!s&&!l)return}let a=typeof o=="string"?o:o?.source??"";this.zone.run(()=>{this.filterChange.emit({widgetId:this.widgetId,controlId:r.id,query:a})})}readLiveFilterValue(e){let t=this.chartRef?.nativeElement?.shadowRoot?.querySelector("nile-filter-chart"),M=t?.shadowRoot?.querySelector(`#fc-prompt-${CSS.escape(e)}`);if(M&&typeof M.value=="string")return M.value;let n=t?.selectedValues?.get(e);return typeof n=="string"?n:n&&typeof n=="object"?String(n.source??""):""}lastFilterFocusTs=0;handleFilterFocus(){let e=Date.now();if(e-this.lastFilterFocusTs<120)return;this.lastFilterFocusTs=e;let t=this.getExpressionControl(this.config);if(!t)return;let M=this.readLiveFilterValue(t.id);this.zone.run(()=>{this.filterChange.emit({widgetId:this.widgetId,controlId:t.id,query:M})})}handleFilterKeydown(e){let t=e;if(t.key!=="Enter"||t.shiftKey||t.isComposing)return;let M=this.getPromptControlId(this.config);if(!M)return;let n=this.readLiveFilterValue(M),r=this._filterMode;this.zone.run(()=>{this.filterSubmit.emit(x({widgetId:this.widgetId,filters:{[M]:n},errors:{},mode:r},r==="prompt"?{prompt:n}:{}))})}handleFilterClear(){this.zone.run(()=>{this.filterSubmit.emit({widgetId:this.widgetId,filters:{},errors:{}})})}static \u0275fac=function(t){return new(t||i)(ui(nl),ui(ll),ui(L2,8),ui(fj,8))};static \u0275cmp=oM({type:i,selectors:[["shared-nile-chart-widget"]],viewQuery:function(t,M){if(t&1&&rd(iUt,5),t&2){let n;Ic(n=dc())&&(M.chartRef=n.first)}},inputs:{config:"config",widgetId:"widgetId",widgetTitle:"widgetTitle",loading:"loading",drilldownBy:"drilldownBy",menu:"menu",dashboardFilters:"dashboardFilters",resolvedFilters:"resolvedFilters",dashboardId:"dashboardId",conversationId:"conversationId",cellFilterEnabled:[1,"cellFilterEnabled"]},outputs:{aiSend:"aiSend",sortChange:"sortChange",filterSubmit:"filterSubmit",filterChange:"filterChange",chartClick:"chartClick",chartSelection:"chartSelection",chartSelectionReset:"chartSelectionReset",gridFilterVerdict:"gridFilterVerdict",menuAction:"menuAction",cellFilter:"cellFilter",dataViewFilterChange:"dataViewFilterChange"},features:[Ro],ngContentSelectors:MUt,decls:1,vars:1,consts:[["nileChart",""],["fit",""],["slot","header-actions",1,"projected-actions"],["hoist","","placement","bottom-end"],["slot","trigger","type","button","aria-label","Switch chart view",1,"md-variant-toggle"],["name","ng-switch-horizontal-01","method","stroke","size","16"],[1,"md-variant-menu"],[1,"md-variant-divider"],[3,"click"],["slot","prefix","name","ng-refresh-ccw","method","stroke","size","14"],["slot","prefix","name","ng-check","method","stroke","size","14"]],template:function(t,M){t&1&&(ay(),xe(0,sUt,5,1,"nile-chart",1)),t&2&&pe(M.mounted?0:-1)},dependencies:[Pa],styles:["[_nghost-%COMP%]{display:block;width:100%;height:100%;overflow:hidden}nile-chart[_ngcontent-%COMP%]{display:block;width:100%;height:100%}nile-chart[_ngcontent-%COMP%]::part(ai-trigger){display:none}nile-chart[_ngcontent-%COMP%]::part(chart-card){border:unset;border-radius:unset;box-shadow:none}.projected-actions[_ngcontent-%COMP%]{display:flex;gap:12px;align-items:center}.md-variant-toggle[_ngcontent-%COMP%]{display:inline-flex;align-items:center;justify-content:center;padding:var(--ng-spacing-1);border:none;border-radius:var(--ng-radius-md);background:transparent;color:var(--ng-colors-fg-quaternary-400);cursor:pointer}.md-variant-toggle[_ngcontent-%COMP%]:hover{background:var(--ng-colors-bg-secondary);color:var(--ng-colors-text-primary-900)}.md-variant-divider[_ngcontent-%COMP%]{height:1px;margin:4px 8px;background:var(--ng-colors-border-secondary, #e9eaeb)}"]})};function wm(i){switch(i?.reason){case"no_applicable_field":return"Filter not applicable to this widget";case"execution_error":case"execution_error_fallback":return"Couldn't apply filter here";case"not_filterable_in_memory":return"Filtered on loaded data only";case"or_unsupported_for_widget":return"This widget can't combine those filters with OR";case"kpi_value_ambiguous":return"Couldn't identify this KPI's value under the filter";default:return"Filter not applied"}}var lUt=["bar"],nB=(i,e)=>e.id??e.label,jat=(i,e)=>e.id;function gUt(i,e){if(i&1){let t=Ee();C(0,"nile-menu-item",10),Te("click",function(){let n=R(t).$implicit,r=p();return V(r.addRow(n.id??n.name??n.label))}),v(1),k()}if(i&2){let t=e.$implicit;m(),hi(" ",t.label," ")}}function NUt(i,e){i&1&&Ot(0,"nile-skeleton-loader",8)}function uUt(i,e){if(i&1){let t=Ee();C(0,"button",28),Te("click",function(){R(t);let n=p().$implicit,r=p();return V(r.toggleConnector(n))}),v(1),k()}if(i&2){let t=p().$implicit,M=p();ji("mf-conn--disabled",M.disabled()),be("title",t.connector==="or"?"Matches EITHER side \u2014 click for AND":"Matches BOTH sides \u2014 click for OR"),mt("aria-label","Change join to previous filter (currently "+(t.connector==="or"?"OR":"AND")+")"),m(),it(t.connector==="or"?"OR":"AND")}}function DUt(i,e){if(i&1){let t=Ee();C(0,"nile-menu-item",10),Te("click",function(){let n=R(t).$implicit,r=p().$implicit,o=p();return V(o.changeOp(r,n))}),v(1),k()}if(i&2){let t=e.$implicit,M=p(2);m(),it(M.operatorLabels[t])}}function cUt(i,e){if(i&1){let t=Ee();C(0,"nile-select",29),Te("nile-change",function(n){R(t);let r=p().$implicit,o=p();return V(o.setScalar(r,n.target.value))}),C(1,"nile-option",30),v(2,"true"),k(),C(3,"nile-option",31),v(4,"false"),k()()}if(i&2){let t=p().$implicit;be("value",t.value)}}function IUt(i,e){if(i&1){let t=Ee();C(0,"nile-date-picker",34),Te("nile-change",function(n){R(t);let r=p(2).$implicit,o=p();return V(o.setRangeDate(r,n.detail))}),Ot(1,"nile-input",35),k()}if(i&2){let t=p(2).$implicit,M=p();be("dateFormat",M.dateFormatFor(t)),m(),be("value",M.rangeTriggerText(t))}}function dUt(i,e){if(i&1){let t=Ee();C(0,"nile-date-picker",36),Te("nile-change",function(n){R(t);let r=p(2).$implicit,o=p();return V(o.setSingleDate(r,n.detail))}),Ot(1,"nile-input",37),k()}if(i&2){let t=p(2).$implicit,M=p();be("dateFormat",M.dateFormatFor(t)),m(),be("value",M.singleTriggerText(t))}}function jUt(i,e){if(i&1&&xe(0,IUt,2,2,"nile-date-picker",32)(1,dUt,2,2,"nile-date-picker",33),i&2){let t=p().$implicit,M=p();pe(M.isBetween(t)?0:1)}}function yUt(i,e){if(i&1){let t=Ee();C(0,"div",19)(1,"nile-input",38),Te("nile-change",function(n){R(t);let r=p().$implicit,o=p();return V(o.setRangeMin(r,n.detail.value))}),k(),C(2,"span",39),v(3,"\u2013"),k(),C(4,"nile-input",40),Te("nile-change",function(n){R(t);let r=p().$implicit,o=p();return V(o.setRangeMax(r,n.detail.value))}),k()()}if(i&2){let t=p().$implicit;m(),be("value",t.rangeMin),m(3),be("value",t.rangeMax)}}function TUt(i,e){if(i&1){let t=Ee();C(0,"nile-input",41),Te("nile-change",function(n){R(t);let r=p().$implicit,o=p();return V(o.setScalar(r,n.detail==null?null:n.detail.value))}),k()}if(i&2){let t=p().$implicit;be("value",t.value)}}function AUt(i,e){if(i&1){let t=Ee();C(0,"nile-combobox",42),Te("nile-focus",function(){R(t);let n=p().$implicit,r=p();return V(r.listUsesFetcher(n)&&r.onTypeaheadSearch(n,""))})("nile-change",function(n){R(t);let r=p().$implicit,o=p();return V(o.isMulti(r)?o.setMulti(r,n.detail==null?null:n.detail.value):o.setScalar(r,n.detail==null?null:n.detail.value))}),k()}if(i&2){let t=p().$implicit,M=p();be("multiple",M.isMulti(t))("value",M.valueForControl(t))("autoCompleteOptions",M.listComboOptionsFor(t))("renderItemConfig",M.typeaheadRenderConfig)}}function zUt(i,e){if(i&1){let t=Ee();C(0,"nile-combobox",43),Te("nile-focus",function(){R(t);let n=p().$implicit,r=p();return V(r.onTypeaheadSearch(n,""))})("nile-search",function(n){R(t);let r=p().$implicit,o=p();return V(o.onTypeaheadSearchDebounced(r,(n.detail==null?null:n.detail.query)??""))})("nile-change",function(n){R(t);let r=p().$implicit,o=p();return V(o.isMulti(r)?o.setMulti(r,n.detail==null?null:n.detail.value):o.setScalar(r,n.detail==null?null:n.detail.value))}),k()}if(i&2){let t=p().$implicit,M=p();be("multiple",M.isMulti(t))("value",M.valueForControl(t))("autoCompleteOptions",M.typeaheadOptionsFor(t))("renderItemConfig",M.typeaheadRenderConfig)}}function hUt(i,e){if(i&1){let t=Ee();C(0,"nile-combobox",44),Te("nile-change",function(n){R(t);let r=p().$implicit,o=p();return V(o.setMulti(r,n.detail==null?null:n.detail.value))}),k()}if(i&2){let t=p().$implicit;be("value",t.values)}}function xUt(i,e){if(i&1){let t=Ee();C(0,"nile-combobox",45),Te("nile-change",function(n){R(t);let r=p().$implicit,o=p();return V(o.setScalar(r,n.detail==null?null:n.detail.value))}),k()}if(i&2){let t=p().$implicit,M=p();be("value",t.value)("autoCompleteOptions",M.listOptionsFor(t))}}function pUt(i,e){if(i&1){let t=Ee();C(0,"nile-menu-item",10),Te("click",function(){let n=R(t).$implicit,r=p(2).$implicit,o=p();return V(o.applyPreset(r,n.id))}),v(1),k()}if(i&2){let t=e.$implicit;m(),it(t.label)}}function LUt(i,e){if(i&1&&(C(0,"nile-dropdown",25)(1,"button",46),Ot(2,"nile-glyph",47),k(),C(3,"nile-menu"),xt(4,pUt,2,1,"nile-menu-item",null,jat),k()()),i&2){let t=p().$implicit,M=p();m(4),pt(M.relativePresetsFor(t))}}function OUt(i,e){if(i&1){let t=Ee();xe(0,uUt,2,5,"button",11),C(1,"div",12)(2,"span",13),v(3),k(),C(4,"nile-dropdown",14)(5,"button",15)(6,"span"),v(7),k(),Ot(8,"nile-glyph",16),k(),C(9,"nile-menu"),xt(10,DUt,2,1,"nile-menu-item",null,da),k()(),C(12,"div",17),xe(13,cUt,5,1,"nile-select",18)(14,jUt,2,1)(15,yUt,5,2,"div",19)(16,TUt,1,1,"nile-input",20)(17,AUt,1,4,"nile-combobox",21)(18,zUt,1,4,"nile-combobox",22)(19,hUt,1,1,"nile-combobox",23)(20,xUt,1,2,"nile-combobox",24),k(),xe(21,LUt,6,0,"nile-dropdown",25),C(22,"button",26),Te("click",function(){let n=R(t).$implicit,r=p();return V(r.removeRow(n))}),Ot(23,"nile-glyph",27),k()()}if(i&2){let t=e.$implicit,M=e.$index,n=p();pe(M>0?0:-1),m(3),it(n.labelFor(t.field)),m(4),it(n.operatorLabels[t.op]),m(3),pt(n.operatorsFor(t.field)),m(3),pe(n.isBoolean(t)?13:n.isDate(t)?14:n.isBetween(t)?15:n.fieldTypeFor(t.field)==="number"&&!n.isMulti(t)?16:n.valueModeOf(t)==="list"?17:n.usesTypeahead(t)?18:n.isMulti(t)?19:20),m(8),pe(n.relativePresetsFor(t).length?21:-1)}}function mUt(i,e){if(i&1){let t=Ee();C(0,"nile-menu-item",10),Te("click",function(){let n=R(t).$implicit,r=p(2);return V(r.addRow(n.id??n.name??n.label,"or"))}),v(1),k()}if(i&2){let t=e.$implicit;m(),it(t.label)}}function EUt(i,e){if(i&1){let t=Ee();C(0,"nile-menu-item",10),Te("click",function(){let n=R(t).$implicit,r=p(2);return V(r.addRow(n.id??n.name??n.label,"and"))}),v(1),k()}if(i&2){let t=e.$implicit;m(),it(t.label)}}function fUt(i,e){if(i&1){let t=Ee();C(0,"div",9)(1,"nile-dropdown",48)(2,"span",49)(3,"span",50),Ot(4,"nile-glyph",51),k(),v(5," OR "),k(),C(6,"nile-menu",7),Te("nile-search-value",function(n){R(t);let r=p();return V(r.attrSearch.set((n.detail==null?null:n.detail.value)??""))}),xt(7,mUt,2,1,"nile-menu-item",null,nB),k()(),C(9,"nile-dropdown",48)(10,"span",49)(11,"span",50),Ot(12,"nile-glyph",51),k(),v(13," AND "),k(),C(14,"nile-menu",7),Te("nile-search-value",function(n){R(t);let r=p();return V(r.attrSearch.set((n.detail==null?null:n.detail.value)??""))}),xt(15,EUt,2,1,"nile-menu-item",null,nB),k()(),C(17,"button",52),Te("click",function(){R(t);let n=p();return V(n.clearAll())}),Ot(18,"nile-glyph",27),v(19," Clear "),k()()}if(i&2){let t=p();m(2),ji("mf-conn-add__btn--disabled",t.disabled()),m(5),pt(t.menuAttributes()),m(3),ji("mf-conn-add__btn--disabled",t.disabled()),m(5),pt(t.menuAttributes())}}var SUt=/^-?\d+(\.\d+)?$/,wUt=0,CUt=()=>`mf-row-${++wUt}`,M3=class i{catalog=Et([]);conditions=Et([]);catalogLoading=Et(!1);disabled=Et(!1);valueFetcher=Et(null);onDashboardFields=Et([]);recentlyUsedFields=Et([]);attrSearch=Ye("");conditionsChange=rM();operatorLabels=Zh;expanded=Et(!1);contentHeight=rM();overflowCountChange=rM();overflowCount=-1;lastContentHeight=0;barRef=rf("bar");resizeObs;rows=Ye([]);typeaheadRowId=Ye(null);typeaheadOptions=Ye([]);typeaheadLoading=Ye(!1);static LOADING_VALUE="\0__loading__";static LOADING_ROW={value:"\0__loading__",label:"Loading\u2026"};typeaheadSeq=0;static TYPEAHEAD_DEBOUNCE_MS=250;typeaheadDebounce=null;inFlightFetchKey=null;lastEmittedKey="";constructor(){Co(()=>{let e=this.conditions(),t=wI(e);t!==this.lastEmittedKey&&(this.lastEmittedKey=t,this.rows.set(e.map(M=>this.conditionToRow(M))))},{allowSignalWrites:!0}),id(()=>{let e=this.barRef()?.nativeElement;!e||typeof ResizeObserver>"u"||(this.resizeObs=new ResizeObserver(()=>this.measureOverflow()),this.resizeObs.observe(e),this.measureOverflow())})}ngOnDestroy(){this.resizeObs?.disconnect(),this.typeaheadDebounce&&clearTimeout(this.typeaheadDebounce)}measureOverflow(){let e=this.barRef()?.nativeElement;if(!e)return;let t=Array.from(e.querySelectorAll(".mf-pill")),n=[...new Set(t.map(a=>Math.round(a.offsetTop)))].sort((a,s)=>a-s)[1],r=n===void 0?0:t.filter(a=>Math.round(a.offsetTop)>n).length;r!==this.overflowCount&&(this.overflowCount=r,this.overflowCountChange.emit(r));let o=e.scrollHeight;o!==this.lastContentHeight&&(this.lastContentHeight=o,this.contentHeight.emit(o))}attributes=Ft(()=>e3(this.catalog().filter(e=>e.type==="attribute").filter(e=>K2(e)),{onDashboard:this.onDashboardFields(),recentlyUsed:this.recentlyUsedFields()}));menuAttributes=Ft(()=>{let e=this.attrSearch(),t=this.attributes();return e?t.filter(M=>sat(M,e)):t});onDashboardSet=Ft(()=>new Set(this.onDashboardFields()));isOnDashboard(e){let t=this.onDashboardSet();return[e.id,e.name,e.label].some(M=>!!M&&t.has(M))}attrFor(e){return this.attributes().find(t=>t.id===e||t.name===e||t.label===e)}labelFor(e){return this.attrFor(e)?.label??e}fieldTypeFor(e){return this.attrFor(e)?.fieldType}operatorsFor(e){return q2(this.attrFor(e)??{})}defaultOperatorFor(e){return XV(this.attrFor(e)??{})}valueModeFor(e){let t=this.attrFor(e);return t?Em(t):"free"}isBetween(e){return e.op==="between"}isMulti(e){return e.op==="in"||e.op==="not in"}isDate(e){return this.fieldTypeFor(e.field)==="date"||/(^|[_\s])(date|time|timestamp|datetime)|_(at|on)$/i.test(e.field)?!0:(e.op==="between"?[e.rangeMin,e.rangeMax]:[e.value]).some(M=>typeof M=="string"&&/^\d{4}-\d{2}-\d{2}[T ]/.test(M.trim()))}isBoolean(e){return this.fieldTypeFor(e.field)==="boolean"}valueModeOf(e){return this.valueModeFor(e.field)}usesTypeahead(e){return this.valueModeOf(e)==="search"&&!!this.valueFetcher()}listOptionsFor(e){let M=this.attrFor(e.field)?.sampleValues;return M?.length?M.map(n=>({value:n,label:n})):this.catalog().filter(n=>n.type==="value"&&(!n.id||n.id===e.field)).map(n=>({value:n.label,label:n.label}))}listComboOptionsFor(e){let t=this.typeaheadOptionsFor(e);return t.length?t:this.listOptionsFor(e)}listUsesFetcher(e){return this.valueModeOf(e)==="list"&&!!this.valueFetcher()}relativePresetsFor(e){if(this.fieldTypeFor(e.field)!=="date")return[];let t=this.attrFor(e.field)?.relativePresets;return(t?.length?t:eB).filter(n=>tB(n.id))}dateFormatFor(e){return this.attrFor(e.field)?.format??"YYYY-MM-DD"}fmtDateHour(e){let t=String(e??"").trim();if(!t)return"";let M=new Date(t);return Number.isNaN(M.getTime())?t:M.toISOString().slice(0,16).replace("T"," ")}rangeTriggerText(e){let t=this.fmtDateHour(e.rangeMin),M=this.fmtDateHour(e.rangeMax);return t&&M?`${t} \u2013 ${M}`:t||M}singleTriggerText(e){return this.fmtDateHour(e.value)}typeaheadOptionsFor(e){if(this.typeaheadRowId()!==e.id)return[];let t=this.typeaheadOptions();return t.length===0&&this.typeaheadLoading()?[i.LOADING_ROW]:t}typeaheadRenderConfig={getDisplayText:e=>e.label,getSuffix:()=>""};addRow(e,t="and"){if(this.disabled())return;let M=this.blankRow(e,t);this.rows.update(n=>[...n,M]),this.commit()}toggleConnector(e){this.disabled()||this.patch(e,{connector:e.connector==="or"?"and":"or"})}changeOp(e,t){this.rows.update(M=>M.map(n=>{if(n.id!==e.id)return n;let r=_(x({},n),{op:t}),o=!this.opIsMulti(n.op)&&!this.opIsBetween(n.op),a=!this.opIsMulti(t)&&!this.opIsBetween(t);return o&&a||(r.value=this.fieldTypeFor(n.field)==="boolean"?"true":"",r.values=[],r.rangeMin="",r.rangeMax=""),r})),this.commit()}setScalar(e,t){let M=Array.isArray(t)?t[0]??"":t??"";M!==i.LOADING_VALUE&&this.patch(e,{value:M})}setMulti(e,t){let n=(Array.isArray(t)?t:t?[t]:[]).filter(r=>r!=null&&r!==""&&r!==i.LOADING_VALUE);this.patch(e,{values:n})}setRangeMin(e,t){this.patch(e,{rangeMin:t})}setRangeMax(e,t){this.patch(e,{rangeMax:t})}setSingleDate(e,t){this.patch(e,{value:this.toDateString(t?.value??t?.startDate)})}setRangeDate(e,t){this.patch(e,{rangeMin:this.toDateString(t?.startDate),rangeMax:this.toDateString(t?.endDate??t?.startDate)})}applyPreset(e,t){let M=t3(t);M&&this.patch(e,{op:"between",rangeMin:M.min,rangeMax:M.max})}removeRow(e){this.rows.update(t=>t.filter(M=>M.id!==e.id)),this.commit()}clearAll(){this.disabled()||(this.rows.set([]),this.commit())}onTypeaheadSearchDebounced(e,t){this.typeaheadDebounce&&clearTimeout(this.typeaheadDebounce),this.typeaheadDebounce=setTimeout(()=>{this.typeaheadDebounce=null,this.onTypeaheadSearch(e,t)},i.TYPEAHEAD_DEBOUNCE_MS)}async onTypeaheadSearch(e,t){this.typeaheadDebounce&&(clearTimeout(this.typeaheadDebounce),this.typeaheadDebounce=null);let M=this.valueFetcher();if(!M||!e.field)return;let n=`${e.id}\0${(t??"").trim()}`;if(n===this.inFlightFetchKey)return;this.inFlightFetchKey=n,this.typeaheadRowId()!==e.id&&this.typeaheadOptions.set([]),this.typeaheadRowId.set(e.id);let r=++this.typeaheadSeq;this.typeaheadLoading.set(!0);try{let o=await M(e.field,t??"");if(r!==this.typeaheadSeq)return;this.typeaheadOptions.set(o.map(a=>({value:String(a.value),label:a.label??String(a.value),observed:a.observed})))}catch{r===this.typeaheadSeq&&this.typeaheadOptions.set([])}finally{this.inFlightFetchKey===n&&(this.inFlightFetchKey=null),r===this.typeaheadSeq&&this.typeaheadLoading.set(!1)}}patch(e,t){this.rows.update(M=>M.map(n=>n.id===e.id?x(x({},n),t):n)),this.commit()}blankRow(e,t="and",M=CUt()){let n=lat(e),r=this.defaultOperatorFor(n),o=this.fieldTypeFor(n)==="boolean"?"true":"";return{id:M,field:n,op:r,value:o,values:[],rangeMin:"",rangeMax:"",connector:t}}opIsMulti(e){return e==="in"||e==="not in"}opIsBetween(e){return e==="between"}rowValid(e){if(!e.field)return!1;if(this.opIsBetween(e.op)){let t=e.rangeMin.trim(),M=e.rangeMax.trim();if(t===""||M==="")return!1;if(this.fieldTypeFor(e.field)==="number"){let n=Number(t),r=Number(M);if(Number.isFinite(n)&&Number.isFinite(r)&&n>r)return!1}else if(this.fieldTypeFor(e.field)==="date"&&t>M)return!1;return!0}return this.opIsMulti(e.op)?e.values.length>0:e.value.trim()!==""}rowToCondition(e){let t=this.fieldTypeFor(e.field),M={field:e.field,connector:e.connector};return this.opIsBetween(e.op)?_(x({},M),{op:"between",value:[this.coerce(e.rangeMin,t),this.coerce(e.rangeMax,t)]}):this.opIsMulti(e.op)?_(x({},M),{op:e.op,value:e.values.map(n=>this.coerce(n,t))}):t==="boolean"?_(x({},M),{op:"==",value:e.value==="true"}):_(x({},M),{op:e.op,value:this.coerce(e.value,t)})}conditionToRow(e){let t=this.blankRow(e.field,e.connector??"and");return t.op=e.op,e.op==="between"&&Array.isArray(e.value)?(t.rangeMin=String(e.value[0]??""),t.rangeMax=String(e.value[1]??"")):(e.op==="in"||e.op==="not in")&&Array.isArray(e.value)?t.values=e.value.map(M=>String(M)):t.value=String(e.value),t}commit(){let e=this.rows().filter(M=>this.rowValid(M)).map(M=>this.rowToCondition(M)),t=wI(e);t!==this.lastEmittedKey&&(this.lastEmittedKey=t,this.conditionsChange.emit(e))}coerce(e,t){return t==="date"?e:(t==="number"||t===void 0)&&SUt.test(e)?Number(e):e}toDateString(e){if(!e)return"";if(typeof e=="string"){let o=e.match(/^(\d{4})-(\d{2})-(\d{2})/);if(o)return`${o[1]}-${o[2]}-${o[3]}`}let t=new Date(e);if(isNaN(t.getTime()))return typeof e=="string"?e:"";let M=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${M}-${n}-${r}`}valueForControl(e){return this.isMulti(e)?e.values:e.value}static \u0275fac=function(t){return new(t||i)};static \u0275cmp=oM({type:i,selectors:[["shared-manual-filter-panel"]],viewQuery:function(t,M){t&1&&Mf(M.barRef,lUt,5),t&2&&nf()},inputs:{catalog:[1,"catalog"],conditions:[1,"conditions"],catalogLoading:[1,"catalogLoading"],disabled:[1,"disabled"],valueFetcher:[1,"valueFetcher"],onDashboardFields:[1,"onDashboardFields"],recentlyUsedFields:[1,"recentlyUsedFields"],expanded:[1,"expanded"]},outputs:{conditionsChange:"conditionsChange",contentHeight:"contentHeight",overflowCountChange:"overflowCountChange"},decls:15,vars:6,consts:[["bar",""],[1,"mf-panel"],[1,"mf-panel__clip"],[1,"mf-panel__bar"],["hoist","","placement","bottom-start",1,"mf-add"],["slot","trigger",1,"mf-add__btn"],["name","ng-list-filter","method","stroke","size","14","color","#155EEFFF"],["searchEnabled","","customSearch","",3,"nile-search-value"],["variant","rounded","width","200","height","34"],[1,"mf-actions"],[3,"click"],["type","button",1,"mf-conn","mf-conn--toggle",3,"mf-conn--disabled","title"],[1,"mf-pill"],[1,"mf-seg","mf-seg--field"],["hoist","","placement","bottom-start",1,"mf-pill__menu"],["slot","trigger","type","button",1,"mf-seg","mf-seg--op"],["name","ng-chevron-down","method","stroke","size","12"],[1,"mf-seg","mf-seg--value"],["size","small","hoist","",3,"value"],[1,"mf-range"],["size","small","type","number","placeholder","Value",3,"value"],["size","small","hoist","","portal","","clearable","","allowCustomValue","","placeholder","Value",3,"multiple","value","autoCompleteOptions","renderItemConfig"],["size","small","hoist","","portal","","clearable","","allowCustomValue","","disableLocalSearch","","placeholder","Search\u2026",3,"multiple","value","autoCompleteOptions","renderItemConfig"],["size","small","hoist","","portal","","clearable","","allowCustomValue","","multiple","","placeholder","Add values",3,"value"],["size","small","hoist","","portal","","clearable","","allowCustomValue","","placeholder","Value","noDataMessage","Type a value",3,"value","autoCompleteOptions"],["hoist","","placement","bottom-start",1,"mf-pill__menu","borders"],["type","button","aria-label","Remove filter",1,"mf-pill__x",3,"click"],["name","ng-x-close","method","stroke","size","12"],["type","button",1,"mf-conn","mf-conn--toggle",3,"click","title"],["size","small","hoist","",3,"nile-change","value"],["value","true"],["value","false"],["range","","allowClear","",3,"dateFormat"],["allowClear","",3,"dateFormat"],["range","","allowClear","",3,"nile-change","dateFormat"],["slot","trigger","size","small","placeholder","Date range",3,"value"],["allowClear","",3,"nile-change","dateFormat"],["slot","trigger","size","small","placeholder","Pick a date",3,"value"],["size","small","type","number","placeholder","Min",3,"nile-change","value"],[1,"mf-range__sep"],["size","small","type","number","placeholder","Max",3,"nile-change","value"],["size","small","type","number","placeholder","Value",3,"nile-change","value"],["size","small","hoist","","portal","","clearable","","allowCustomValue","","placeholder","Value",3,"nile-focus","nile-change","multiple","value","autoCompleteOptions","renderItemConfig"],["size","small","hoist","","portal","","clearable","","allowCustomValue","","disableLocalSearch","","placeholder","Search\u2026",3,"nile-focus","nile-search","nile-change","multiple","value","autoCompleteOptions","renderItemConfig"],["size","small","hoist","","portal","","clearable","","allowCustomValue","","multiple","","placeholder","Add values",3,"nile-change","value"],["size","small","hoist","","portal","","clearable","","allowCustomValue","","placeholder","Value","noDataMessage","Type a value",3,"nile-change","value","autoCompleteOptions"],["slot","trigger","type","button","title","Relative date",1,"mf-seg","mf-seg--preset"],["name","ng-calendar","method","stroke","size","12"],["hoist","","placement","bottom-end",1,"mf-conn-add"],["slot","trigger",1,"mf-conn-add__btn"],[1,"mf-conn-add__ring"],["name","ng-plus","method","stroke","size","10"],["type","button",1,"mf-clear",3,"click"]],template:function(t,M){t&1&&(C(0,"div",1)(1,"div",2)(2,"div",3,0)(4,"nile-dropdown",4)(5,"span",5),Ot(6,"nile-glyph",6),v(7," Add filter "),k(),C(8,"nile-menu",7),Te("nile-search-value",function(r){return M.attrSearch.set((r.detail==null?null:r.detail.value)??"")}),xt(9,gUt,2,1,"nile-menu-item",null,nB),k()(),xe(11,NUt,1,0,"nile-skeleton-loader",8),xt(12,OUt,24,5,null,null,jat),xe(14,fUt,20,4,"div",9),k()()()),t&2&&(m(),ji("mf-panel__clip--collapsed",!M.expanded()),m(4),ji("mf-add__btn--disabled",M.disabled()),m(4),pt(M.menuAttributes()),m(2),pe(M.catalogLoading()&&!M.rows().length?11:-1),m(),pt(M.rows()),m(2),pe(M.rows().length?14:-1))},dependencies:[Pa],styles:["[_nghost-%COMP%]{display:flex;width:100%;height:100%;overflow:visible}.mf-panel[_ngcontent-%COMP%]{position:relative;display:flex;flex-direction:column;width:100%;height:100%;padding:var(--ng-spacing-4) var(--ng-spacing-5) 0 var(--ng-spacing-5)}.mf-panel__bar[_ngcontent-%COMP%]{position:relative;display:flex;flex-wrap:wrap;align-items:center;gap:var(--ng-spacing-2);min-width:0;padding-right:200px}.mf-pill[_ngcontent-%COMP%]{display:inline-flex;align-items:stretch;height:34px;border:1px solid var(--ng-colors-border-secondary);border-radius:var(--ng-radius-md);background:var(--ng-colors-bg-primary);overflow:hidden}.mf-pill__menu[_ngcontent-%COMP%]{display:inline-flex}.borders[_ngcontent-%COMP%]{border-right:1px solid var(--ng-colors-border-secondary)}.mf-seg[_ngcontent-%COMP%]{display:inline-flex;align-items:center;gap:var(--ng-spacing-1);height:100%;padding:0 var(--ng-spacing-2);border:none;background:transparent;font:inherit;font-size:13px;color:var(--ng-colors-text-primary-900);white-space:nowrap;cursor:pointer}.mf-seg--field[_ngcontent-%COMP%]{font-weight:500;border-right:1px solid var(--ng-colors-border-primary);cursor:default}.mf-seg--op[_ngcontent-%COMP%]:hover, .mf-seg--preset[_ngcontent-%COMP%]:hover{background:var(--ng-colors-bg-secondary)}.mf-seg[_ngcontent-%COMP%] nile-glyph[_ngcontent-%COMP%]{color:var(--ng-colors-fg-quaternary-400)}.mf-seg--value[_ngcontent-%COMP%]{padding:0;cursor:default}.mf-seg--value[_ngcontent-%COMP%] nile-input[_ngcontent-%COMP%], .mf-seg--value[_ngcontent-%COMP%] nile-combobox[_ngcontent-%COMP%], .mf-seg--value[_ngcontent-%COMP%] nile-select[_ngcontent-%COMP%], .mf-seg--value[_ngcontent-%COMP%] nile-date-picker[_ngcontent-%COMP%]{--nile-input-border-color: transparent;min-width:120px}.mf-seg--value[_ngcontent-%COMP%] nile-date-picker[_ngcontent-%COMP%]{--nile-input-standard-border-color: transparent;--nile-input-standard-background-color: transparent}.mf-seg--value[_ngcontent-%COMP%] nile-date-picker[_ngcontent-%COMP%] nile-input[_ngcontent-%COMP%]{min-width:280px}.mf-range[_ngcontent-%COMP%]{display:inline-flex;align-items:center;gap:var(--ng-spacing-1)}.mf-range[_ngcontent-%COMP%] nile-input[_ngcontent-%COMP%]{min-width:72px}.mf-range__sep[_ngcontent-%COMP%]{color:var(--ng-colors-text-secondary-700)}.mf-pill__x[_ngcontent-%COMP%]{display:inline-flex;align-items:center;justify-content:center;padding:0 var(--ng-spacing-2);border:none;background:transparent;color:var(--ng-colors-fg-quaternary-400);cursor:pointer}.mf-pill__x[_ngcontent-%COMP%]:hover{color:var(--ng-colors-fg-error-primary);background:var(--ng-colors-bg-error-primary)}.mf-add[_ngcontent-%COMP%]{display:inline-flex}.mf-add__btn[_ngcontent-%COMP%]{display:inline-flex;align-items:center;gap:var(--ng-spacing-1);height:34px;font:inherit;font-size:14px;font-weight:500;color:var(--ng-colors-fg-brand-primary-600);cursor:pointer}.mf-add__btn[_ngcontent-%COMP%] nile-glyph[_ngcontent-%COMP%]{color:var(--ng-colors-fg-quaternary-400)}.mf-add__btn--disabled[_ngcontent-%COMP%]{pointer-events:none;opacity:.5}.mf-clear[_ngcontent-%COMP%]{display:inline-flex;align-items:center;gap:var(--ng-spacing-1);height:34px;padding:0 var(--ng-spacing-3);border:1px solid var(--ng-colors-border-secondary);border-radius:var(--ng-radius-md);background:var(--ng-colors-bg-primary);font:inherit;font-size:13px;font-weight:500;color:var(--ng-colors-text-secondary-700);cursor:pointer}.mf-clear[_ngcontent-%COMP%]:hover{color:var(--ng-colors-fg-error-primary)}.mf-panel__clip--collapsed[_ngcontent-%COMP%]{max-height:calc(68px + var(--ng-spacing-2));overflow:hidden}.mf-actions[_ngcontent-%COMP%]{position:absolute;top:0;right:0;display:inline-flex;align-items:center;gap:var(--ng-spacing-2)}.mf-conn-add__btn[_ngcontent-%COMP%]{display:inline-flex;align-items:center;gap:var(--ng-spacing-1);height:34px;font-size:14px;font-weight:500;color:var(--ng-colors-fg-brand-primary-600);cursor:pointer}.mf-conn-add__btn[_ngcontent-%COMP%] nile-glyph[_ngcontent-%COMP%]{color:var(--ng-colors-fg-brand-primary-600)}.mf-conn-add__ring[_ngcontent-%COMP%]{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;border:1px solid currentColor;border-radius:50%}.mf-conn-add__btn--disabled[_ngcontent-%COMP%]{pointer-events:none;opacity:.5}.mf-conn[_ngcontent-%COMP%]{display:inline-flex;align-items:center;font-size:11px;font-weight:600;color:var(--ng-colors-text-tertiary-600)}.mf-conn--toggle[_ngcontent-%COMP%]{padding:2px var(--ng-spacing-1);border:1px solid transparent;border-radius:var(--ng-radius-xs, 4px);background:none;font:inherit;font-size:11px;font-weight:600;line-height:1;color:var(--ng-colors-text-tertiary-600);cursor:pointer}.mf-conn--toggle[_ngcontent-%COMP%]:hover, .mf-conn--toggle[_ngcontent-%COMP%]:focus-visible{border-color:var(--ng-colors-border-brand-solid, currentColor);color:var(--ng-colors-fg-brand-primary-600)}.mf-conn--toggle[_ngcontent-%COMP%]:focus-visible{outline:none}.mf-conn--disabled[_ngcontent-%COMP%]{pointer-events:none;opacity:.5}"]})};var kUt=(i,e)=>e.mode,bUt=(i,e)=>e.label,QUt=(i,e)=>e.id,UUt=(i,e)=>e.op;function vUt(i,e){if(i&1){let t=Ee();q(0,"button",17),Fe("click",function(){let n=R(t).$implicit,r=p(),o=GA(3);return r.pickMode(n.mode),V(o.hide())}),It(1,"nile-glyph",18),q(2,"span",19)(3,"span",20),v(4),Me(),q(5,"span",21),v(6),Me()(),q(7,"span",22),v(8),Me()()}if(i&2){let t=e.$implicit,M=p();ji("is-active",t.mode===M.activeMode().mode),mt("aria-checked",t.mode===M.activeMode().mode),m(),Lt("name",t.icon),m(3),it(t.label),m(2),it(t.desc),m(2),it(t.mode===M.activeMode().mode?"\u2713":"")}}function YUt(i,e){if(i&1){let t=Ee();q(0,"button",31),Fe("click",function(){R(t);let n=p().$index,r=p(2);return V(r.toggleJoin(n))}),v(1),Me()}if(i&2){let t=p().$implicit,M=p(2);Lt("disabled",M.busy()),mt("aria-label","Join with "+(t.connector==="or"?"OR":"AND")+" \u2014 click to change"),m(),it(t.connector==="or"?"OR":"AND")}}function ZUt(i,e){if(i&1){let t=Ee();xe(0,YUt,2,3,"button",25),q(1,"span",26)(2,"span",27),v(3),Me(),q(4,"span",28),v(5),Me(),q(6,"span",29),v(7),Me(),q(8,"button",30),Fe("click",function(){let n=R(t).$index,r=p(2);return V(r.removeChip(n))}),v(9,"\u2715"),Me()()}if(i&2){let t=e.$implicit,M=e.$index,n=p(2);pe(M>0?0:-1),m(3),it(n.fieldLabel(t.field)),m(2),it(n.opLabel(t.op)),m(2),it(n.valueLabel(t)),m(),Lt("disabled",n.busy()),mt("aria-label","Remove filter "+n.fieldLabel(t.field))}}function _Ut(i,e){if(i&1){let t=Ee();q(0,"div",12),xt(1,ZUt,10,6,null,null,Yr),q(3,"span",23)(4,"nile-button",24),Fe("click",function(){R(t);let n=p();return V(n.openCondPop())}),v(5," + Add filter "),Me()()()}if(i&2){let t=p();m(),pt(t.conditions()),m(3),mt("disabled",t.busy()?"":null)}}function WUt(i,e){if(i&1&&(q(0,"span",43),v(1),Me()),i&2){let t=p(2);ji("is-error",!!t.exprState().error)("is-warn",t.exprState().partial),m(),it(t.exprState().error?"!":t.exprState().partial?"~":"\u2713")}}function PUt(i,e){if(i&1&&It(0,"span",46),i&2){let t=e.$implicit;dM("width",t,"%")}}function RUt(i,e){if(i&1&&(xt(0,PUt,1,2,"span",44,da),q(2,"span",45),v(3,"Loading values\u2026"),Me()),i&2){let t=p(3);pt(t.skeletonRows)}}function VUt(i,e){if(i&1){let t=Ee();q(0,"button",48),Fe("click",function(){let n=R(t).$implicit,r=p(4);return V(r.applySuggestion(n.insert))}),q(1,"span",49),v(2),Me(),q(3,"span",50),v(4),Me()()}if(i&2){let t=e.$implicit;m(2),it(t.label),m(),ji("is-badge",t.hint==="CONNECTOR"||t.hint==="KEYWORD"||t.hint==="value"),m(),it(t.hint)}}function BUt(i,e){if(i&1&&xt(0,VUt,5,4,"button",47,bUt),i&2){let t=p(3);pt(t.suggestions())}}function FUt(i,e){if(i&1&&(q(0,"span",37),xe(1,RUt,4,0)(2,BUt,2,0),Me()),i&2){let t=p(2);mt("aria-busy",t.suggestLoading()),m(),pe(t.suggestLoading()?1:2)}}function HUt(i,e){if(i&1&&(q(0,"span",39),v(1),Me()),i&2){let t=p(2);m(),it(t.exprState().error)}}function JUt(i,e){i&1&&(q(0,"span",40),v(1,"Valid, but "),q(2,"code"),v(3,"or"),Me(),v(4," / bare "),q(5,"code"),v(6,"not"),Me(),v(7," / grouping are dropped on apply."),Me())}function GUt(i,e){i&1&&(q(0,"span",41),v(1,"Valid"),Me())}function $Ut(i,e){if(i&1){let t=Ee();q(0,"span",32)(1,"span",33),It(2,"nile-glyph",34),Me(),q(3,"input",35),Fe("ngModelChange",function(n){R(t);let r=p();return r.exprDraft.set(n),V(r.suggestDismissed.set(!1))})("focus",function(){R(t);let n=p();return V(n.suggestDismissed.set(!1))})("keydown",function(n){R(t);let r=p();return V(r.onExprKeydown(n))}),Me(),xe(4,WUt,2,5,"span",36),xe(5,FUt,3,2,"span",37),Me(),q(6,"span",38),xe(7,HUt,2,1,"span",39)(8,JUt,8,0,"span",40)(9,GUt,2,0,"span",41),Me(),q(10,"nile-button",42),Fe("click",function(){R(t);let n=p();return V(n.runExpression())}),v(11,"Run"),Me()}if(i&2){let t=p();ji("is-error",t.exprState().error),m(3),Lt("disabled",t.busy())("ngModel",t.exprDraft()),mt("aria-expanded",t.suggestions().length>0),m(),pe(t.exprState().empty?-1:4),m(),pe(t.suggestLoading()||t.suggestions().length?5:-1),m(2),pe(t.exprState().error?7:t.exprState().partial?8:t.exprState().ok?9:-1),m(3),mt("disabled",t.busy()||!t.exprState().ok?"":null)}}function XUt(i,e){if(i&1){let t=Ee();q(0,"span",51)(1,"span",52),It(2,"nile-glyph",53),Me(),q(3,"input",54),Fe("ngModelChange",function(n){R(t);let r=p();return V(r.promptDraft.set(n))})("keydown",function(n){R(t);let r=p();return V(r.onPromptKeydown(n))}),Me()(),q(4,"nile-button",42),Fe("click",function(){R(t);let n=p();return V(n.askPrompt())}),v(5,"Ask"),Me()}if(i&2){let t=p();m(3),Lt("disabled",t.busy())("ngModel",t.promptDraft()),m(),mt("disabled",t.busy()||!t.promptDraft().trim()?"":null)}}function qUt(i,e){if(i&1&&(q(0,"span",14),v(1),Me()),i&2){let t=p();m(),Bo("",t.chipCount()," ",t.chipCount()===1?"filter":"filters")}}function KUt(i,e){if(i&1&&(q(0,"nile-option",60),v(1),Me()),i&2){let t=e.$implicit;Lt("value",t.id),m(),it(t.label)}}function evt(i,e){if(i&1&&(q(0,"nile-option",60),v(1),Me()),i&2){let t=e.$implicit;Lt("value",t.op),m(),it(t.label)}}function tvt(i,e){i&1&&(q(0,"span",62),It(1,"span",69),Me())}function ivt(i,e){if(i&1&&(q(0,"nile-option",60),v(1),Me()),i&2){let t=e.$implicit;Lt("value",t),m(),it(t)}}function Mvt(i,e){if(i&1){let t=Ee();q(0,"nile-select",70),Fe("nile-change",function(n){R(t);let r=p(2);return V(r.draftValue.set(n.target.value))}),xt(1,ivt,2,2,"nile-option",60,da),Me()}if(i&2){let t=p(2);Lt("value",t.draftValue()),m(),pt(t.draftValueOptions())}}function nvt(i,e){if(i&1){let t=Ee();q(0,"nile-input",71),Fe("nile-change",function(n){R(t);let r=p(2);return V(r.draftValue.set(n.target.value))}),Me()}if(i&2){let t=p(2);Lt("value",t.draftValue())}}function rvt(i,e){if(i&1){let t=Ee();q(0,"div",65)(1,"span",72),v(2,"Join with"),Me(),q(3,"div",73)(4,"button",74),Fe("click",function(){R(t);let n=p(2);return V(n.draftJoin.set("and"))}),v(5,"AND"),Me(),q(6,"button",74),Fe("click",function(){R(t);let n=p(2);return V(n.draftJoin.set("or"))}),v(7,"OR"),Me()()()}if(i&2){let t=p(2);m(4),ji("is-active",t.draftJoin()==="and"),m(2),ji("is-active",t.draftJoin()==="or")}}function ovt(i,e){if(i&1){let t=Ee();q(0,"div",16)(1,"div",55)(2,"span",56),v(3,"Add condition"),Me(),q(4,"span",57),v(5,"Manual filters"),Me()(),q(6,"div",58)(7,"nile-select",59),Fe("nile-change",function(n){R(t);let r=p();return V(r.onDraftFieldChange(n.target.value))}),xt(8,KUt,2,2,"nile-option",60,QUt),Me(),q(10,"nile-select",61),Fe("nile-change",function(n){R(t);let r=p();return V(r.onDraftOpChange(n.target.value))}),xt(11,evt,2,2,"nile-option",60,UUt),Me(),xe(13,tvt,2,0,"span",62)(14,Mvt,3,1,"nile-select",63)(15,nvt,1,1,"nile-input",64),Me(),xe(16,rvt,8,4,"div",65),q(17,"div",66)(18,"nile-button",67),Fe("click",function(){R(t);let n=p();return V(n.condPopOpen.set(!1))}),v(19,"Cancel"),Me(),q(20,"nile-button",68),Fe("click",function(){R(t);let n=p();return V(n.applyDraft())}),v(21,"Apply filter"),Me()()()}if(i&2){let t=p();m(7),Lt("value",t.draftField()),m(),pt(t.fields()),m(2),Lt("value",t.draftOp()),m(),pt(t.operators),m(2),pe(t.draftValuesLoading()?13:t.draftValueOptions().length?14:15),m(3),pe(t.conditions().length?16:-1),m(4),mt("disabled",t.canApplyDraft()?null:"")}}var avt=new Set(["NILE-SELECT","NILE-OPTION","NILE-INPUT"]);function svt(i){let t=(i instanceof Error?i.message:String(i)).split(`
|
|
40484
40484
|
`).map(r=>r.trim()).filter(Boolean),M=[...t].reverse().find(r=>/^(Expecting|Unrecognized|Unexpected)/i.test(r));return M?M.replace(/\s+/g," "):t.find(r=>/lexical error/i.test(r))??t[0]??"Invalid expression"}var lvt=new Set(["==","!=","<","<=",">",">=","~="]),n3=class i{mode=Et("prompt");conditions=Et([]);catalog=Et([]);expression=Et("");busy=Et(!1);valueFetcher=Et(null);modeChange=rM();conditionsChange=rM();expressionRun=rM();promptAsk=rM();clearAll=rM();modeMenuOpen=Ye(!1);condPopOpen=Ye(!1);exprDraft=Ye("");promptDraft=Ye("");draftField=Ye("");draftOp=Ye("==");draftValue=Ye("");draftJoin=Ye("and");modes=[{mode:"prompt",icon:"ng-brain",label:"Prompt",desc:"Ask in plain words and let it build the filter."},{mode:"expression",icon:"ng-square-function",label:"Filtrex expression",desc:'Type a validated expression, e.g. status != "Success".'},{mode:"manual",icon:"ng-filter-lines",label:"Manual filters",desc:"Pick a field, operator and value \u2014 combined with AND / OR."}];operators=Om.map(e=>({op:e,label:Zh[e]}));activeMode=Ft(()=>this.modes.find(e=>e.mode===this.mode())??this.modes[0]);fields=Ft(()=>this.catalog().filter(e=>e.type==="attribute").map(e=>({id:e.id??e.name??e.label,label:e.label})));draftAttr=Ft(()=>this.catalog().find(e=>(e.id??e.name??e.label)===this.draftField()));draftValues=Ye([]);draftValuesLoading=Ye(!1);draftValueSeq=0;draftValueOptions=Ft(()=>{let e=this.draftValues();return e.length?[...e]:[...this.draftAttr()?.sampleValues??[]]});requestDraftValues(e){this.draftValues.set([]);let t=this.valueFetcher();if(!t||!e){this.draftValuesLoading.set(!1);return}this.draftValuesLoading.set(!0);let M=++this.draftValueSeq;t(e,"").then(n=>{M===this.draftValueSeq&&(this.draftValues.set(n.map(r=>String(r.label??r.value))),this.draftValuesLoading.set(!1))}).catch(()=>{M===this.draftValueSeq&&(this.draftValues.set([]),this.draftValuesLoading.set(!1))})}canApplyDraft=Ft(()=>!!this.draftField()&&this.draftValue().trim().length>0);chipCount=Ft(()=>this.conditions().length);canClear=Ft(()=>this.mode()==="manual"?this.chipCount()>0:this.mode()==="expression"?this.exprDraft().trim().length>0||this.expression().trim().length>0:this.promptDraft().trim().length>0);fieldLabel(e){return this.catalog().find(M=>(M.id??M.name??M.label)===e)?.label??e}opLabel(e){return Zh[e]??e}valueLabel(e){return qV(e)}clauseError(e){let t=null;try{t=G2(e)}catch{return null}let M=t?.type==="Compound"?t.body??[]:[t];for(let n=0;n<M.length;n++){let r=M[n];if(n%2===1){if(!(r?.type==="Identifier"&&/^(and|or)$/i.test(r.name??"")))return'Expected "and" or "or" between conditions';continue}if(!i.isPredicate(r)){let o=i.nameOf(r);return o?`"${o}" is not a condition yet \u2014 add an operator and a value, e.g. ${o} == "\u2026"`:"Incomplete condition \u2014 expected field, operator and value"}}return M.length%2===0?"Expression ends with a connector \u2014 add another condition":null}static nameOf(e){let t=e;if(t?.type==="Identifier")return t.name??null;if(t?.type==="MemberExpression"){let M=i.nameOf(t.object),n=i.nameOf(t.property);return M&&n?`${M}.${n}`:null}return null}static isPredicate(e){let t=e;return t?.type?t.type==="BinaryExpression"?lvt.has(t.operator??""):t.type==="UnaryExpression"?(t.operator??"").toLowerCase()==="not"&&i.isPredicate(t.argument):t.type==="CallExpression":!1}exprState=Ft(()=>{let e=this.exprDraft().trim();if(!e)return{ok:!1,empty:!0,error:null,partial:!1};if(/\b(and|or)\s*$/i.test(e))return{ok:!1,empty:!1,error:"Expression ends with a connector \u2014 add another condition",partial:!1};try{wJ(e)}catch(M){return{ok:!1,empty:!1,error:svt(M),partial:!1}}let t=this.clauseError(e);return t?{ok:!1,empty:!1,error:t,partial:!1}:Sm(e)?{ok:!0,empty:!1,error:null,partial:!1}:{ok:!0,empty:!1,error:null,partial:!0}});skeletonRows=[72,54,63,45];suggestDismissed=Ye(!1);suggestContext=Ft(()=>{let e=this.exprDraft(),t=/\s+(?:and|or)\s+/gi,M=0;for(let D=t.exec(e);D;D=t.exec(e))M=D.index+D[0].length;let n=e.slice(M),r=/^(\s*)([A-Za-z_][\w.]*)?(\s*)(==|!=|<=|>=|~=|<|>)?(\s*)(.*)$/.exec(n),o=r?.[1]??"",a=r?.[2]??"",s=r?.[3]??"",l=r?.[4]??"",N=r?.[6]??"";if(l){let D=/^("[^"]*"|'[^']*'|-?\d+(?:\.\d+)?)(\s*)$/.exec(N);return D?D[2].length>0?{kind:"joiner",from:e.length,partial:"",field:a}:{kind:"none",from:e.length,partial:"",field:a}:{kind:"value",from:e.length-N.length,partial:N,field:a}}return a&&s?{kind:"op",from:e.length,partial:"",field:a}:{kind:"field",from:M+o.length,partial:a,field:""}});suggestingValue=Ft(()=>!this.suggestDismissed()&&this.suggestContext().kind==="value");suggestLoading=Ft(()=>this.suggestingValue()&&this.exprValuesLoading()&&!this.fetchedValues().length);suggestions=Ft(()=>{if(this.suggestDismissed())return[];let e=this.suggestContext(),t=e.partial.replace(/^["']/,"").toLowerCase();if(e.kind==="field")return this.catalog().filter(o=>o.type==="attribute").map(o=>({id:o.id??o.name??o.label,label:o.label})).filter(o=>!t||o.id.toLowerCase().includes(t)||o.label.toLowerCase().includes(t)).slice(0,8).map(o=>({label:o.id,hint:o.label,insert:o.id}));if(e.kind==="op")return this.operators.slice(0,8).map(o=>({label:o.op,hint:o.label,insert:o.op}));if(e.kind==="none")return[];if(e.kind==="joiner")return[{label:"and",hint:"CONNECTOR",insert:"and"},{label:"or",hint:"CONNECTOR",insert:"or"}];let M=this.catalog().find(o=>(o.id??o.name??o.label)===e.field),n=this.fetchedValues();return(n.length?n:[...M?.sampleValues??[]]).filter(o=>!t||String(o).toLowerCase().includes(t)).slice(0,8).map(o=>({label:String(o),hint:"value",insert:`"${String(o)}"`}))});fetchedFor=Ye("");fetchedValues=Ye([]);exprValuesLoading=Ye(!1);fetchSeq=0;valueLookup=Co(()=>{let e=this.suggestContext();e.kind==="value"&&e.field&&this.requestValues()});requestValues(){let e=this.suggestContext();if(e.kind!=="value"||!e.field)return;let t=e.field+"\0"+e.partial.replace(/^["']/,"");if(this.fetchedFor()===t)return;let M=this.valueFetcher();if(!M)return;this.fetchedFor.set(t),this.exprValuesLoading.set(!0);let n=++this.fetchSeq;M(e.field,e.partial.replace(/^["']/,"")).then(r=>{n===this.fetchSeq&&(this.fetchedValues.set(r.map(o=>String(o.label??o.value))),this.exprValuesLoading.set(!1))}).catch(()=>{n===this.fetchSeq&&(this.fetchedValues.set([]),this.exprValuesLoading.set(!1))})}dismissSuggestions(){this.suggestDismissed.set(!0)}applySuggestion(e){let t=this.suggestContext(),n=this.exprDraft().slice(0,Math.max(0,t.from)),r=t.kind==="op"||n&&!/[\s(]$/.test(n)?" ":"";this.exprDraft.set(n+r+e+" ")}host=Be(Vo);onDocumentClick(e){let t=e.composedPath?.()??[];if(t.some(r=>r instanceof HTMLElement&&avt.has(r.tagName)))return;let M=this.host.nativeElement,n=t.indexOf(M);if(n!==-1){let r=t.slice(0,n),o=N=>r.some(D=>D instanceof HTMLElement&&D.matches?.(N)),a=o(".rail__mode"),s=o(".pop--cond, .add-filter"),l=o(".inline-wrap");a||this.modeMenuOpen.set(!1),s||this.condPopOpen.set(!1),l||this.suggestDismissed.set(!0);return}this.modeMenuOpen.set(!1),this.condPopOpen.set(!1),this.suggestDismissed.set(!0)}onEscape(){this.modeMenuOpen.set(!1),this.condPopOpen.set(!1),this.suggestDismissed.set(!0)}pickMode(e){this.modeMenuOpen.set(!1),e!==this.mode()&&(this.resetDrafts(),this.modeChange.emit(e))}resetDrafts(){this.exprDraft.set(""),this.promptDraft.set(""),this.condPopOpen.set(!1),this.suggestDismissed.set(!0),this.draftField.set(""),this.draftOp.set("=="),this.draftValue.set(""),this.draftJoin.set("and")}openCondPop(){let e=this.fields()[0]?.id??"";this.draftField.set(e),this.draftOp.set("=="),this.draftValue.set(""),this.draftJoin.set("and"),this.condPopOpen.set(!0),this.requestDraftValues(e)}onDraftOpChange(e){let t=this.operators.find(M=>M.op===e);t&&this.draftOp.set(t.op)}onDraftFieldChange(e){this.draftField.set(e),this.requestDraftValues(e),this.draftValue.set("")}applyDraft(){if(!this.canApplyDraft())return;let e=x({field:this.draftField(),op:this.draftOp(),value:this.draftValue().trim()},this.conditions().length&&this.draftJoin()==="or"?{connector:"or"}:{});this.conditionsChange.emit([...this.conditions(),e]),this.condPopOpen.set(!1)}removeChip(e){let t=this.conditions().filter((M,n)=>n!==e);t.length&&(t[0]=_(x({},t[0]),{connector:void 0})),this.conditionsChange.emit(t)}toggleJoin(e){let t=[...this.conditions()],M=t[e];M&&(t[e]=_(x({},M),{connector:M.connector==="or"?"and":"or"}),this.conditionsChange.emit(t))}runExpression(){this.exprState().ok&&(this.suggestDismissed.set(!0),this.expressionRun.emit(this.exprDraft().trim()))}askPrompt(){let e=this.promptDraft().trim();e&&this.promptAsk.emit(e)}onExprKeydown(e){if(e.key==="Escape"){this.dismissSuggestions();return}this.suggestDismissed.set(!1),e.key==="Enter"&&(e.preventDefault(),this.runExpression())}onPromptKeydown(e){e.key==="Enter"&&(e.preventDefault(),this.askPrompt())}onClearAll(){this.resetDrafts(),this.clearAll.emit()}static \u0275fac=function(t){return new(t||i)};static \u0275cmp=oM({type:i,selectors:[["shared-filter-rail"]],hostBindings:function(t,M){t&1&&Fe("click",function(r){return M.onDocumentClick(r)},JQ)("keydown.escape",function(){return M.onEscape()},JQ)},inputs:{mode:[1,"mode"],conditions:[1,"conditions"],catalog:[1,"catalog"],expression:[1,"expression"],busy:[1,"busy"],valueFetcher:[1,"valueFetcher"]},outputs:{modeChange:"modeChange",conditionsChange:"conditionsChange",expressionRun:"expressionRun",promptAsk:"promptAsk",clearAll:"clearAll"},decls:24,vars:7,consts:[["modeDropdown",""],[1,"rail"],[1,"rail__mode"],["placement","bottom-start","distance","6",1,"mode-dropdown"],["slot","trigger","type","button","aria-haspopup","menu",1,"mode-btn",3,"disabled"],["method","stroke","size","16",1,"mode-btn__ico",3,"name"],[1,"mode-btn__label"],["aria-hidden","true",1,"mode-btn__caret"],["role","menu",1,"mode-menu"],[1,"mode-menu__heading"],["type","button","role","menuitemradio",1,"mode-item",3,"is-active"],[1,"rail__panel"],[1,"rail__chips"],[1,"rail__right"],[1,"match-label"],["variant","secondary",1,"clear-all",3,"click"],["role","dialog","aria-label","Add condition",1,"pop","pop--cond"],["type","button","role","menuitemradio",1,"mode-item",3,"click"],["method","stroke","size","16",1,"mode-item__ico",3,"name"],[1,"mode-item__text"],[1,"mode-item__label"],[1,"mode-item__desc"],["aria-hidden","true",1,"mode-item__check"],[1,"add-filter"],["variant","ghost",1,"add-filter__btn",3,"click"],["type","button",1,"join-badge",3,"disabled"],[1,"chip"],[1,"chip__f"],[1,"chip__op"],[1,"chip__val"],["type","button",1,"chip__x",3,"click","disabled"],["type","button",1,"join-badge",3,"click","disabled"],[1,"inline-wrap","inline-wrap--suggest"],["aria-hidden","true",1,"inline-wrap__badge","inline-wrap__badge--fx"],["name","ng-square-function","method","stroke","size","15"],["type","text","spellcheck","false","aria-label","Filtrex expression","placeholder",'status != "Success" and department == "Engineering"',"autocomplete","off","role","combobox","aria-autocomplete","list",1,"inline-wrap__input",3,"ngModelChange","focus","keydown","disabled","ngModel"],["aria-hidden","true",1,"inline-wrap__state",3,"is-error","is-warn"],["role","listbox",1,"suggest"],["role","status",1,"inline-status"],[1,"is-error"],[1,"is-warn"],[1,"is-ok"],["variant","primary",1,"run-btn",3,"click"],["aria-hidden","true",1,"inline-wrap__state"],["aria-hidden","true",1,"suggest__skeleton",3,"width"],["role","status",1,"suggest__loading"],["aria-hidden","true",1,"suggest__skeleton"],["type","button","role","option",1,"suggest__item"],["type","button","role","option",1,"suggest__item",3,"click"],[1,"suggest__label"],[1,"suggest__hint"],[1,"inline-wrap"],["aria-hidden","true",1,"inline-wrap__badge","inline-wrap__badge--ai"],["name","ng-brain","method","stroke","size","15"],["type","text","aria-label","Ask your data","placeholder","Ask your data \u2014 e.g. failed provisioning for Engineering last week",1,"inline-wrap__input",3,"ngModelChange","keydown","disabled","ngModel"],[1,"pop__head"],[1,"pop__title"],[1,"pop__sub"],[1,"builder"],["aria-label","Field","portal","","noWidthSync","","searchEnabled","","placeholder","Field",1,"builder__select",3,"nile-change","value"],[3,"value"],["aria-label","Operator","portal","","placeholder","Operator",1,"builder__select",3,"nile-change","value"],["role","status","aria-label","Loading values",1,"builder__skeleton"],["aria-label","Value","portal","","noWidthSync","","searchEnabled","","placeholder","Value",1,"builder__select",3,"value"],["aria-label","Value","placeholder","Value",1,"builder__input",3,"value"],[1,"join-row"],[1,"pop__footer"],["variant","secondary",1,"btn-ghost",3,"click"],["variant","primary",1,"btn-primary",3,"click"],[1,"builder__skeleton-bar"],["aria-label","Value","portal","","noWidthSync","","searchEnabled","","placeholder","Value",1,"builder__select",3,"nile-change","value"],["aria-label","Value","placeholder","Value",1,"builder__input",3,"nile-change","value"],[1,"join-row__label"],[1,"join-toggle"],["type","button",3,"click"]],template:function(t,M){if(t&1&&(q(0,"div",1)(1,"div",2)(2,"nile-dropdown",3,0)(4,"button",4),It(5,"nile-glyph",5),q(6,"span",6),v(7),Me(),q(8,"span",7),v(9,"\u25BE"),Me()(),q(10,"div",8)(11,"span",9),v(12,"Filter with"),Me(),xt(13,vUt,9,7,"button",10,kUt),Me()()(),q(15,"div",11),xe(16,_Ut,6,1,"div",12)(17,$Ut,12,9)(18,XUt,6,3),Me(),q(19,"div",13),xe(20,qUt,2,2,"span",14),q(21,"nile-button",15),Fe("click",function(){return M.onClearAll()}),v(22,"Clear all"),Me()(),xe(23,ovt,22,5,"div",16),Me()),t&2){let n;m(4),Lt("disabled",M.busy()),m(),Lt("name",M.activeMode().icon),m(2),it(M.activeMode().label),m(6),pt(M.modes),m(3),pe((n=M.mode())==="manual"?16:n==="expression"?17:n==="prompt"?18:-1),m(4),pe(M.mode()==="manual"&&M.chipCount()>0?20:-1),m(),mt("disabled",M.busy()||!M.canClear()?"":null),m(2),pe(M.condPopOpen()?23:-1)}},dependencies:[Pa,Oj,bh,k2,Im],styles:['@charset "UTF-8";.rail[_ngcontent-%COMP%]{position:relative;z-index:var(--z-sticky);display:flex;align-items:center;gap:10px;margin:0;padding:12px 20px;background:var(--ng-colors-bg-primary, #fff);border-bottom:1px solid var(--ng-colors-border-secondary, #e9edf3);border-radius:0;font-size:13px}.rail__mode[_ngcontent-%COMP%]{position:relative;flex:none;height:34px;padding-right:10px;border-right:1px solid var(--ng-colors-border-secondary, #e9edf3)}.mode-btn[_ngcontent-%COMP%]{display:flex;align-items:center;gap:7px;height:34px;padding:0 11px;border:1px solid #dbe3ee;border-radius:7px;background:var(--ng-colors-bg-primary, #fff);font:inherit;font-size:13px;font-weight:600;color:#28374a;white-space:nowrap;cursor:pointer}.mode-btn[_ngcontent-%COMP%]:hover:not(:disabled){border-color:#b9cbe6;background:#f8fafc}.mode-btn[_ngcontent-%COMP%]:disabled{cursor:not-allowed;opacity:.6}.mode-btn__ico[_ngcontent-%COMP%]{flex:none;display:inline-flex;color:var(--ng-colors-fg-brand-primary-600, #1d4ed8)}.mode-btn__caret[_ngcontent-%COMP%]{font-size:9px;color:#9aa6b6}.mode-dropdown[_ngcontent-%COMP%]::part(panel){background:transparent;box-shadow:none;border-radius:0}.mode-menu[_ngcontent-%COMP%]{width:286px;display:flex;flex-direction:column;gap:2px;padding:6px;background:var(--ng-colors-bg-primary, #fff);border:1px solid #dfe6ef;border-radius:11px;box-shadow:0 18px 40px -12px #0f172a47}.mode-menu__heading[_ngcontent-%COMP%]{padding:6px 8px 4px;font-size:10.5px;font-weight:700;letter-spacing:.07em;text-transform:uppercase;color:#a3aebd}.mode-item[_ngcontent-%COMP%]{display:flex;align-items:flex-start;gap:9px;width:100%;padding:8px 9px;border:0;border-radius:8px;background:transparent;font:inherit;text-align:left;cursor:pointer}.mode-item[_ngcontent-%COMP%]:hover{background:#f4f7fb}.mode-item.is-active[_ngcontent-%COMP%]{background:#f2f6fd}.mode-item__ico[_ngcontent-%COMP%]{flex:none;width:20px;margin-top:1px;display:inline-flex;justify-content:center;color:#28374a}.mode-item__text[_ngcontent-%COMP%]{display:flex;flex-direction:column;gap:1px;min-width:0}.mode-item__label[_ngcontent-%COMP%]{font-size:13px;font-weight:650;color:#28374a}.mode-item__desc[_ngcontent-%COMP%]{font-size:11.5px;line-height:1.35;color:#94a3b8}.mode-item__check[_ngcontent-%COMP%]{flex:none;margin-left:auto;padding-left:8px;font-size:11px;color:var(--ng-colors-fg-brand-primary-600, #1d4ed8)}.mode-item.is-active[_ngcontent-%COMP%] .mode-item__ico[_ngcontent-%COMP%], .mode-item.is-active[_ngcontent-%COMP%] .mode-item__label[_ngcontent-%COMP%]{color:var(--ng-colors-fg-brand-primary-600, #1d4ed8)}.rail__panel[_ngcontent-%COMP%]{flex:1;min-width:0;display:flex;align-items:center;gap:6px;flex-wrap:nowrap}.rail__chips[_ngcontent-%COMP%]{flex:1;min-width:0;display:flex;align-items:center;gap:6px;flex-wrap:nowrap;overflow-x:auto;overflow-y:hidden;scrollbar-width:thin;scrollbar-color:#c9d4e4 transparent;overscroll-behavior-x:contain}.rail__chips[_ngcontent-%COMP%]::-webkit-scrollbar{height:6px}.rail__chips[_ngcontent-%COMP%]::-webkit-scrollbar-track{background:transparent}.rail__chips[_ngcontent-%COMP%]::-webkit-scrollbar-thumb{background:#c9d4e4;border-radius:3px}.rail__chips[_ngcontent-%COMP%] > .chip[_ngcontent-%COMP%], .rail__chips[_ngcontent-%COMP%] > .join-badge[_ngcontent-%COMP%], .rail__chips[_ngcontent-%COMP%] > .add-filter[_ngcontent-%COMP%]{flex:0 0 auto}.chip[_ngcontent-%COMP%]{display:flex;align-items:stretch;height:34px;max-width:340px;border:1px solid #d8e2f0;border-radius:7px;background:var(--ng-colors-bg-primary, #fff);overflow:hidden}.chip__f[_ngcontent-%COMP%]{display:flex;align-items:center;padding:0 8px;background:#f6f9fe;color:#5b6a7d;white-space:nowrap}.chip__op[_ngcontent-%COMP%]{display:flex;align-items:center;padding:0 6px;font-size:12px;color:#9aa6b6;white-space:nowrap}.chip__val[_ngcontent-%COMP%]{display:flex;align-items:center;padding:0 6px 0 0;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:600;color:#0f172a}.chip__x[_ngcontent-%COMP%]{flex:none;width:24px;border:0;border-left:1px solid #eef2f8;background:var(--ng-colors-bg-primary, #fff);font-size:12px;color:#9aa6b6;cursor:pointer}.chip__x[_ngcontent-%COMP%]:hover:not(:disabled){background:var(--ng-color-error-50, #fef2f2);color:var(--ng-colors-fg-error-primary, #dc2626)}.chip__x[_ngcontent-%COMP%]:disabled{cursor:not-allowed}.join-badge[_ngcontent-%COMP%]{padding:2px 6px;border:1px solid #e5ebf3;border-radius:5px;background:var(--ng-colors-bg-primary, #fff);font:inherit;font-size:10.5px;font-weight:800;letter-spacing:.06em;color:#7c8797;cursor:pointer}.join-badge[_ngcontent-%COMP%]:hover:not(:disabled){border-color:#bfd3fb;color:var(--ng-colors-fg-brand-primary-600, #1d4ed8)}.join-badge[_ngcontent-%COMP%]:disabled{cursor:not-allowed}.add-filter[_ngcontent-%COMP%]{display:inline-flex;flex:none;height:34px;border:1px dashed #b9cbe6;border-radius:7px;overflow:hidden}.add-filter__btn[_ngcontent-%COMP%]{--nile-height-40px: 34px;--nile-spacing-10px: 0;--nile-spacing-14px: 10px;--nile-radius-base-standard: 0;--nile-colors-dark-900: var(--ng-colors-fg-brand-primary-600, #1d4ed8)}.inline-wrap[_ngcontent-%COMP%]{flex:1 1 auto;min-width:300px;display:flex;align-items:stretch;height:34px;border:1px solid #dbe3ee;border-radius:7px;background:var(--ng-colors-bg-primary, #fff);overflow:hidden}.inline-wrap.is-error[_ngcontent-%COMP%]{border-color:#f3b4b4}.inline-wrap__badge[_ngcontent-%COMP%]{display:flex;align-items:center;justify-content:center;flex:none;width:30px;padding:0;border-radius:6px 0 0 6px}.inline-wrap__badge[_ngcontent-%COMP%] nile-glyph[_ngcontent-%COMP%]{flex:none;line-height:0}.inline-wrap__badge--fx[_ngcontent-%COMP%]{background:#f2f6fd;color:var(--ng-colors-fg-brand-primary-600, #1d4ed8)}.inline-wrap__badge--ai[_ngcontent-%COMP%]{background:#f7f4fe;color:#7c3aed}.inline-wrap__input[_ngcontent-%COMP%]{flex:1;min-width:0;border:0;padding:0 10px;background:transparent;font:inherit;font-size:13px;color:#0f172a}.inline-wrap__input[_ngcontent-%COMP%]:focus{outline:none}.inline-wrap__input[_ngcontent-%COMP%]::placeholder{color:#9aa6b6}.inline-wrap__state[_ngcontent-%COMP%]{display:grid;place-items:center;width:26px;font-size:11px;font-weight:800;color:var(--ng-color-success-700, #15803d)}.inline-wrap__state.is-warn[_ngcontent-%COMP%]{color:var(--ng-color-warning-700, #b45309)}.inline-wrap__state.is-error[_ngcontent-%COMP%]{color:var(--ng-color-error-700, #b91c1c)}.inline-status[_ngcontent-%COMP%]{flex:0 1 auto;min-width:0;font-size:11.5px;line-height:1.3}.inline-status[_ngcontent-%COMP%] .is-ok[_ngcontent-%COMP%]{color:var(--ng-color-success-700, #15803d)}.inline-status[_ngcontent-%COMP%] .is-warn[_ngcontent-%COMP%]{color:var(--ng-color-warning-700, #b45309)}.inline-status[_ngcontent-%COMP%] .is-error[_ngcontent-%COMP%]{color:var(--ng-color-error-700, #b91c1c)}.inline-status[_ngcontent-%COMP%] code[_ngcontent-%COMP%]{padding:0 3px;border-radius:3px;background:#f1f5f9;font-family:ui-monospace,SFMono-Regular,Menlo,monospace}.run-btn[_ngcontent-%COMP%]{flex:none;--nile-height-40px: 34px;--nile-spacing-10px: 0;--nile-spacing-14px: 16px}.rail__right[_ngcontent-%COMP%]{flex:none;display:flex;align-items:center;gap:12px;height:34px}.match-label[_ngcontent-%COMP%]{font-size:12px;color:#94a3b8;font-variant-numeric:tabular-nums;white-space:nowrap}.clear-all[_ngcontent-%COMP%]{--nile-height-40px: 34px;--nile-spacing-10px: 0;--nile-spacing-14px: 10px}.pop[_ngcontent-%COMP%]{position:absolute;top:calc(100% - 2px);left:20px;z-index:50;width:560px;max-height:calc(100vh - 190px);display:flex;flex-direction:column;gap:12px;padding:14px;background:var(--ng-colors-bg-primary, #fff);border:1px solid #dfe6ef;border-radius:12px;box-shadow:0 20px 44px -14px #0f172a4d;overflow-y:auto}.pop__head[_ngcontent-%COMP%]{display:flex;align-items:center;justify-content:space-between;gap:8px}.pop__title[_ngcontent-%COMP%]{font-size:13px;font-weight:700;color:#0f172a}.pop__sub[_ngcontent-%COMP%]{font-size:11.5px;color:#a3aebd}.builder[_ngcontent-%COMP%]{display:grid;grid-template-columns:1.25fr .7fr 1.15fr;gap:8px;align-items:start}.builder__select[_ngcontent-%COMP%], .builder__input[_ngcontent-%COMP%]{display:block;min-width:0;width:100%}.join-row[_ngcontent-%COMP%]{display:flex;align-items:center;gap:8px}.join-row__label[_ngcontent-%COMP%]{font-size:12px;color:#94a3b8}.join-toggle[_ngcontent-%COMP%]{display:flex;align-items:center;gap:2px;padding:2px;background:#f1f5f9;border-radius:7px}.join-toggle[_ngcontent-%COMP%] button[_ngcontent-%COMP%]{padding:3px 9px;border:0;border-radius:5px;background:transparent;font:inherit;font-size:12px;font-weight:700;color:#64748b;cursor:pointer}.join-toggle[_ngcontent-%COMP%] button.is-active[_ngcontent-%COMP%]{background:var(--ng-colors-bg-primary, #fff);color:var(--ng-colors-fg-brand-primary-600, #1d4ed8);box-shadow:0 1px 2px #0f172a1f}.pop__footer[_ngcontent-%COMP%]{position:sticky;bottom:-14px;display:flex;justify-content:flex-end;gap:8px;margin:0 -14px -14px;padding:10px 14px;background:var(--ng-colors-bg-primary, #fff);border-top:1px solid #f1f5f9}.btn-ghost[_ngcontent-%COMP%]{--nile-height-40px: 31px;--nile-spacing-10px: 0;--nile-spacing-14px: 11px}.btn-primary[_ngcontent-%COMP%]{--nile-height-40px: 31px;--nile-spacing-10px: 0;--nile-spacing-14px: 13px}.inline-wrap--suggest[_ngcontent-%COMP%]{position:relative;overflow:visible}.suggest[_ngcontent-%COMP%]{position:absolute;top:calc(100% + 4px);left:0;z-index:70;min-width:260px;max-height:240px;display:flex;flex-direction:column;padding:4px;background:var(--ng-colors-bg-primary, #fff);border:1px solid #dfe6ef;border-radius:9px;box-shadow:0 16px 36px -12px #0f172a47;overflow-y:auto}.suggest__item[_ngcontent-%COMP%]{display:flex;align-items:baseline;gap:8px;padding:6px 8px;border:0;border-radius:6px;background:transparent;font:inherit;text-align:left;cursor:pointer}.suggest__item[_ngcontent-%COMP%]:hover{background:#f4f7fb}.suggest__label[_ngcontent-%COMP%]{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px;color:#0f172a}.suggest__hint[_ngcontent-%COMP%]{margin-left:auto;font-size:11px;color:#94a3b8;white-space:nowrap}.builder__skeleton[_ngcontent-%COMP%]{display:block;width:100%;height:36px;padding:10px;border:1px solid #e6ebf2;border-radius:8px;background:var(--ng-colors-bg-primary, #fff);box-sizing:border-box}.builder__skeleton-bar[_ngcontent-%COMP%]{display:block;height:14px;border-radius:4px;background:linear-gradient(90deg,#eef2f7 25%,#e2e8f0 37%,#eef2f7 63%);background-size:400% 100%;animation:_ngcontent-%COMP%_builder-skeleton 1.3s ease-in-out infinite}@keyframes _ngcontent-%COMP%_builder-skeleton{0%{background-position:100% 50%}to{background-position:0 50%}}@media(prefers-reduced-motion:reduce){.builder__skeleton-bar[_ngcontent-%COMP%]{animation:none}}.suggest__skeleton[_ngcontent-%COMP%]{display:block;height:12px;margin:7px 8px;border-radius:4px;background:linear-gradient(90deg,#eef2f7 25%,#e2e8f0 37%,#eef2f7 63%);background-size:400% 100%;animation:_ngcontent-%COMP%_builder-skeleton 1.3s ease-in-out infinite}.suggest__loading[_ngcontent-%COMP%]{display:block;padding:2px 8px 6px;font-size:11px;color:#94a3b8}@media(prefers-reduced-motion:reduce){.suggest__skeleton[_ngcontent-%COMP%]{animation:none}}.suggest__hint.is-badge[_ngcontent-%COMP%]{padding:2px 6px;border-radius:999px;background:#f1f5f9;font-size:9.5px;font-weight:700;letter-spacing:.06em;color:#7c8797;text-transform:uppercase}'],changeDetection:0})};var gvt=new Set(["today","yesterday","last-7-days","last-30-days","this-month","last-month"]),yat=[{value:"today",label:"Today"},{value:"yesterday",label:"Yesterday"},{value:"last-7-days",label:"Last 7 days"},{value:"last-30-days",label:"Last 30 days"},{value:"this-month",label:"This month"},{value:"last-month",label:"Last month"}];function ZD(i){return i==="date"?[{value:"today",label:"Today",valueKind:"none"},{value:"yesterday",label:"Yesterday",valueKind:"none"},{value:"last-7-days",label:"Last 7 days",valueKind:"none"},{value:"last-30-days",label:"Last 30 days",valueKind:"none"},{value:"this-month",label:"This month",valueKind:"none"},{value:"last-month",label:"Last month",valueKind:"none"},{value:"is",label:"is on",valueKind:"date"},{value:"is-not",label:"is not on",valueKind:"date"},{value:"before",label:"is before",valueKind:"date"},{value:"after",label:"is after",valueKind:"date"},{value:"on-or-before",label:"is on or before",valueKind:"date"},{value:"on-or-after",label:"is on or after",valueKind:"date"},{value:"between",label:"is between",valueKind:"date",needsSecondValue:!0},{value:"is-empty",label:"is empty",valueKind:"none"},{value:"is-not-empty",label:"is not empty",valueKind:"none"}]:i==="number"?[{value:"is",label:"= (equals)",valueKind:"number"},{value:"is-not",label:"\u2260 (not equal to)",valueKind:"number"},{value:"gt",label:"> (greater than)",valueKind:"number"},{value:"lt",label:"< (less than)",valueKind:"number"},{value:"gte",label:"\u2265 (at least)",valueKind:"number"},{value:"lte",label:"\u2264 (at most)",valueKind:"number"},{value:"between",label:"is between",valueKind:"number",needsSecondValue:!0},{value:"is-empty",label:"is empty",valueKind:"none"},{value:"is-not-empty",label:"is not empty",valueKind:"none"}]:i==="boolean"?[{value:"is",label:"is",valueKind:"select"},{value:"is-not",label:"is not",valueKind:"select"},{value:"is-empty",label:"is empty",valueKind:"none"},{value:"is-not-empty",label:"is not empty",valueKind:"none"}]:[{value:"is",label:"is",valueKind:"select"},{value:"is-not",label:"is not",valueKind:"select"},{value:"contains",label:"contains",valueKind:"text"},{value:"not-contains",label:"does not contain",valueKind:"text"},{value:"starts-with",label:"starts with",valueKind:"text"},{value:"ends-with",label:"ends with",valueKind:"text"},{value:"is-any-of",label:"is any of",valueKind:"multi-select"},{value:"is-none-of",label:"is none of",valueKind:"multi-select"},{value:"is-empty",label:"is empty",valueKind:"none"},{value:"is-not-empty",label:"is not empty",valueKind:"none"}]}function r3(i){return i==="string"||i==="boolean"}function Sj(i){return String(i).padStart(2,"0")}function rB(i,e){let t=new Date(`${i}T00:00:00Z`);return t.setUTCDate(t.getUTCDate()+e),`${t.getUTCFullYear()}-${Sj(t.getUTCMonth()+1)}-${Sj(t.getUTCDate())}`}function Nvt(i,e){return new Date(Date.UTC(i,e+1,0)).getUTCDate()}function oB(i){let e=new Date,t=`${e.getUTCFullYear()}-${Sj(e.getUTCMonth()+1)}-${Sj(e.getUTCDate())}`;switch(i){case"yesterday":{let M=rB(t,-1);return{from:M,to:M}}case"last-7-days":return{from:rB(t,-6),to:t};case"last-30-days":return{from:rB(t,-29),to:t};case"this-month":return{from:`${e.getUTCFullYear()}-${Sj(e.getUTCMonth()+1)}-01`,to:t};case"last-month":{let M=e.getUTCMonth(),n=e.getUTCFullYear(),r=M===0?11:M-1,o=M===0?n-1:n;return{from:`${o}-${Sj(r+1)}-01`,to:`${o}-${Sj(r+1)}-${Sj(Nvt(o,r))}`}}default:return{from:t,to:t}}}var uvt={is:"equals","is-not":"not_equals",contains:"contains","not-contains":"not_contains","starts-with":"starts_with","ends-with":"ends_with",gt:"gt",lt:"lt",gte:"gte",lte:"lte",before:"lt",after:"gt","on-or-before":"lte","on-or-after":"gte","is-empty":"not_exists","is-not-empty":"exists"};function Cm(i){if(gvt.has(i.operator)){let{from:e,to:t}=oB(i.operator);return{field:i.fieldId,operation:"between",value:[e,t]}}return i.operator==="between"?{field:i.fieldId,operation:"between",value:[i.value??"",i.value2??""]}:i.operator==="is-any-of"?{field:i.fieldId,operation:"in",value:i.values??[]}:i.operator==="is-none-of"?{field:i.fieldId,operation:"not_in",value:i.values??[]}:{field:i.fieldId,operation:uvt[i.operator]??"equals",value:i.value??""}}function o3(i,e,t){let M=ZD(t).find(r=>r.value===i.operator),n=M?.label??i.operator;return M?.valueKind==="none"?`${e} ${n}`:M?.valueKind==="multi-select"?`${e} ${n} ${(i.values??[]).join(", ")}`:i.operator==="between"?`${e} ${n} ${i.value} and ${i.value2??""}`:`${e} ${n} ${i.value}`}var Dvt={number:"ng-number",bar:"ng-chart-bar",column:"ng-chart-column",line:"ng-chart-line",area:"ng-chart-area",spline:"ng-chart-spline",stacked:"ng-chart-bar-stacked",cluster:"ng-chart-bar-big",pie:"ng-chart-pie",donut:"ng-donut",funnel:"ng-funnel",scatter:"ng-chart-scatter",bubble:"bubble-chart",radar:"radar",histogram:"ng-chart-bar-increasing",table:"ng-table",grid:"ng-table"};function a3(i){return Dvt[i]??"ng-chart-bar"}function Tat(i,e=!1){let t=[],M=e,n=()=>{let r=M;return M=!1,r||void 0};return i.canChangeChartType&&t.push({type:"custom",label:"Change chart type",id:"changeChartType",glyph:"ng-chart-bar",divider:n()}),i.canManageFilters&&t.push({type:"custom",label:"Manage filters",id:"manageFilters",glyph:"ng-filter-lines",divider:n()}),i.canCustomizeColors&&t.push({type:"custom",label:"Customize colors",id:"customizeColors",glyph:"ng-palette",divider:n()}),i.canSetAlert&&t.push({type:"custom",label:"Set Alert",id:"setAlert",glyph:"ng-bell-01",divider:n()}),(i.canForecast||i.hasForecast)&&t.push({type:"custom",label:i.hasForecast?"Remove forecast":"Forecast",id:"forecast",glyph:i.hasForecast?"ng-trending-down":"ng-trend-up-01",divider:n()}),i.isKpi||(t.push({type:"default",label:"Export PNG",downloadPng:!0,glyph:"ng-image-03",divider:t.length>0}),t.push({type:"default",label:"Export CSV",downloadCsv:!0,glyph:"ng-file-06"}),t.push({type:"default",label:"Print",print:!0,glyph:"ng-printer"})),t}function aB(i,e,t){let M=i.filter(e).map(a=>_(x({},a),{divider:!1})),n=i.filter(t).map(a=>_(x({},a),{divider:!1})),r=i.filter(a=>!e(a)&&!t(a));if(!M.length&&!n.length)return i;let o=[...M,...r,...n];return M.length&&r.length&&(o[M.length]=_(x({},o[M.length]),{divider:!0})),r.length&&n.length&&(o[M.length+r.length]=_(x({},o[M.length+r.length]),{divider:!0})),o}function s3(i){return aB(i,e=>e.type==="custom"&&(e.id==="viewChart"||e.id==="viewRecords"),e=>e.type==="custom"&&e.id==="setAlert"||e.type==="default"&&e.downloadCsv===!0)}var Aat=["#3C67DE","#12B76A","#F79009","#F04438","#7A5AF8","#0BA5EC","#EE46BC","#EAAA08","#155EEF","#17B26A"];function sB(i){let e=i?.data;return Array.isArray(e)&&e.length>0&&e.every(t=>t&&typeof t=="object"&&Array.isArray(t.data))}function zat(i){let e=i?.chart;return sB(e)?e.data.map((t,M)=>({index:M,name:typeof t.name=="string"&&t.name?t.name:`Series ${M+1}`,color:typeof t.color=="string"?t.color:Aat[M%Aat.length]})):null}function hat(i){return sB(i?.chart)}function xat(i,e,t){let M=i?.chart;return!sB(M)||!M.data[e]?i:_(x({},i),{chart:_(x({},M),{data:M.data.map((r,o)=>o===e?_(x({},r),{color:t}):r)})})}var cvt=new Set(["script","script_fields","scripted_metric","scripted_upsert","delete_by_query","update_by_query","reindex","update","delete","index","indices","_delete_by_query"]);function l3(i){if(i===null||typeof i!="object")return null;if(Array.isArray(i)){for(let e of i){let t=l3(e);if(t)return t}return null}for(let[e,t]of Object.entries(i)){if(cvt.has(e))return e;let M=l3(t);if(M)return M}return null}function Ivt(i){let e=i.replace(/;\s*$/,"");return e.includes(";")?{ok:!1,error:"Only a single statement is allowed"}:/^(select|with)\b/i.test(e)?/\b(insert|update|delete|drop|alter|truncate|merge|create|exec|execute|grant|revoke|into)\b/i.test(e)?{ok:!1,error:"This statement isn't read-only \u2014 the DSL editor accepts SELECT/WITH queries only"}:/\b(sp_|xp_)\w*/i.test(e)?{ok:!1,error:"Stored/extended procedures aren't allowed"}:{ok:!0,error:null}:{ok:!1,error:"Only a read-only SELECT/WITH statement is allowed"}}function wj(i,e="json"){let t=(i??"").trim();if(!t)return{ok:!1,error:"Query is empty"};if(e==="sql")return Ivt(t);let M;try{M=JSON.parse(t)}catch(r){return{ok:!1,error:`Not valid JSON: ${r instanceof Error?r.message:String(r)}`}}if(M===null||typeof M!="object"||Array.isArray(M))return{ok:!1,error:"The DSL body must be a JSON object"};let n=l3(M);return n?{ok:!1,error:`"${n}" is not allowed \u2014 the DSL editor accepts read-only search/aggregation queries only`}:{ok:!0,error:null}}function km(i,e="json"){if(e==="sql")return i;try{return JSON.stringify(JSON.parse(i),null,2)}catch{return null}}var pat=800;function lB(i,e){let t=(i??"").split(`
|
|
40485
40485
|
`),M=(e??"").split(`
|
|
40486
40486
|
`);if(t.length>pat||M.length>pat)return[...t.map(l=>({kind:"remove",text:l})),...M.map(l=>({kind:"add",text:l}))];let n=M.length+1,r=new Int32Array((t.length+1)*n);for(let l=t.length-1;l>=0;l--)for(let N=M.length-1;N>=0;N--)r[l*n+N]=t[l]===M[N]?r[(l+1)*n+(N+1)]+1:Math.max(r[(l+1)*n+N],r[l*n+(N+1)]);let o=[],a=0,s=0;for(;a<t.length&&s<M.length;)t[a]===M[s]?(o.push({kind:"context",text:t[a]}),a++,s++):r[(a+1)*n+s]>=r[a*n+(s+1)]?(o.push({kind:"remove",text:t[a]}),a++):(o.push({kind:"add",text:M[s]}),s++);for(;a<t.length;)o.push({kind:"remove",text:t[a++]});for(;s<M.length;)o.push({kind:"add",text:M[s++]});return o}function gB(i){return i.filter(e=>e.kind!=="context")}var dvt="wf.pendingStoryScene";function NB(i){try{sessionStorage.setItem(dvt,JSON.stringify(i))}catch{}}function jvt(i){return/\bWHERE\b([\s\S]*?)(?:\bGROUP BY\b|\bORDER BY\b|\bLIMIT\b|$)/i.exec(i)?.[1]?.trim().replace(/\s+/g," ")||null}function yvt(i){let e=i?.query?.bool,t=[...e?.filter??[],...e?.must??[]],M=[];for(let n of t){let r=n;if(r.term)for(let[o,a]of Object.entries(r.term))M.push(`${o.replace(/\.keyword$/,"")} = ${String(a)}`);else if(r.terms)for(let[o,a]of Object.entries(r.terms))M.push(`${o.replace(/\.keyword$/,"")} in [${a.join(", ")}]`);else if(r.range)for(let[o,a]of Object.entries(r.range)){let s=Object.entries(a).map(([l,N])=>`${l} ${N}`).join(" ");M.push(`${o} ${s}`)}else if(r.match)for(let[o,a]of Object.entries(r.match))M.push(`${o} ~ "${String(a)}"`)}return M.length?M.join(" AND "):null}function g3(i){let e=[],t=i.config?.aq,M=t?.summary??t?.chartSubtitle;M&&e.push({label:"Summary",text:M}),i.edited===!1?e.push({label:"Filter",text:wm(i)}):i.edited===!0&&e.push({label:"Filter",text:"Reflects the active dashboard filter"});let n=i.queryMeta,r=n?.sql?jvt(n.sql):n?.dsl?yvt(n.dsl):null;return r&&e.push({label:"Filters applied",text:r}),e}function N3(i){if(!i)return{columns:[],rows:[]};let e=i.data,t=i.value;if(t!=null&&!Array.isArray(e)){let M=i.label||"value";return{columns:[M],rows:[{[M]:t}]}}if(Array.isArray(e)&&e.length){let M=e[0],n=M?.data;if(Array.isArray(n)&&!Array.isArray(n[0])&&typeof n[0]!="object"){let r=e,a=(i.categories??n.map((s,l)=>l+1)).map((s,l)=>{let N={category:s};for(let D of r)N[D.name??"value"]=D.data?.[l]??null;return N});return{columns:["category",...r.map(s=>s.name??"value")],rows:a}}if(Array.isArray(n)&&Array.isArray(n[0]))return{columns:["x","y"],rows:n.map(([o,a])=>({x:o,y:a}))};if(M&&typeof M=="object"&&"y"in M)return{columns:["name","value"],rows:e.map(o=>({name:o.name,value:o.y}))};if(typeof M=="number")return{columns:["value"],rows:e.map(r=>({value:r}))};if(M&&typeof M=="object")return{columns:Object.keys(M),rows:e}}return{columns:[],rows:[]}}function Lat(i,e){return async(t,M,n,r)=>{let o=await i(t,M,n,r),a=e.match(M,n);if(!a.length)return o;let s=new Set(a.map(I=>String(I))),l=o.values.map(I=>s.has(String(I.value))?_(x({},I),{observed:!0}):I),N=new Set(o.values.map(I=>String(I.value))),c=[...a.filter(I=>!N.has(String(I))).map(I=>({value:I,label:String(I),observed:!0})),...l.filter(I=>I.observed),...l.filter(I=>!I.observed)];return _(x({},o),{values:c})}}var u3=(i,e)=>e.id,Tvt=(i,e)=>e.key,mat=(i,e)=>e.component,Avt=(i,e)=>e.index,Cj=(i,e)=>e.value,Eat=(i,e)=>e.name,zvt=(i,e)=>e.drillDownName,hvt=(i,e)=>e.label;function xvt(i,e){if(i&1){let t=Ee();q(0,"shared-filter-rail",42),Fe("modeChange",function(n){R(t);let r=p();return V(r.onRailModeChange(n))})("conditionsChange",function(n){R(t);let r=p();return V(r.onRailConditions(n))})("expressionRun",function(n){R(t);let r=p();return V(r.onRailExpressionRun(n))})("promptAsk",function(n){R(t);let r=p();return V(r.onRailPromptAsk(n))})("clearAll",function(){R(t);let n=p();return V(n.onRailClearAll())}),Me()}if(i&2){let t=p();Lt("mode",t.railMode())("conditions",t.railConditions())("catalog",t.railCatalog())("expression",t.railExpression())("busy",t.widgetsLoading)("valueFetcher",t.valueFetcher())}}function pvt(i,e){if(i&1&&(q(0,"div",3),It(1,"nile-glyph",43),q(2,"span",44),v(3),Me()()),i&2){let t=p();m(3),it(t.filterExplanation)}}function Lvt(i,e){i&1&&(q(0,"div",46),It(1,"nile-skeleton-loader",49)(2,"nile-skeleton-loader",50)(3,"nile-skeleton-loader",51),Me())}function Ovt(i,e){if(i&1&&It(0,"nile-skeleton-loader",58),i&2){let t=e.$implicit;dM("height",t,"%")}}function mvt(i,e){if(i&1&&(q(0,"div",48),It(1,"nile-skeleton-loader",52)(2,"nile-skeleton-loader",53),q(3,"div",54),xt(4,Ovt,1,2,"nile-skeleton-loader",55,Yr),Me(),q(6,"div",56),It(7,"nile-skeleton-loader",57)(8,"nile-skeleton-loader",57),Me()()),i&2){let t=p(2);m(4),pt(t.skeletonBars)}}function Evt(i,e){if(i&1&&(q(0,"div",4)(1,"div",45),xt(2,Lvt,4,0,"div",46,Yr),Me(),q(4,"div",47),xt(5,mvt,9,0,"div",48,Yr),Me()()),i&2){let t=p();m(2),pt(t.skeletonKpis),m(3),pt(t.skeletonCharts)}}function fvt(i,e){i&1&&(q(0,"p"),v(1,"Tap the canvas above to generate charts, KPIs, and tables \u2014 or pick from the library."),Me())}function Svt(i,e){if(i&1){let t=Ee();q(0,"nile-button",93),Fe("click",function(){R(t);let n=p(2);return V(n.openAiBuilder.emit())}),It(1,"nile-glyph",94),v(2," Add widget "),Me()}}function wvt(i,e){if(i&1){let t=Ee();q(0,"div",59)(1,"div",60),Fe("click",function(){R(t);let n=p();return V(n.editMode&&n.openAiBuilder.emit())})("keydown.enter",function(){R(t);let n=p();return V(n.editMode&&n.openAiBuilder.emit())})("keydown.space",function(n){R(t);let r=p();return r.editMode&&r.openAiBuilder.emit(),V(r.editMode&&n.preventDefault())}),KH(),q(2,"svg",61),It(3,"rect",62)(4,"rect",63)(5,"rect",64),q(6,"rect",65),It(7,"animate",66)(8,"animate",67),Me(),q(9,"rect",68),It(10,"animate",69)(11,"animate",70),Me(),q(12,"rect",71),It(13,"animate",72)(14,"animate",73),Me(),q(15,"rect",74),It(16,"animate",75)(17,"animate",76),Me(),q(18,"rect",77),It(19,"animate",78)(20,"animate",79),Me(),It(21,"rect",80)(22,"rect",81)(23,"circle",82),q(24,"circle",83),It(25,"animate",84),Me(),It(26,"rect",85)(27,"rect",86),q(28,"path",87),It(29,"animate",88),Me(),q(30,"circle",89),It(31,"animate",90),Me()()(),eJ(),q(32,"h3"),v(33,"Add widgets to build your dashboard"),Me(),e5(34,fvt,2,0,"p",91)(35,Svt,3,0,"nile-button",92),Me()}if(i&2){let t=p();m(),mt("role",t.editMode?"button":null)("tabindex",t.editMode?0:null),m(33),Lt("ngIf",t.editMode),m(),Lt("ngIf",!t.editMode)}}function Cvt(i,e){if(i&1&&(q(0,"div",99)(1,"span",107)(2,"nile-lite-tooltip",108),It(3,"nile-glyph",109),Me(),q(4,"span",110),v(5),Me()()()),i&2){let t=p().$implicit,M=p(2);m(),mt("aria-label",M.reasonText(t)),m(),Lt("content",M.reasonText(t)),m(3),it(M.reasonText(t))}}function kvt(i,e){i&1&&It(0,"div",114)}function bvt(i,e){i&1&&(q(0,"nile-menu-item",122),v(1,"Loading stories\u2026"),Me())}function Qvt(i,e){if(i&1){let t=Ee();q(0,"nile-menu-item",125),Fe("click",function(){let n=R(t).$implicit;p(4);let r=GA(1),o=p(3);return o.chooseStory(n.id),V(o.closeWidgetMenu(r))}),v(1),Me()}if(i&2){let t=e.$implicit;m(),hi(" ",t.title||"Untitled story"," ")}}function Uvt(i,e){if(i&1){let t=Ee();xt(0,Qvt,2,1,"nile-menu-item",null,u3),q(2,"nile-menu-item",123),Fe("click",function(){R(t),p(3);let n=GA(1),r=p(3);return r.chooseStory(null),V(r.closeWidgetMenu(n))}),It(3,"nile-glyph",124),v(4," Add as new story "),Me()}if(i&2){let t=p(6);pt(t.storyOptions)}}function vvt(i,e){if(i&1){let t=Ee();q(0,"nile-menu-item",116),Fe("click",function(){R(t);let n=p(3).$implicit,r=p(2);return V(r.loadStoriesFor(n.id))}),q(1,"nile-dropdown",117)(2,"span",118),It(3,"nile-glyph",119),v(4),It(5,"nile-glyph",120),Me(),q(6,"nile-menu",121),xe(7,bvt,2,0,"nile-menu-item",122)(8,Uvt,5,0),Me()()()}if(i&2){let t=p().$implicit,M=p(4);m(3),Lt("name",t.glyph),m(),hi(" ",t.label," "),m(3),pe(M.storyLoading?7:8)}}function Yvt(i,e){if(i&1&&It(0,"nile-glyph",128),i&2){let t=p(2).$implicit;dM("color",t.color),Lt("name",t.glyph)("method",t.method||"stroke")}}function Zvt(i,e){if(i&1){let t=Ee();q(0,"nile-menu-item",116),Fe("click",function(){R(t);let n=p().$implicit;p();let r=GA(1),o=p().$implicit,a=p(2);return V(a.onOwnMenuItem(o,n,r))}),q(1,"span",126),xe(2,Yvt,1,4,"nile-glyph",127),v(3),Me()()}if(i&2){let t=p().$implicit;m(2),pe(t.glyph?2:-1),m(),hi(" ",t.label," ")}}function _vt(i,e){if(i&1&&(xe(0,kvt,1,0,"div",114),xe(1,vvt,9,3,"nile-menu-item",115)(2,Zvt,4,2,"nile-menu-item",115)),i&2){let t=e.$implicit;pe(t.divider?0:-1),m(),pe(t.key==="addToStory"?1:2)}}function Wvt(i,e){if(i&1){let t=Ee();q(0,"nile-dropdown",111,0),Fe("nile-show",function(){R(t);let n=p().$implicit,r=p(2);return V(r.menuOpenWidgetId=n.id)})("nile-hide",function(){R(t);let n=p().$implicit,r=p(2);return V(r.menuOpenWidgetId===n.id&&(r.menuOpenWidgetId=null))}),q(2,"button",112),It(3,"nile-glyph",113),Me(),q(4,"nile-menu"),xt(5,_vt,3,2,null,null,Tvt),Me()()}if(i&2){let t=p().$implicit,M=p(2);m(5),pt(M.menuItemsFor(t))}}function Pvt(i,e){i&1&&(q(0,"div",103),It(1,"nile-glyph",129),Me())}function Rvt(i,e){if(i&1){let t=Ee();q(0,"div",104)(1,"nile-checkbox",130),Fe("nile-change",function(n){R(t);let r=p().$implicit,o=p(2);return V(o.toggleSelection(r.id,n.detail.checked))}),Me()()}if(i&2){let t=p().$implicit,M=p(2);m(),mt("checked",M.isSelected(t.id)?"":null)}}function Vvt(i,e){i&1&&(q(0,"div",135),It(1,"nile-spinner",138),q(2,"span"),v(3,"Loading chart types\u2026"),Me()())}function Bvt(i,e){i&1&&(q(0,"p",136),v(1,"No other chart types fit this widget's data."),Me())}function Fvt(i,e){i&1&&It(0,"nile-spinner",138)}function Hvt(i,e){if(i&1&&It(0,"nile-glyph",143),i&2){let t=p().$implicit,M=p(6);Lt("name",M.chartTypeIcon(t.type))}}function Jvt(i,e){if(i&1){let t=Ee();q(0,"button",142),Fe("click",function(){let n=R(t).$implicit,r=p(6);return V(r.selectChartType(n.component))}),xe(1,Fvt,1,0,"nile-spinner",138)(2,Hvt,1,1,"nile-glyph",143),q(3,"span"),v(4),Me()()}if(i&2){let t=e.$implicit,M=p(6);mt("disabled",M.chartTypeApplying?"":null),m(),pe(M.chartTypeApplyingComponent===t.component?1:2),m(3),it(t.label)}}function Gvt(i,e){if(i&1&&(q(0,"p",139),v(1,"Recommended"),Me(),q(2,"div",140),xt(3,Jvt,5,3,"button",141,mat),Me()),i&2){let t=p(5);m(3),pt(t.sensibleChartTypes())}}function $vt(i,e){i&1&&It(0,"nile-spinner",138)}function Xvt(i,e){if(i&1&&It(0,"nile-glyph",143),i&2){let t=p().$implicit,M=p(6);Lt("name",M.chartTypeIcon(t.type))}}function qvt(i,e){if(i&1){let t=Ee();q(0,"button",145),Fe("click",function(){let n=R(t).$implicit,r=p(6);return V(r.selectChartType(n.component))}),xe(1,$vt,1,0,"nile-spinner",138)(2,Xvt,1,1,"nile-glyph",143),q(3,"span"),v(4),Me()()}if(i&2){let t=e.$implicit,M=p(6);mt("disabled",M.chartTypeApplying?"":null),m(),pe(M.chartTypeApplyingComponent===t.component?1:2),m(3),it(t.label)}}function Kvt(i,e){if(i&1&&(q(0,"p",139),v(1,"Other types"),Me(),q(2,"div",140),xt(3,qvt,5,3,"button",144,mat),Me()),i&2){let t=p(5);m(3),pt(t.otherChartTypes())}}function eYt(i,e){if(i&1&&(xe(0,Gvt,5,0),xe(1,Kvt,5,0)),i&2){let t=p(4);pe(t.sensibleChartTypes().length>0?0:-1),m(),pe(t.otherChartTypes().length>0?1:-1)}}function tYt(i,e){if(i&1&&(q(0,"p",137),v(1),Me()),i&2){let t=p(4);m(),it(t.chartTypeError)}}function iYt(i,e){if(i&1){let t=Ee();q(0,"nile-dropdown",131),Fe("nile-hide",function(){R(t);let n=p().$implicit,r=p(2);return V(r.chartTypePickerWidgetId===n.id&&r.closeChartTypePicker())}),q(1,"button",132),It(2,"nile-glyph",133),Me(),q(3,"div",134),xe(4,Vvt,4,0,"div",135)(5,Bvt,2,0,"p",136)(6,eYt,2,2),xe(7,tYt,2,1,"p",137),Me()()}if(i&2){let t=p().$implicit,M=p(2);Lt("open",M.chartTypePickerWidgetId===t.id),m(4),pe(M.chartTypeLoading?4:M.chartTypeOptions.length===0?5:6),m(3),pe(M.chartTypeError?7:-1)}}function MYt(i,e){if(i&1){let t=Ee();q(0,"label",148)(1,"span",149)(2,"input",150),Fe("change",function(n){let r=R(t).$implicit,o=p(4);return V(o.selectSeriesColor(r.index,n.target.value))}),Me()(),q(3,"span",151),v(4),Me()()}if(i&2){let t=e.$implicit;m(2),Lt("value",t.color),m(2),it(t.name)}}function nYt(i,e){if(i&1){let t=Ee();q(0,"nile-dropdown",131),Fe("nile-hide",function(){R(t);let n=p().$implicit,r=p(2);return V(r.colorPickerWidgetId===n.id&&r.closeColorPicker())}),q(1,"button",132),It(2,"nile-glyph",146),Me(),q(3,"div",147)(4,"p",139),v(5,"Series colors"),Me(),xt(6,MYt,5,2,"label",148,Avt),Me()()}if(i&2){let t=p().$implicit,M=p(2);Lt("open",M.colorPickerWidgetId===t.id),m(6),pt(M.colorPickerSeries())}}function rYt(i,e){if(i&1){let t=Ee();q(0,"span",157),v(1),q(2,"button",158),Fe("click",function(){let n=R(t).$implicit,r=p(6);return V(n.id&&r.removeFilterFromBuilder(n.id))}),It(3,"nile-glyph",159),Me()()}if(i&2){let t=e.$implicit,M=p(6);m(),AJ(" ",t.field," ",t.operation," ",t.value," "),m(),mt("disabled",M.filterBuilderRemovingId?"":null)}}function oYt(i,e){if(i&1&&(q(0,"div",154),xt(1,rYt,4,4,"span",157,u3),Me()),i&2){let t=p(5);m(),pt(t.filterBuilderActiveFilters())}}function aYt(i,e){if(i&1){let t=Ee();q(0,"button",161),Fe("click",function(){let n=R(t).$implicit,r=p(4).$implicit,o=p(2);return V(o.applyQuickTimeFilter(r,n.value))}),v(1),Me()}if(i&2){let t=e.$implicit,M=p(6);mt("disabled",M.filterBuilderApplying?"":null),m(),hi(" ",t.label," ")}}function sYt(i,e){if(i&1&&(q(0,"div",155),xt(1,aYt,2,2,"button",160,Cj),Me()),i&2){let t=p(5);m(),pt(t.quickTimePresets)}}function lYt(i,e){i&1&&(q(0,"div",135),It(1,"nile-spinner",138),q(2,"span"),v(3,"Loading filterable fields\u2026"),Me()())}function gYt(i,e){if(i&1&&(q(0,"p",137),v(1),Me()),i&2){let t=p(5);m(),it(t.ephemeralFilterFieldsError)}}function NYt(i,e){i&1&&(q(0,"p",136),v(1,"No filterable fields found for this widget's data."),Me())}function uYt(i,e){if(i&1&&(q(0,"option",163),v(1),Me()),i&2){let t=e.$implicit;Lt("value",t.name),m(),it(t.label)}}function DYt(i,e){if(i&1&&(q(0,"option",163),v(1),Me()),i&2){let t=e.$implicit;Lt("value",t.value),m(),it(t.label)}}function cYt(i,e){if(i&1){let t=Ee();q(0,"input",169),sl("ngModelChange",function(n){R(t);let r=p(7);return al(r.filterBuilderValue,n)||(r.filterBuilderValue=n),V(n)}),Fe("keydown.enter",function(){R(t);let n=p(7);return V(n.submitFilterBuilder())}),Me()}if(i&2){let t=p(7);ol("ngModel",t.filterBuilderValue)}}function IYt(i,e){if(i&1){let t=Ee();q(0,"span",171),v(1,"and"),Me(),q(2,"input",170),sl("ngModelChange",function(n){R(t);let r=p(8);return al(r.filterBuilderValue2,n)||(r.filterBuilderValue2=n),V(n)}),Me()}if(i&2){let t=p(8);m(2),ol("ngModel",t.filterBuilderValue2)}}function dYt(i,e){if(i&1){let t=Ee();q(0,"input",170),sl("ngModelChange",function(n){R(t);let r=p(7);return al(r.filterBuilderValue,n)||(r.filterBuilderValue=n),V(n)}),Me(),xe(1,IYt,3,1)}if(i&2){let t,M=p(7);ol("ngModel",M.filterBuilderValue),m(),pe((t=M.filterBuilderSelectedOperator())!=null&&t.needsSecondValue?1:-1)}}function jYt(i,e){if(i&1){let t=Ee();q(0,"span",171),v(1,"and"),Me(),q(2,"input",173),sl("ngModelChange",function(n){R(t);let r=p(8);return al(r.filterBuilderValue2,n)||(r.filterBuilderValue2=n),V(n)}),Me()}if(i&2){let t=p(8);m(2),ol("ngModel",t.filterBuilderValue2)}}function yYt(i,e){if(i&1){let t=Ee();q(0,"input",172),sl("ngModelChange",function(n){R(t);let r=p(7);return al(r.filterBuilderValue,n)||(r.filterBuilderValue=n),V(n)}),Fe("keydown.enter",function(){R(t);let n=p(7);return V(n.submitFilterBuilder())}),Me(),xe(1,jYt,3,1)}if(i&2){let t,M=p(7);ol("ngModel",M.filterBuilderValue),m(),pe((t=M.filterBuilderSelectedOperator())!=null&&t.needsSecondValue?1:-1)}}function TYt(i,e){if(i&1){let t=Ee();q(0,"label",174)(1,"input",175),Fe("change",function(){let n=R(t).$implicit,r=p(8);return V(r.toggleFilterBuilderMultiValue(n.value))}),Me(),q(2,"span"),v(3),Me()()}if(i&2){let t=e.$implicit,M=p(8);m(),Lt("checked",M.filterBuilderValues.includes(t.value)),m(2),Bo("",t.label,"",t.count!=null?" ("+t.count+")":"")}}function AYt(i,e){if(i&1&&(q(0,"div",167),xt(1,TYt,4,3,"label",174,Cj),Me()),i&2){let t=p(5).$implicit,M=p(2);m(),pt(M.filterValuesFor(t,M.filterBuilderField))}}function zYt(i,e){if(i&1&&(q(0,"option",163),v(1),Me()),i&2){let t=e.$implicit;Lt("value",t.value),m(),Bo("",t.label,"",t.count!=null?" ("+t.count+")":"")}}function hYt(i,e){if(i&1){let t=Ee();q(0,"select",162),sl("ngModelChange",function(n){R(t);let r=p(7);return al(r.filterBuilderValue,n)||(r.filterBuilderValue=n),V(n)}),q(1,"option",176),v(2,"Select\u2026"),Me(),xt(3,zYt,2,3,"option",163,Cj),Me()}if(i&2){let t=p(5).$implicit,M=p(2);ol("ngModel",M.filterBuilderValue),m(3),pt(M.filterValuesFor(t,M.filterBuilderField))}}function xYt(i,e){if(i&1&&xe(0,cYt,1,1,"input",166)(1,dYt,2,2)(2,yYt,2,2)(3,AYt,3,0,"div",167)(4,hYt,5,1,"select",168),i&2){let t,M=p(6);pe((t=(t=M.filterBuilderSelectedOperator())==null?null:t.valueKind)==="text"?0:t==="date"?1:t==="number"?2:t==="multi-select"?3:t==="select"?4:-1)}}function pYt(i,e){i&1&&(q(0,"div",165),It(1,"nile-spinner",177),q(2,"span"),v(3,"Loading values\u2026"),Me()())}function LYt(i,e){if(i&1){let t=Ee();q(0,"div",156)(1,"select",162),Fe("ngModelChange",function(n){R(t);let r=p(5);return V(r.onFilterBuilderFieldChange(n))}),xt(2,uYt,2,2,"option",163,Eat),Me(),q(4,"select",162),Fe("ngModelChange",function(n){R(t);let r=p(5);return V(r.onFilterBuilderOperatorChange(n))}),xt(5,DYt,2,2,"option",163,Cj),Me(),xe(7,xYt,5,1),q(8,"nile-button",164),Fe("click",function(){R(t);let n=p(5);return V(n.submitFilterBuilder())}),v(9," Add filter "),Me(),xe(10,pYt,4,0,"div",165),Me()}if(i&2){let t=p(5);m(),Lt("ngModel",t.filterBuilderField),m(),pt(t.filterBuilderFields()),m(2),Lt("ngModel",t.filterBuilderOperation),m(),pt(t.filterBuilderOperators()),m(2),pe(t.ephemeralFilterValuesLoading?-1:7),m(),mt("loading",t.filterBuilderApplying?"":null)("disabled",t.filterBuilderApplying||t.ephemeralFilterValuesLoading?"":null),m(2),pe(t.ephemeralFilterValuesLoading?10:-1)}}function OYt(i,e){if(i&1&&(q(0,"p",137),v(1),Me()),i&2){let t=p(5);m(),it(t.filterBuilderError)}}function mYt(i,e){if(i&1&&(xe(0,oYt,3,0,"div",154),xe(1,sYt,3,0,"div",155),xe(2,lYt,4,0,"div",135)(3,gYt,2,1,"p",137)(4,NYt,2,0,"p",136)(5,LYt,11,6,"div",156),xe(6,OYt,2,1,"p",137)),i&2){let t=p(2).$implicit,M=p(2);pe(M.filterBuilderActiveFilters().length>0?0:-1),m(),pe(M.timeWindowField(t)?1:-1),m(),pe(M.ephemeralFilterFieldsLoading?2:M.ephemeralFilterFieldsError?3:M.filterBuilderFields().length===0?4:5),m(4),pe(M.filterBuilderError?6:-1)}}function EYt(i,e){if(i&1){let t=Ee();q(0,"span",157),v(1),q(2,"button",158),Fe("click",function(){let n=R(t).$implicit,r=p(6);return V(r.removeEphemeralFilter(n.id))}),It(3,"nile-glyph",159),Me()()}if(i&2){let t=e.$implicit,M=p(6);m(),hi(" ",M.ephemeralFilterChipLabel(t)," "),m(),mt("disabled",M.ephemeralFilterApplying?"":null)}}function fYt(i,e){if(i&1&&(q(0,"div",154),xt(1,EYt,4,2,"span",157,u3),Me()),i&2){let t=p(5);m(),pt(t.ephemeralFilterActiveFilters())}}function SYt(i,e){if(i&1){let t=Ee();q(0,"button",161),Fe("click",function(){let n=R(t).$implicit,r=p(4).$implicit,o=p(2);return V(o.applyQuickTimeFilter(r,n.value))}),v(1),Me()}if(i&2){let t=e.$implicit,M=p(6);mt("disabled",M.ephemeralFilterApplying?"":null),m(),hi(" ",t.label," ")}}function wYt(i,e){if(i&1&&(q(0,"div",155),xt(1,SYt,2,2,"button",160,Cj),Me()),i&2){let t=p(5);m(),pt(t.quickTimePresets)}}function CYt(i,e){i&1&&(q(0,"div",135),It(1,"nile-spinner",138),q(2,"span"),v(3,"Loading filterable fields\u2026"),Me()())}function kYt(i,e){if(i&1&&(q(0,"p",137),v(1),Me()),i&2){let t=p(5);m(),it(t.ephemeralFilterFieldsError)}}function bYt(i,e){i&1&&(q(0,"p",136),v(1,"No filterable fields found for this widget's data."),Me())}function QYt(i,e){if(i&1&&(q(0,"option",163),v(1),Me()),i&2){let t=e.$implicit;Lt("value",t.name),m(),it(t.label)}}function UYt(i,e){if(i&1&&(q(0,"option",163),v(1),Me()),i&2){let t=e.$implicit;Lt("value",t.value),m(),it(t.label)}}function vYt(i,e){if(i&1){let t=Ee();q(0,"input",169),sl("ngModelChange",function(n){R(t);let r=p(7);return al(r.ephemeralFilterBuilderValue,n)||(r.ephemeralFilterBuilderValue=n),V(n)}),Fe("keydown.enter",function(){R(t);let n=p(7);return V(n.addEphemeralFilter())}),Me()}if(i&2){let t=p(7);ol("ngModel",t.ephemeralFilterBuilderValue)}}function YYt(i,e){if(i&1){let t=Ee();q(0,"span",171),v(1,"and"),Me(),q(2,"input",170),sl("ngModelChange",function(n){R(t);let r=p(8);return al(r.ephemeralFilterBuilderValue2,n)||(r.ephemeralFilterBuilderValue2=n),V(n)}),Me()}if(i&2){let t=p(8);m(2),ol("ngModel",t.ephemeralFilterBuilderValue2)}}function ZYt(i,e){if(i&1){let t=Ee();q(0,"input",170),sl("ngModelChange",function(n){R(t);let r=p(7);return al(r.ephemeralFilterBuilderValue,n)||(r.ephemeralFilterBuilderValue=n),V(n)}),Me(),xe(1,YYt,3,1)}if(i&2){let t,M=p(7);ol("ngModel",M.ephemeralFilterBuilderValue),m(),pe((t=M.ephemeralFilterSelectedOperator())!=null&&t.needsSecondValue?1:-1)}}function _Yt(i,e){if(i&1){let t=Ee();q(0,"span",171),v(1,"and"),Me(),q(2,"input",173),sl("ngModelChange",function(n){R(t);let r=p(8);return al(r.ephemeralFilterBuilderValue2,n)||(r.ephemeralFilterBuilderValue2=n),V(n)}),Me()}if(i&2){let t=p(8);m(2),ol("ngModel",t.ephemeralFilterBuilderValue2)}}function WYt(i,e){if(i&1){let t=Ee();q(0,"input",172),sl("ngModelChange",function(n){R(t);let r=p(7);return al(r.ephemeralFilterBuilderValue,n)||(r.ephemeralFilterBuilderValue=n),V(n)}),Fe("keydown.enter",function(){R(t);let n=p(7);return V(n.addEphemeralFilter())}),Me(),xe(1,_Yt,3,1)}if(i&2){let t,M=p(7);ol("ngModel",M.ephemeralFilterBuilderValue),m(),pe((t=M.ephemeralFilterSelectedOperator())!=null&&t.needsSecondValue?1:-1)}}function PYt(i,e){if(i&1){let t=Ee();q(0,"label",174)(1,"input",175),Fe("change",function(){let n=R(t).$implicit,r=p(8);return V(r.toggleEphemeralFilterMultiValue(n.value))}),Me(),q(2,"span"),v(3),Me()()}if(i&2){let t=e.$implicit,M=p(8);m(),Lt("checked",M.ephemeralFilterBuilderValues.includes(t.value)),m(2),Bo("",t.label,"",t.count!=null?" ("+t.count+")":"")}}function RYt(i,e){if(i&1&&(q(0,"div",167),xt(1,PYt,4,3,"label",174,Cj),Me()),i&2){let t=p(5).$implicit,M=p(2);m(),pt(M.filterValuesFor(t,M.ephemeralFilterBuilderFieldId))}}function VYt(i,e){if(i&1&&(q(0,"option",163),v(1),Me()),i&2){let t=e.$implicit;Lt("value",t.value),m(),Bo("",t.label,"",t.count!=null?" ("+t.count+")":"")}}function BYt(i,e){if(i&1){let t=Ee();q(0,"select",162),sl("ngModelChange",function(n){R(t);let r=p(7);return al(r.ephemeralFilterBuilderValue,n)||(r.ephemeralFilterBuilderValue=n),V(n)}),q(1,"option",176),v(2,"Select\u2026"),Me(),xt(3,VYt,2,3,"option",163,Cj),Me()}if(i&2){let t=p(5).$implicit,M=p(2);ol("ngModel",M.ephemeralFilterBuilderValue),m(3),pt(M.filterValuesFor(t,M.ephemeralFilterBuilderFieldId))}}function FYt(i,e){if(i&1&&xe(0,vYt,1,1,"input",166)(1,ZYt,2,2)(2,WYt,2,2)(3,RYt,3,0,"div",167)(4,BYt,5,1,"select",168),i&2){let t,M=p(6);pe((t=(t=M.ephemeralFilterSelectedOperator())==null?null:t.valueKind)==="text"?0:t==="date"?1:t==="number"?2:t==="multi-select"?3:t==="select"?4:-1)}}function HYt(i,e){i&1&&(q(0,"div",165),It(1,"nile-spinner",177),q(2,"span"),v(3,"Loading values\u2026"),Me()())}function JYt(i,e){if(i&1){let t=Ee();q(0,"div",156)(1,"select",162),Fe("ngModelChange",function(n){R(t);let r=p(5);return V(r.onEphemeralFilterFieldChange(n))}),xt(2,QYt,2,2,"option",163,Eat),Me(),q(4,"select",162),Fe("ngModelChange",function(n){R(t);let r=p(5);return V(r.onEphemeralFilterOperatorChange(n))}),xt(5,UYt,2,2,"option",163,Cj),Me(),xe(7,FYt,5,1),q(8,"nile-button",164),Fe("click",function(){R(t);let n=p(5);return V(n.addEphemeralFilter())}),v(9," Add filter "),Me(),xe(10,HYt,4,0,"div",165),Me()}if(i&2){let t=p(5);m(),Lt("ngModel",t.ephemeralFilterBuilderFieldId),m(),pt(t.ephemeralFilterFields()),m(2),Lt("ngModel",t.ephemeralFilterBuilderOperator),m(),pt(t.ephemeralFilterOperators()),m(2),pe(t.ephemeralFilterValuesLoading?-1:7),m(),mt("loading",t.ephemeralFilterApplying?"":null)("disabled",t.ephemeralFilterApplying||t.ephemeralFilterValuesLoading?"":null),m(2),pe(t.ephemeralFilterValuesLoading?10:-1)}}function GYt(i,e){if(i&1&&(q(0,"p",137),v(1),Me()),i&2){let t=p(5);m(),it(t.ephemeralFilterApplyError)}}function $Yt(i,e){if(i&1&&(q(0,"p",136),v(1,"Filters this preview only \u2014 nothing is saved."),Me(),xe(2,fYt,3,0,"div",154),xe(3,wYt,3,0,"div",155),xe(4,CYt,4,0,"div",135)(5,kYt,2,1,"p",137)(6,bYt,2,0,"p",136)(7,JYt,11,6,"div",156),xe(8,GYt,2,1,"p",137)),i&2){let t=p(2).$implicit,M=p(2);m(2),pe(M.ephemeralFilterActiveFilters().length>0?2:-1),m(),pe(M.timeWindowField(t)?3:-1),m(),pe(M.ephemeralFilterFieldsLoading?4:M.ephemeralFilterFieldsError?5:M.ephemeralFilterFields().length===0?6:7),m(4),pe(M.ephemeralFilterApplyError?8:-1)}}function XYt(i,e){if(i&1){let t=Ee();q(0,"nile-dropdown",131),Fe("nile-hide",function(){R(t);let n=p().$implicit,r=p(2);return V((r.dashboardId?r.filterBuilderWidgetId:r.ephemeralFilterBuilderWidgetId)===n.id&&(r.dashboardId?r.closeFilterBuilder():r.closeEphemeralFilterBuilder()))}),q(1,"button",132),It(2,"nile-glyph",152),Me(),q(3,"div",153),xe(4,mYt,7,4)(5,$Yt,9,4),Me()()}if(i&2){let t=p().$implicit,M=p(2);Lt("open",(M.dashboardId?M.filterBuilderWidgetId:M.ephemeralFilterBuilderWidgetId)===t.id),m(4),pe(M.dashboardId?4:5)}}function qYt(i,e){if(i&1){let t=Ee();q(0,"div",106)(1,"button",178),Fe("click",function(){R(t);let n=p().$implicit,r=p(2);return V(r.applyDataViewFilter(n))}),v(2," Apply filter "),Me()()}}function KYt(i,e){i&1&&(q(0,"div",185),It(1,"nile-glyph",129),Me())}function eZt(i,e){if(i&1){let t=Ee();q(0,"nile-menu-item",191),Fe("click",function(){R(t);let n=p(4).$implicit,r=p(2);return V(r.onMenuAction(n,"tweak"))}),It(1,"nile-glyph",192),v(2," Tweak "),Me(),q(3,"nile-menu-item",191),Fe("click",function(){R(t);let n=p(4).$implicit,r=p(2);return V(r.onMenuAction(n,"edit"))}),It(4,"nile-glyph",193),v(5," Edit "),Me(),q(6,"nile-menu-item",191),Fe("click",function(){R(t);let n=p(4).$implicit,r=p(2);return V(r.onMenuAction(n,"delete"))}),It(7,"nile-glyph",194),v(8," Delete "),Me()}}function tZt(i,e){if(i&1){let t=Ee();q(0,"nile-menu-item",191),Fe("click",function(){R(t);let n=p(4).$implicit,r=p(2);return V(r.onMenuAction(n,"setAlert"))}),It(1,"nile-glyph",195),v(2," Set Alert "),Me()}}function iZt(i,e){if(i&1){let t=Ee();q(0,"nile-menu-item",191),Fe("click",function(){R(t);let n=p(4).$implicit,r=p(2);return V(r.onMenuAction(n,"toggleFilterDefault"))}),It(1,"nile-glyph",196),v(2),Me()}if(i&2){let t=p(4).$implicit,M=p(2);m(),Lt("name",M.isFilterDefaultActive(t)?"ng-x-close":"ng-check"),m(),hi(" ",M.isFilterDefaultActive(t)?"Clear default filter":"Set current filter as default"," ")}}function MZt(i,e){if(i&1&&(q(0,"div",183),xe(1,KYt,2,0,"div",185),q(2,"nile-dropdown",186)(3,"button",187),It(4,"nile-glyph",188),Me(),q(5,"nile-menu",189),xe(6,eZt,9,0),xe(7,tZt,3,0,"nile-menu-item",190),xe(8,iZt,3,2,"nile-menu-item",190),Me()()()),i&2){let t=p(3).$implicit,M=p(2);m(),pe(M.editMode?1:-1),m(5),pe(M.editMode?6:-1),m(),pe(M.showSetAlertFor(t)?7:-1),m(),pe(M.canToggleFilterDefault(t)?8:-1)}}function nZt(i,e){if(i&1){let t=Ee();q(0,"div",180)(1,"div",181)(2,"span",182),v(3),Me()(),xe(4,MZt,9,4,"div",183),Me(),q(5,"shared-manual-filter-panel",184),Fe("conditionsChange",function(n){R(t);let r=p(2).$implicit,o=p(2);return V(o.onManualConditionsChange(r,n))})("contentHeight",function(n){R(t);let r=p(2).$implicit,o=p(2);return V(o.onFilterContentHeight(r,n))})("overflowCountChange",function(n){R(t);let r=p(2).$implicit,o=p(2);return V(o.onFilterOverflow(r,n))}),Me()}if(i&2){let t=p(2).$implicit,M=p(2);m(3),it(M.filterHeaderTitle),m(),pe((M.editMode||M.showSetAlertFor(t))&&M.showWidgetMenu?4:-1),m(),Lt("catalog",M.catalogFor(t.id))("conditions",M.manualStateFor(t.id).conditions)("catalogLoading",!M.catalogFor(t.id).length)("disabled",M.widgetsLoading)("valueFetcher",M.valueFetcher())("onDashboardFields",M.observedFields())("recentlyUsedFields",M.recentlyUsedFields())("expanded",M.expandedFilterId()===t.id)}}function rZt(i,e){if(i&1&&(q(0,"p",137),v(1),Me()),i&2){let t=p(4);m(),it(t.filterDefaultError)}}function oZt(i,e){if(i&1){let t=Ee();q(0,"div",179)(1,"span",197),Fe("click",function(){R(t);let n=p(2).$implicit,r=p(2);return V(r.toggleFilterExpand(n))})("keydown.enter",function(){R(t);let n=p(2).$implicit,r=p(2);return V(r.toggleFilterExpand(n))}),v(2),Me()()}if(i&2){let t=p(2).$implicit,M=p(2);m(2),hi(" ",M.expandedFilterId()===t.id?"Show less":"+"+M.filterOverflowFor(t.id)+" more"," ")}}function aZt(i,e){if(i&1&&(xe(0,nZt,6,10),xe(1,rZt,2,1,"p",137),xe(2,oZt,3,1,"div",179)),i&2){let t=p().$implicit,M=p(2);pe(M.isManualMode(t.id)?0:-1),m(),pe(M.filterDefaultError?1:-1),m(),pe(M.isManualMode(t.id)&&(M.filterOverflowFor(t.id)>0||M.expandedFilterId()===t.id)?2:-1)}}function sZt(i,e){if(i&1){let t=Ee();q(0,"gridster-item",97)(1,"div",98),xe(2,Cvt,6,3,"div",99),q(3,"div",100),Fe("click",function(n){let r=R(t).$implicit,o=p(2);return V(o.onWidgetBodyClick(r,n))}),q(4,"shared-nile-chart-widget",101),Fe("aiSend",function(n){R(t);let r=p(2);return V(r.onAiSend(n))})("filterSubmit",function(n){R(t);let r=p(2);return V(r.onFilterSubmit(n))})("filterChange",function(n){R(t);let r=p(2);return V(r.onFilterChange(n))})("chartClick",function(n){let r=R(t).$implicit,o=p(2);return V(o.onChartClick(r,n))})("chartSelection",function(n){let r=R(t).$implicit,o=p(2);return V(o.onChartSelection(r,n))})("chartSelectionReset",function(){let n=R(t).$implicit,r=p(2);return V(r.onChartSelectionReset(n))})("cellFilter",function(n){let r=R(t).$implicit,o=p(2);return V(o.onCellFilter(r,n))})("dataViewFilterChange",function(n){let r=R(t).$implicit,o=p(2);return V(o.onDataViewFilterChange(r.id,n))})("gridFilterVerdict",function(n){R(t);let r=p(2);return V(r.onGridFilterVerdict(n))})("menuAction",function(n){let r=R(t).$implicit,o=p(2);return V(o.onMenuAction(r,n))}),xe(5,Wvt,7,0,"nile-dropdown",102),xe(6,Pvt,2,0,"div",103),xe(7,Rvt,2,1,"div",104),xe(8,iYt,8,3,"nile-dropdown",105),xe(9,nYt,8,1,"nile-dropdown",105),xe(10,XYt,6,2,"nile-dropdown",105),Me(),xe(11,qYt,3,0,"div",106),Me(),xe(12,aZt,3,3),Me()()}if(i&2){let t=e.$implicit,M=p(2);ji("gridster-item--menu-open",M.hasOpenOverlay(t.id)),Lt("item",M.getItemForWidget(t)),m(),ji("widget-card--filter-inactive",M.showFilterNotice(t))("widget-card--filter",M.isFilterWidget(t))("widget-card--menu-open",M.hasOpenOverlay(t.id)),mt("data-widget-id",t.id),m(),pe(M.showFilterNotice(t)?2:-1),m(),ji("widget-body--hidden",M.isFilterWidget(t)&&M.isManualMode(t.id)),m(),Lt("config",M.displayConfigFor(t))("drilldownBy",t.drilldownBy)("widgetId",t.id)("widgetTitle",t.title)("loading",M.widgetsLoading&&!M.isFilterWidget(t)||t.id===M.tweakingWidgetId||M.isRecordsLoading(t)||t.id===M.forecastingWidgetId)("menu",M.chartMenuFor(t))("dashboardFilters",M.dashboardFilters)("resolvedFilters",M.resolvedFilters)("dashboardId",M.dashboardId)("conversationId",M.conversationId)("cellFilterEnabled",M.hasFilterWidget()&&M.viewModeFor(t)!=="data"),m(),pe(M.showWidgetMenu&&M.menuItemsFor(t).length?5:-1),m(),pe(M.editMode?6:-1),m(),pe(M.selectable?7:-1),m(),pe(M.canShowChartTypePicker(t)?8:-1),m(),pe(M.canShowColorPicker(t)?9:-1),m(),pe(M.canShowFilterPicker(t)?10:-1),m(),pe(M.viewModeFor(t)==="data"&&M.hasPendingDataViewFilter(t)?11:-1),m(),pe(M.isFilterWidget(t)?12:-1)}}function lZt(i,e){if(i&1&&(q(0,"gridster",95),xt(1,sZt,13,32,"gridster-item",96,u3),Me()),i&2){let t=p();ji("grid-hidden",t.widgets.length===0&&t.editMode),Lt("options",t.options),m(),pt(t.gridWidgets())}}function gZt(i,e){if(i&1){let t=Ee();q(0,"nile-menu-item",191),Fe("click",function(){let n=R(t).$implicit,r=p(2);return V(r.pickDrillOption(n))}),It(1,"nile-glyph",24),v(2),Me()}if(i&2){let t=e.$implicit;m(),mt("name",t.drillDownIcon||"ng-tag"),m(),hi(" ",t.drillDownName," ")}}function NZt(i,e){if(i&1){let t=Ee();It(0,"div",201),q(1,"nile-menu-item",191),Fe("click",function(){R(t);let n=p(2);return V(n.pickAddAsFilter())}),It(2,"nile-glyph",202),v(3," Add as filter "),Me()}}function uZt(i,e){if(i&1){let t=Ee();q(0,"nile-dropdown",198),Fe("nile-after-hide",function(){R(t);let n=p();return V(n.closeDrillContextMenu())}),It(1,"span",199),q(2,"nile-menu",189)(3,"div",200),v(4,"Drill Down"),Me(),xt(5,gZt,3,2,"nile-menu-item",190,zvt),xe(7,NZt,4,0),Me()()}if(i&2){let t=e;dM("left",t.x,"px")("top",t.y,"px"),m(5),pt(t.options),m(2),pe(t.conditions!=null&&t.conditions.length?7:-1)}}function DZt(i,e){if(i&1){let t=Ee();q(0,"button",203),Fe("click",function(){let n=R(t).$implicit,r=p();return V(r.useTweakExample(n))}),It(1,"nile-glyph",204),q(2,"span"),v(3),Me()()}if(i&2){let t=e.$implicit;m(3),it(t)}}function cZt(i,e){if(i&1&&(q(0,"span",21),v(1),Me()),i&2){let t=p();m(),it(t.dslChartTypeLabel)}}function IZt(i,e){if(i&1){let t=Ee();q(0,"nile-button",15),Fe("click",function(){R(t);let n=p();return V(n.resetDslQuery())}),It(1,"nile-glyph",205),v(2," Reset to saved query "),Me()}if(i&2){let t=p();mt("disabled",t.dslApplying?"":null)}}function dZt(i,e){if(i&1){let t=Ee();q(0,"div",25),It(1,"nile-glyph",206),q(2,"span",207),v(3),Me(),q(4,"button",208),Fe("click",function(){R(t);let n=p();return V(n.dslError=null)}),It(5,"nile-glyph",209),Me()()}if(i&2){let t=p();m(3),it(t.dslError)}}function jZt(i,e){if(i&1){let t=Ee();q(0,"section",27)(1,"header",29)(2,"span",30),v(3,"Query"),Me(),q(4,"span",210)(5,"button",211),Fe("click",function(){R(t);let n=p();return V(n.formatDslQuery())}),It(6,"nile-glyph",212),v(7," Format "),Me(),q(8,"button",213),Fe("click",function(){R(t);let n=p();return V(n.copyDslQuery())}),It(9,"nile-glyph",214),v(10),Me(),q(11,"span",215),It(12,"nile-glyph",214),v(13),Me()()(),q(14,"nile-code-editor",216),Fe("nile-change",function(n){R(t);let r=p();return V(r.onDslTextChange(n.detail.value))}),Me()()}if(i&2){let t=p();m(5),Lt("disabled",t.dslApplying),m(4),mt("name",t.dslCopied?"ng-check":"ng-copy"),m(),hi(" ",t.dslCopied?"Copied":"Copy"," "),m(),ji("dsl-validity--ok",t.dslValidity.ok),mt("title",t.dslValidity.error),m(),mt("name",t.dslValidity.ok?"ng-check":"ng-alert-triangle"),m(),hi(" ",t.dslValidity.ok?"Valid "+t.dslTerm:"Invalid "+t.dslTerm," "),m(),Lt("expandable",!1)("value",t.dslQueryText),mt("language",t.dslCodeEditorLanguage)("readonly",t.dslApplying?"":null)}}function yZt(i,e){if(i&1&&(q(0,"span",32),v(1),Me()),i&2){let t=p();m(),Bo(" ",t.dslTurns.length," ",t.dslTurns.length===1?"change":"changes"," this session ")}}function TZt(i,e){i&1&&(q(0,"p",34),v(1," Describe a change and the assistant rewrites the query. Nothing is saved until you apply. "),Me())}function AZt(i,e){if(i&1&&(q(0,"div",224)(1,"span",225),v(2),Me(),q(3,"span",226),v(4),Me()()),i&2){let t=e.$implicit;TJ("dsl-diff-line--"+t.kind),m(2),it(t.kind==="add"?"+":t.kind==="remove"?"\u2212":" "),m(2),it(t.text)}}function zZt(i,e){if(i&1&&(q(0,"div",219),xt(1,AZt,5,4,"div",223,Yr),Me()),i&2){let t=p(),M=t.$implicit,n=t.$index,r=p();m(),pt(r.dslExpandedTurn===n?M.diff:M.changed)}}function hZt(i,e){if(i&1){let t=Ee();q(0,"button",227),Fe("click",function(){R(t);let n=p().$index,r=p();return V(r.toggleDslDiff(n))}),v(1),Me()}if(i&2){let t=p().$index,M=p();m(),hi(" ",M.dslExpandedTurn===t?"Hide full diff":"View full diff"," ")}}function xZt(i,e){if(i&1){let t=Ee();q(0,"button",228),Fe("click",function(){R(t);let n=p().$index,r=p();return V(r.undoDslTurn(n))}),v(1," Undo this change "),Me()}if(i&2){let t=p().$index,M=p();Lt("disabled",M.dslApplying||M.dslGenerating)("title",t===M.dslTurns.length-1?"Restore the query to before this change":"Restore the query to before this change \u2014 later changes are discarded")}}function pZt(i,e){if(i&1&&(It(0,"nile-ai-chat-bubble",35),q(1,"nile-ai-chat-bubble",217)(2,"p",218),v(3),Me(),xe(4,zZt,3,0,"div",219),q(5,"nile-ai-message-actions",220),xe(6,hZt,2,1,"button",221),xe(7,xZt,2,2,"button",222),Me()()),i&2){let t=e.$implicit,M=p();Lt("role","user")("message",t.prompt),m(),Lt("role","ai")("agent","Query assistant")("icon","ng-code"),m(2),it(t.summary),m(),pe(M.dslDevMode&&t.wasModified&&t.changed.length?4:-1),m(),Lt("copy",M.dslDevMode)("copyValue",t.after),m(),pe(M.dslDevMode&&t.wasModified&&t.changed.length?6:-1),m(),pe(t.wasModified?7:-1)}}function LZt(i,e){if(i&1&&It(0,"nile-ai-chat-bubble",35),i&2){let t=p();Lt("role","user")("message",t.dslPendingPrompt)}}function OZt(i,e){i&1&&It(0,"nile-ai-chat-bubble",36),i&2&&Lt("role","ai")("agent","Query assistant")("icon","ng-code")("thinking","")("loading",!0)}function mZt(i,e){if(i&1){let t=Ee();q(0,"button",238),Fe("click",function(){let n=R(t).$implicit,r=p(2);return V(r.onForecastGranularity(n))}),v(1),Me()}if(i&2){let t=e.$implicit,M=p(2);ji("fc-seg__btn--on",M.forecastDraft.granularity===t),m(),it(t)}}function EZt(i,e){if(i&1){let t=Ee();q(0,"button",238),Fe("click",function(){let n=R(t).$implicit,r=p(2);return V(r.onForecastConfidence(n))}),v(1),Me()}if(i&2){let t=e.$implicit,M=p(2);ji("fc-seg__btn--on",M.forecastDraft.confidence===t),m(),hi("",t,"%")}}function fZt(i,e){if(i&1&&(q(0,"span",239),v(1),q(2,"strong"),v(3),Me()()),i&2){let t=e.$implicit;m(),it(t.label),m(2),it(t.value)}}function SZt(i,e){i&1&&(q(0,"span",233),v(1,"This forecast"),Me(),xt(2,fZt,4,2,"span",239,hvt)),i&2&&(m(2),pt(e))}function wZt(i,e){if(i&1){let t=Ee();q(0,"div",229)(1,"label",230),v(2," Horizon \u2014 "),q(3,"strong"),v(4),Me(),v(5),Me(),q(6,"input",231),Fe("input",function(n){R(t);let r=p();return V(r.onForecastHorizon(n.target.value))}),Me(),q(7,"p",232),v(8),Me(),q(9,"span",233),v(10,"Granularity"),Me(),q(11,"div",234),xt(12,mZt,2,3,"button",235,da),Me(),q(14,"p",232),v(15,"Coarser buckets are reachable; finer ones are not."),Me(),q(16,"span",233),v(17,"Confidence interval \u2014 "),q(18,"strong"),v(19),Me()(),q(20,"div",236),xt(21,EZt,2,3,"button",235,da),Me(),q(23,"p",232),v(24,"A wider band is more likely to contain the real value. 80% is a good default."),Me(),xe(25,SZt,4,0),Me(),q(26,"div",237)(27,"nile-button",15),Fe("click",function(){R(t);let n=p();return V(n.closeForecastSettings())}),v(28,"Cancel"),Me(),q(29,"nile-button",16),Fe("click",function(){R(t);let n=p();return V(n.applyForecastSettings())}),v(30,"Apply"),Me()()}if(i&2){let t,M=p();m(4),it(M.forecastDraft.horizon),m(),Bo(" ",M.forecastPeriodWord,"",M.forecastDraft.horizon===1?"":"s"," "),m(),Lt("value",M.forecastDraft.horizon),mt("max",M.forecastMaxHorizon),m(2),hi("Capped at ",M.forecastMaxHorizon," for this widget \u2014 half the history the model was fitted on."),m(4),pt(M.forecastGranularities),m(7),hi("",M.forecastDraft.confidence,"%"),m(2),pt(M.forecastConfidences),m(4),pe((t=M.forecastProvenance)?25:-1,t)}}var Oat=2e3,CZt={line:"Line chart",area:"Area chart",bar:"Bar chart",column:"Column chart",pie:"Pie chart",donut:"Donut chart",scatter:"Scatter chart",heatmap:"Heatmap",funnel:"Funnel chart",gauge:"Gauge",radar:"Radar chart",waterfall:"Waterfall chart",kpi:"KPI",table:"Table",grid:"Data grid"},dA=class i{constructor(e,t,M=null,n=null,r=null,o=null,a=null,s=null,l=null,N=null,D=null,c=null){this.host=e;this.observed=t;this.filterValuesFetcher=M;this.dslEditorFetcher=n;this.recordsFetcher=r;this.chartTypeFetcher=o;this.widgetFilterFetcher=a;this.adhocFilterFetcher=s;this.filterDefaultFetcher=l;this.storiesFetcher=N;this.router=D;this.cdr=c;this.decorated=this.filterValuesFetcher?Lat(this.filterValuesFetcher,this.observed):null}host;observed;filterValuesFetcher;dslEditorFetcher;recordsFetcher;chartTypeFetcher;widgetFilterFetcher;adhocFilterFetcher;filterDefaultFetcher;storiesFetcher;router;cdr;widgets=[];editMode=!0;dashboardId=null;conversationId=null;persistToPublished=!1;tweakingWidgetId=null;forecastingWidgetId=null;loading=!1;outerMargin=!0;widgetsLoading=!1;showTweakInViewMode=!1;showEditDslInViewMode=!1;canSetAlert=!1;canAddToStory=!1;canForecast=!1;forecastable={};showWidgetMenu=!0;selectable=!1;selectedWidgetIds=null;dashboardFilters=null;resolvedFilters=null;applySummary=null;filterExplanation=null;static FILTER_LAYER_INDEX=10;filterHeaderTitle=hm;skeletonKpis=[0,1,2,3];skeletonCharts=[0,1,2,3];skeletonBars=[55,80,42,92,65,48,75];remove=new ni;editWidget=new ni;openAiBuilder=new ni;updateLayout=new ni;aiSend=new ni;tweakWidget=new ni;dslWidgetUpdated=new ni;dslEditorClosed=new ni;widgetChartTypeChanged=new ni;widgetFiltersChanged=new ni;widgetColorChanged=new ni;filterSubmit=new ni;filterChange=new ni;selectionChange=new ni;setAlert=new ni;addToStory=new ni;widgetClick=new ni;forecast=new ni;selectedIds=new Set;tweakTargetId=null;tweakPromptText="";tweakSubmitting=!1;tweakExamples=["Convert this into a bar chart and make the title shorter","Convert this into a column chart and make red color","Convert this into a pie chart and use a blue pallete"];gridsterItems=[];options={gridType:cM.VerticalFixed,displayGrid:vh.OnDragAndResize,compactType:dn.None,pushItems:!0,swap:!1,margin:8,outerMargin:!1,maxLayerIndex:i.FILTER_LAYER_INDEX,minCols:12,maxCols:12,minRows:4,defaultItemCols:6,defaultItemRows:4,fixedRowHeight:72,disableAutoPositionOnConflict:!0,mobileBreakpoint:0,initCallback:(e,t)=>{this.gridApi=t,this.gridInstance=e},draggable:{enabled:!0,ignoreContent:!0,dragHandleClass:"widget-drag-handle",stop:()=>this.scheduleGestureReconcile()},resizable:{enabled:!0,handles:{s:!0,e:!0,n:!0,w:!0,se:!0,ne:!0,sw:!0,nw:!0},stop:()=>this.scheduleGestureReconcile()}};gridApi=null;gridInstance=null;expandedFilterId=Ye(null);filterContentHeights=new Map;filterExtraRows=new Map;filterOverflowCounts=Ye(new Map);resizeObserver=null;resizeRaf=0;lastGridWidth=0;lastGridHeight=0;ngOnChanges(e){(e.editMode||e.showTweakInViewMode||e.showEditDslInViewMode||e.showWidgetMenu||e.canAddToStory)&&this.menuCache.clear(),e.editMode&&(this.options=_(x({},this.options),{outerMargin:!this.editMode,draggable:_(x({},this.options.draggable),{enabled:this.editMode}),resizable:_(x({},this.options.resizable),{enabled:this.editMode}),displayGrid:this.editMode?vh.OnDragAndResize:vh.None})),e.outerMargin&&(this.options=_(x({},this.options),{outerMargin:this.outerMargin})),e.dashboardId&&(this.observed.clear(),this.observedFields.set([]),this.menuCache.clear(),this.autoAppliedDefaultForDashboardId=null),(e.dashboardFilters&&!e.dashboardFilters.firstChange||e.resolvedFilters&&!e.resolvedFilters.firstChange)&&this.clearEphemeralOverrides(),e.widgets&&(this.observed.publish(Iat(this.widgets)),this.observedFields.set(this.observed.fields()),this.expandedFilterId.set(null),this.filterExtraRows.clear(),this.filterOverflowCounts.set(new Map),this.syncGridsterItems(),this.pruneManualState(),this.pruneEphemeralFilterState(),this.maybeAutoApplyDefaultFilter(),this.selectable?this.syncDefaultSelection():this.resetSelection()),e.selectable&&!this.selectable&&this.resetSelection(),e.selectedWidgetIds&&!e.widgets&&this.selectable&&this.syncDefaultSelection()}reasonText(e){let t=e?.id?this.gridFilterVerdicts.get(e.id):void 0;return t&&!t.applied?wm({reason:t.reason}):wm(e)}gridFilterVerdicts=new Map;onGridFilterVerdict(e){if(!e?.widgetId)return;let t=this.gridFilterVerdicts.get(e.widgetId);t&&t.applied===e.applied&&t.reason===e.reason||(this.gridFilterVerdicts.set(e.widgetId,{applied:e.applied,reason:e.reason}),this.cdr?.markForCheck())}showFilterNotice(e){if(!e)return!1;if(e.edited===!1)return!0;let t=e.id?this.gridFilterVerdicts.get(e.id):void 0;return!!t&&!t.applied}static DEFAULT_MANUAL_STATE={mode:"prompt",conditions:[]};static EMPTY_CATALOG=[];static SYNTHETIC_FILTER_KEY="manual-filter";manualFilterStates=Ye(new Map);filterCatalogs=Ye(new Map);observedFields=Ye([]);recentlyUsedFields=Ye([]);manualStateFor(e){return this.manualFilterStates().get(e)??i.DEFAULT_MANUAL_STATE}isManualMode(e){return this.manualStateFor(e).mode==="manual"}catalogFor(e){return this.filterCatalogs().get(e)??i.EMPTY_CATALOG}boundValueFetcher=async(e,t)=>{let M=this.dashboardId;if(!this.decorated||!M)return[];let n=(this.resolvedFilters??[]).filter(N=>N.field!==e),r=n.length>0?{resolvedFilters:n}:{};if(!(t??"").trim())return(await this.decorated(M,e,t,n.length>0?r:void 0)).values;let a=await this.decorated(M,e,t,_(x({},r),{matchMode:"substring"}));if(a.values.length>0)return a.values;let s=await this.decorated(M,e,t,_(x({},r),{matchMode:"fuzzy"}));return s.values.length>0?s.values:(await this.decorated(M,e,t,_(x({},r),{matchMode:"semantic"}))).values};valueFetcher(){return this.decorated&&this.dashboardId?this.boundValueFetcher:null}decorated=null;ngAfterViewInit(){if(typeof ResizeObserver>"u"||typeof window>"u")return;let e=this.host.nativeElement.querySelector(".canvas-wrap")??this.host.nativeElement;this.lastGridWidth=e.clientWidth,this.lastGridHeight=e.clientHeight,this.resizeObserver=new ResizeObserver(()=>{this.resizeRaf&&cancelAnimationFrame(this.resizeRaf),this.resizeRaf=requestAnimationFrame(()=>{let t=e.clientWidth,M=e.clientHeight;t===this.lastGridWidth&&M===this.lastGridHeight||(this.lastGridWidth=t,this.lastGridHeight=M,this.gridApi?.resize(),window.dispatchEvent(new Event("resize")))})}),this.resizeObserver.observe(e)}ngOnDestroy(){this.resizeRaf&&cancelAnimationFrame(this.resizeRaf),this.resizeObserver?.disconnect(),this.resizeObserver=null}setManualState(e,t){this.manualFilterStates.update(M=>new Map(M).set(e,t))}firstFilterWidget(){return this.widgets.find(e=>this.isFilterWidget(e))}autoAppliedDefaultForDashboardId=null;maybeAutoApplyDefaultFilter(){if(this.autoAppliedDefaultForDashboardId===this.dashboardId)return;let e=this.firstFilterWidget(),t=this.filterDefaultControl(e);!e||!t?.autoApply||!t.defaultValue?.trim()||(this.autoAppliedDefaultForDashboardId=this.dashboardId,this.applyExpression(e,t.defaultValue))}filterDefaultControl(e){return e?.config?.chart?.controls?.[0]}filterDefaultBusy=!1;filterDefaultError=null;canToggleFilterDefault(e){return this.isFilterWidget(e)&&!!this.filterDefaultFetcher&&!!this.dashboardId}isFilterDefaultActive(e){return!!this.filterDefaultControl(e)?.autoApply}async toggleFilterDefault(e){if(!this.filterDefaultFetcher||!this.dashboardId||this.filterDefaultBusy)return;let t=this.filterDefaultControl(e),M=!!t?.autoApply,n=M?"":(this.lastAppliedFilter.get(e.id)??t?.value??"").trim();if(!M&&!n){this.filterDefaultError="Apply a filter first, then set it as the default.",this.cdr?.markForCheck();return}this.filterDefaultBusy=!0,this.filterDefaultError=null,this.cdr?.markForCheck();try{let r=await this.filterDefaultFetcher.set(this.dashboardId,e.id,n,!M,this.persistToPublished);this.widgetFiltersChanged.emit(r)}catch(r){this.filterDefaultError=r instanceof Error?r.message:"Could not update the default filter"}finally{this.filterDefaultBusy=!1,this.cdr?.markForCheck()}}hasFilterWidget(){return this.widgets.some(e=>this.isFilterWidget(e))}expressionControlIdOf(e){return e.config?.chart?.controls?.find(n=>(n.variant==="expression"||n.variant==="hybrid")&&n.id)?.id??null}chartWidgetFor(e){return this.chartWidgets?.find(t=>t.widgetId===e)}activeFilterMode(e){return this.manualStateFor(e.id).mode}gridWidgetsCache=null;gridWidgets(){let e=this.railReplacesCard(),t=this.gridWidgetsCache;if(t&&t.src===this.widgets&&t.rail===e)return t.out;let M=e?this.widgets.filter(n=>!this.isFilterWidget(n)):this.widgets;return this.gridWidgetsCache={src:this.widgets,rail:e,out:M},M}railVisible(){return this.hasFilterWidget()}railReplacesCard(){return this.hasFilterWidget()}railShift(){if(!this.railReplacesCard())return null;let e=this.firstFilterWidget();if(!e)return null;let t=this.gridsterItems.find(M=>M.widgetId===e.id)??this.buildItem(e);return{y:Number(t.y??0),rows:Number(t.rows??0)}}railItemsCache=null;railItems(){let e=this.railShift();if(!e)return null;let t=this.railItemsCache;if(t&&t.src===this.widgets&&t.edit===this.editMode)return t.map;let M=new Map;for(let n of this.widgets){if(this.isFilterWidget(n))continue;let r=this.gridsterItems.find(a=>a.widgetId===n.id)??this.buildItem(n),o=Number(r.y??0);M.set(n.id,_(x({},r),{y:o>e.y?Math.max(0,o-e.rows):o}))}return this.railItemsCache={src:this.widgets,edit:this.editMode,map:M},M}railMode(){let e=this.firstFilterWidget();return e?this.manualStateFor(e.id).mode:"prompt"}railConditions(){let e=this.firstFilterWidget();return e?this.manualStateFor(e.id).conditions:[]}railCatalog(){let e=this.firstFilterWidget();return e?this.catalogFor(e.id):[]}railExpression(){let e=this.firstFilterWidget();return e?this.chartWidgetFor(e.id)?.getLiveExpression()?.value??"":""}onRailModeChange(e){let t=this.firstFilterWidget();t&&this.useFilterMode(t,e)}onRailConditions(e){let t=this.firstFilterWidget();t&&this.onManualConditionsChange(t,e)}onRailExpressionRun(e){let t=this.firstFilterWidget();t&&(this.chartWidgetFor(t.id)?.setFilterExpression(e),this.applyExpression(t,e))}onRailPromptAsk(e){let t=this.firstFilterWidget();t&&this.applyExpression(t,e)}onRailClearAll(){let e=this.firstFilterWidget();e&&(this.setManualState(e.id,_(x({},this.manualStateFor(e.id)),{conditions:[]})),this.chartWidgetFor(e.id)?.setFilterExpression(""),this.applyExpression(e,""))}useFilterMode(e,t){if(this.activeFilterMode(e)===t)return;this.collapseExpandedFilter(),this.filterOverflowCounts.update(o=>{let a=new Map(o);return a.delete(e.id),a});let n=this.chartWidgetFor(e.id),r=this.manualStateFor(e.id);if(t==="manual"){this.setManualState(e.id,{mode:"manual",conditions:[]}),this.requestCatalog(e),this.syncAppliedFilter(e,"");return}if(t==="expression"){n?.setFilterMode("expression",""),this.setManualState(e.id,_(x({},r),{mode:"expression",conditions:[]})),this.requestCatalog(e),this.syncAppliedFilter(e,"");return}n?.setFilterMode("prompt",""),this.setManualState(e.id,_(x({},r),{mode:"prompt",conditions:[]})),this.syncAppliedFilter(e,"")}lastAppliedFilter=new Map;syncAppliedFilter(e,t){let M=(t??"").trim();(this.lastAppliedFilter.get(e.id)??"")!==M&&this.applyExpression(e,M)}onManualConditionsChange(e,t){this.setManualState(e.id,{mode:"manual",conditions:t}),this.trackRecentlyUsed(t),t.length||this.collapseExpandedFilter(),this.applyManualConditions(e)}trackRecentlyUsed(e){let t=e.map(M=>M.field).filter(M=>!!M);t.length&&this.recentlyUsedFields.update(M=>{let n=new Set,r=[];for(let o of[...t,...M])n.has(o)||(n.add(o),r.push(o));return r.slice(0,20)})}applyExpression(e,t){let M=this.expressionControlIdOf(e)??i.SYNTHETIC_FILTER_KEY;this.lastAppliedFilter.set(e.id,t.trim()),this.filterSubmit.emit({widgetId:e.id,filters:t.trim()?{[M]:t}:{},errors:{}})}applyManualConditions(e){this.applyExpression(e,wI(this.manualStateFor(e.id).conditions))}addFilterConditions(e){if(!e.length)return;let t=this.firstFilterWidget();if(!t)return;let M=this.manualStateFor(t.id),n=M.conditions;if(M.mode==="prompt")n=fm(this.resolvedFilters??[]);else if(M.mode==="expression"){let r=this.chartWidgetFor(t.id)?.getLiveExpression()?.value??"";if(r.trim()){let o=iB(r);if(o===null){if(Sm(r)){let a=`${r.trim()} and ${wI(e)}`;this.chartWidgetFor(t.id)?.setFilterExpression(a),this.applyExpression(t,a),this.requestCatalog(t);return}console.warn("[dashboard-filter] live expression uses or/not/grouping the apply engine can't combine with a click-added condition; leaving the expression unchanged.");return}n=o}else n=fm(this.resolvedFilters??[])}this.setManualState(t.id,{mode:"manual",conditions:KV(n,e)}),this.applyManualConditions(t),this.requestCatalog(t)}requestCatalog(e){let M=e.config?.chart?.controls?.find(n=>n.id)?.id;M&&this.filterChange.emit({widgetId:e.id,controlId:M,query:""})}pruneManualState(){let e=new Set(this.widgets.map(t=>t.id));this.manualFilterStates.update(t=>new Map([...t].filter(([M])=>e.has(M)))),this.filterCatalogs.update(t=>new Map([...t].filter(([M])=>e.has(M))));for(let t of[...this.lastAppliedFilter.keys()])e.has(t)||this.lastAppliedFilter.delete(t)}isSelected(e){return this.selectedIds.has(e)}toggleSelection(e,t){t?this.selectedIds.add(e):this.selectedIds.delete(e),this.selectionChange.emit([...this.selectedIds])}resetSelection(){this.lastWidgetIdsKey="",this.selectedIds.size!==0&&(this.selectedIds.clear(),queueMicrotask(()=>this.selectionChange.emit([])))}lastWidgetIdsKey="";syncDefaultSelection(){let e=this.widgets.map(r=>r.id),t=e.join("|")+"::"+(this.selectedWidgetIds?this.selectedWidgetIds.join(","):"*");if(t===this.lastWidgetIdsKey)return;this.lastWidgetIdsKey=t;let M=this.selectedWidgetIds,n=M!=null?e.filter(r=>M.includes(r)):e;this.selectedIds=new Set(n),queueMicrotask(()=>this.selectionChange.emit([...this.selectedIds]))}getItemForWidget(e){let t=this.railItems()?.get(e.id);if(t)return t;let M=this.gridsterItems.find(n=>n.widgetId===e.id);return M||this.buildItem(e)}toggleFilterExpand(e){this.expandedFilterId()===e.id?(this.expandedFilterId.set(null),this.filterExtraRows.delete(e.id)):(this.expandedFilterId.set(e.id),this.filterExtraRows.set(e.id,this.computeExtraRows(e))),this.syncGridsterItems()}onFilterContentHeight(e,t){if(this.filterContentHeights.set(e.id,t),this.expandedFilterId()!==e.id)return;let M=this.computeExtraRows(e);M!==(this.filterExtraRows.get(e.id)??0)&&(this.filterExtraRows.set(e.id,M),this.syncGridsterItems())}onFilterOverflow(e,t){this.filterOverflowCounts.update(M=>new Map(M).set(e.id,t))}filterOverflowFor(e){return this.filterOverflowCounts().get(e)??0}computeExtraRows(e){let t=this.filterContentHeights.get(e.id)??0,M=this.gridInstance?.curRowHeight??0;if(M<=0||t<=0)return 3;let r=Math.max(0,t-76);return Math.ceil(r/M)}expandedExtraRowsFor(e){return this.expandedFilterId()===e?this.filterExtraRows.get(e)??0:0}collapseExpandedFilter(){this.expandedFilterId()!==null&&(this.expandedFilterId.set(null),this.filterExtraRows.clear(),this.syncGridsterItems())}isKpi(e){return e.widgetType==="kpi"?!0:e.config?.chart?.type==="kpi"}isFilterWidget(e){return e.config?.chart?.type==="filter"}showSetAlertFor(e){return this.canSetAlert&&this.showWidgetMenu}showAddToStoryFor(e){return this.canAddToStory&&this.showWidgetMenu&&!!this.storiesFetcher&&!this.isFilterWidget(e)}hasForecast(e){return!!e?.config?.forecast?.enabled}showForecastFor(e){return!this.canForecast||!this.showWidgetMenu?!1:this.hasForecast(e)||!!this.forecastable[e.id]?.forecastable}isDslEditableWidget(e){let t=e.queryMeta?.adapterType;if(!t||!["opensearch","postgres","mssql"].includes(t))return!1;if(this.dashboardId)return!0;let M=e.queryMeta;return!!(M?.sql||M?.dsl)}widgetViewMode=Ye(new Map);widgetRecords=Ye(new Map);widgetRecordsLoading=Ye(new Set);dataViewFilters=Ye(new Map);confirmedDataViewFilters=Ye(new Map);viewModeFor(e){return this.widgetViewMode().get(e.id)??"chart"}onDataViewFilterChange(e,t){let M=new Map(this.dataViewFilters());if(t?.length?M.set(e,t):M.delete(e),this.dataViewFilters.set(M),!t?.length&&this.confirmedDataViewFilters().has(e)){let n=new Map(this.confirmedDataViewFilters());n.delete(e),this.confirmedDataViewFilters.set(n)}}hasPendingDataViewFilter(e){return(this.dataViewFilters().get(e.id)?.length??0)>0}applyDataViewFilter(e){let t=this.dataViewFilters().get(e.id),M=new Map(this.confirmedDataViewFilters());if(t?.length?M.set(e.id,t):M.delete(e.id),this.confirmedDataViewFilters.set(M),this.widgetRecords().has(e.id)){let n=new Map(this.widgetRecords());n.delete(e.id),this.widgetRecords.set(n)}this.viewRecords(e)}widgetDataRows(e){return N3(e.config?.chart)}recordsChartFor(e){return this.widgetRecords().get(e.id)??null}isRecordsLoading(e){return this.widgetRecordsLoading().has(e.id)}displayConfigFor(e){let t=this.viewModeFor(e);if(t==="data")return _(x({},e.config),{chart:this.buildDataViewChart(e)});if(t==="records"){let o=this.recordsChartFor(e);if(o)return o.config}let M=this.ephemeralKey(e),n=this.ephemeralFilterResult.get(M);return n?n?.config??e.config:this.ephemeralChartOverride.get(M)?.config??e.config}ephemeralKey(e){return`${e.id}::${e.title??""}`}ephemeralChartOverride=new Map;ephemeralFilters=new Map;ephemeralFilterSeq=0;ephemeralFilterFieldsCache=new Map;filterValuesCache=new Map;ephemeralFilterBaseConfig=new Map;ephemeralFilterResult=new Map;clearEphemeralOverrides(){!this.ephemeralChartOverride.size&&!this.ephemeralFilterResult.size&&!this.ephemeralFilters.size||(this.ephemeralChartOverride.clear(),this.ephemeralFilters.clear(),this.ephemeralFilterBaseConfig.clear(),this.ephemeralFilterResult.clear(),this.cdr?.markForCheck())}pruneEphemeralFilterState(){let e=new Set(this.widgets.map(M=>this.ephemeralKey(M))),t=M=>{for(let n of e)if(M===n||M.startsWith(`${n}::`))return!0;return!1};for(let M of[this.ephemeralChartOverride,this.ephemeralFilters,this.ephemeralFilterFieldsCache,this.ephemeralFilterBaseConfig,this.ephemeralFilterResult])for(let n of M.keys())e.has(n)||M.delete(n);for(let M of this.filterValuesCache.keys())t(M)||this.filterValuesCache.delete(M)}buildDataViewChart(e){let{columns:t,rows:M}=this.widgetDataRows(e);if(!(e.config?.chart?.type==="kpi"))return{type:"grid",data:M,columns:t.map(s=>({id:s,header:s,accessorKey:s,enableSorting:!0}))};let r=M[0]?.[t[0]]??null,o=g3(e);return{type:"grid",data:[{field:"Value",text:r,emphasize:!0},...o.map(s=>({field:s.label,text:s.text}))],columns:[{id:"field",header:"Field",accessorKey:"field",enableSorting:!1,width:"140px",cell:s=>j`<strong>${s.value}</strong>`},{id:"text",header:"Value",accessorKey:"text",enableSorting:!1,cell:s=>{let N=s.row.emphasize?"display:block;overflow-x:auto;white-space:nowrap;font-size:22px;font-weight:700;":"display:block;overflow-x:auto;white-space:nowrap;";return j`<span style=${N}>${s.value}</span>`}}]}}hasQueryableData(e){if(!this.recordsFetcher)return!1;let t=!!e.queryMeta?.sql,M=e.config?.chart?.type==="grid";return t&&!M}setWidgetViewMode(e,t){let M=new Map(this.widgetViewMode());t==="chart"?M.delete(e):M.set(e,t),this.widgetViewMode.set(M)}async viewRecords(e){if(this.setWidgetViewMode(e.id,"records"),!this.recordsFetcher||this.widgetRecords().has(e.id))return;let t=new Set(this.widgetRecordsLoading());t.add(e.id),this.widgetRecordsLoading.set(t);try{let M=this.confirmedDataViewFilters().get(e.id),n=M?.length?M.map(a=>({field:a.id,operation:"contains",value:a.value})):void 0,r=await this.recordsFetcher.fetch(e,n),o=new Map(this.widgetRecords());o.set(e.id,r.empty?null:r.chart),this.widgetRecords.set(o)}catch{let M=new Map(this.widgetRecords());M.set(e.id,null),this.widgetRecords.set(M)}finally{let M=new Set(this.widgetRecordsLoading());M.delete(e.id),this.widgetRecordsLoading.set(M),this.cdr?.markForCheck()}}menuCache=new Map;disabledMenu={enabled:!1,items:[]};menuFor(e){if(!this.showWidgetMenu)return this.disabledMenu;let t=this.isKpi(e),M=this.isFilterWidget(e),n=this.isDslEditableWidget(e),r=n?this.dslMenuLabelFor(e):null,o=this.showSetAlertFor(e),a=this.showAddToStoryFor(e),s=this.viewModeFor(e),l=this.hasQueryableData(e),N=M&&!!this.filterDefaultControl(e)?.autoApply,D=this.showForecastFor(e),c=this.hasForecast(e),I=`${t}:${o}:${M}:${n}:${r}:${s}:${l}:${N}:${D}:${c}`,d=this.menuCache.get(I);if(d)return d;let y=[],A,z=L=>{M||(s==="chart"?y.push({type:"custom",label:"Chart Data",id:"viewData",glyph:"ng-table",divider:L}):(y.push({type:"custom",label:"View Chart",id:"viewChart",glyph:"ng-chart-bar",divider:L}),l&&s!=="records"&&y.push({type:"custom",label:"View Records",id:"viewRecords",glyph:"ng-database"})))},E=L=>{M||(this.canShowChartTypePicker(e)&&(y.push({type:"custom",label:"Change chart type",id:"changeChartType",glyph:"ng-chart-bar",divider:L}),L=!1),this.canShowFilterPicker(e)&&(y.push({type:"custom",label:"Manage filters",id:"manageFilters",glyph:"ng-filter-lines",divider:L}),L=!1),this.canShowColorPicker(e)&&y.push({type:"custom",label:"Customize colors",id:"customizeColors",glyph:"ng-palette",divider:L}))},S=L=>{!M||!this.filterDefaultFetcher||!this.dashboardId||y.push({type:"custom",label:N?"Clear default filter":"Set current filter as default",id:"toggleFilterDefault",glyph:N?"ng-x-close":"ng-check",divider:L})};return this.editMode?(t||y.push({type:"custom",label:"Ask",id:"ask",glyph:"smart-code",method:"fill",color:"#2970ff"}),y.push({type:"custom",label:"Tweak",id:"tweak",glyph:"ng-wand-sparkles",divider:!t}),y.push({type:"custom",label:"Edit",id:"edit",glyph:"ng-edit-02"}),E(!1),S(!1),!M&&r&&y.push({type:"custom",label:r,id:"editDsl",glyph:"ng-code"}),z(!1),y.push({type:"custom",label:"Delete",id:"delete",glyph:"ng-trash-01"}),o&&y.push({type:"custom",label:"Set Alert",id:"setAlert",glyph:"ng-bell-01",divider:!0}),a&&y.push({type:"custom",label:"Add to Story",id:"addToStory",glyph:"ng-book-open-text"}),D&&y.push({type:"custom",label:c?"Remove forecast":"Forecast",id:"forecast",glyph:c?"ng-trending-down":"ng-trend-up-01"}),D&&c&&y.push({type:"custom",label:"Forecast settings\u2026",id:"forecastSettings",glyph:"ng-sliders-horizontal"}),t||(y.push({type:"default",label:"Export PNG",downloadPng:!0,glyph:"ng-image-03",divider:!0}),y.push({type:"default",label:"Export CSV",downloadCsv:!0,glyph:"ng-file-06"}),y.push({type:"default",label:"Print",print:!0,glyph:"ng-printer"})),A={enabled:!0,items:s!=="chart"?s3(y):y}):(t||y.push({type:"custom",label:"Ask",id:"ask",glyph:"smart-code",method:"fill",color:"#2970ff"}),this.showTweakInViewMode&&y.push({type:"custom",label:"Tweak",id:"tweak",glyph:"ng-wand-sparkles",divider:!t}),E(y.length>0),S(y.length>0),this.showEditDslInViewMode&&!M&&r&&y.push({type:"custom",label:r,id:"editDsl",glyph:"ng-code"}),z(y.length>0),o&&y.push({type:"custom",label:"Set Alert",id:"setAlert",glyph:"ng-bell-01",divider:y.length>0}),a&&y.push({type:"custom",label:"Add to Story",id:"addToStory",glyph:"ng-book-open-text",divider:!o&&y.length>0}),D&&y.push({type:"custom",label:c?"Remove forecast":"Forecast",id:"forecast",glyph:c?"ng-trending-down":"ng-trend-up-01"}),D&&c&&y.push({type:"custom",label:"Forecast settings\u2026",id:"forecastSettings",glyph:"ng-sliders-horizontal"}),t||(y.push({type:"default",label:"Export PNG",downloadPng:!0,glyph:"ng-image-03",divider:y.length>0}),y.push({type:"default",label:"Export CSV",downloadCsv:!0,glyph:"ng-file-06"}),y.push({type:"default",label:"Print",print:!0,glyph:"ng-printer"})),A={enabled:y.length>0,items:s!=="chart"?s3(y):y}),this.menuCache.set(I,A),A}onMenuAction(e,t){switch(t){case"ask":this.chartWidgets?.find(M=>M.widgetId===e.id)?.openAiChat();break;case"tweak":this.openTweak(e.id);break;case"edit":this.editWidget.emit(e.id);break;case"editDsl":this.openDslEditor(e.id);break;case"changeChartType":this.toggleChartTypePicker(e.id);break;case"manageFilters":this.toggleFilterPicker(e.id);break;case"customizeColors":this.toggleColorPicker(e.id);break;case"toggleFilterDefault":this.toggleFilterDefault(e);break;case"viewData":this.setWidgetViewMode(e.id,"data");break;case"viewChart":this.setWidgetViewMode(e.id,"chart");break;case"viewRecords":this.viewRecords(e);break;case"delete":this.remove.emit(e.id);break;case"setAlert":this.setAlert.emit(e);break;case"addToStory":this.addToStory.emit(e);break;case"forecast":this.forecast.emit({widget:e,enable:!this.hasForecast(e)});break;case"forecastSettings":this.openForecastSettings(e.id);break}}drillContextMenu=null;onWidgetBodyClick(e,t){t.target?.closest('button, a, input, select, textarea, nile-checkbox, nile-dropdown, .widget-drag-handle, [role="button"]')||this.widgetClick.emit(e)}onChartClick(e,t){let M=this.hasFilterWidget()?MB({pointName:t.pointName,pointY:t.pointY,seriesName:t.seriesName},e.queryMeta):[],n=this.resolveDrillOptions(e,t);if(n.length===0){!e.drilldownBy?.length&&M.length&&this.addFilterConditions(M);return}if(M.length===0){if(n.length===1){this.drillIntoOption(e.id,t.point,n[0]);return}this.drillContextMenu={widgetId:e.id,x:t.x,y:t.y,options:n,point:t.point,conditions:null};return}this.drillContextMenu={widgetId:e.id,x:t.x,y:t.y,options:n,point:t.point,conditions:M}}resolveDrillOptions(e,t){if(!e.drilldownBy?.length)return[];let n=e.config.chart?.data?.find(r=>r.name===t.pointName)?.drilldown;return n?e.drilldownBy.flatMap(r=>(r.series??[]).filter(o=>o.id===n)):[]}pickDrillOption(e){let t=this.drillContextMenu;t&&(this.drillIntoOption(t.widgetId,t.point,e),this.drillContextMenu=null)}pickAddAsFilter(){let e=this.drillContextMenu;this.drillContextMenu=null,e?.conditions?.length&&this.addFilterConditions(e.conditions)}closeDrillContextMenu(){this.drillContextMenu=null}drillIntoOption(e,t,M){this.chartWidgets?.find(n=>n.widgetId===e)?.drillIntoSeries(t,{id:M.id,name:M.drillDownName,data:M.data,type:M.type})}onAiSend(e){this.aiSend.emit(e)}onCellFilter(e,t){this.addFilterConditions([{field:t.field,op:"==",value:t.value}])}onChartSelection(e,t){let M=this.firstFilterWidget();if(!M)return;let n=this.timeWindowField(e);if(!n){console.warn("[dashboard-filter] zoom ignored: no date field resolvable for widget",e.id,e.title);return}let r={field:n,op:"between",value:[new Date(t.min).toISOString(),new Date(t.max).toISOString()]},a=[...fm(this.resolvedFilters??[]).filter(l=>l.field!==n),r],s=wI(a);this.setManualState(M.id,{mode:"manual",conditions:a}),this.chartWidgetFor(M.id)?.setFilterExpression(s),this.applyExpression(M,s),this.requestCatalog(M)}onChartSelectionReset(e){let t=this.firstFilterWidget();if(!t)return;let M=this.manualStateFor(t.id),n=M.mode==="manual"&&M.conditions.length?M.conditions:fm(this.resolvedFilters??[]),r=this.timeWindowField(e),o=r?n.filter(a=>a.field!==r):[];o.length!==n.length&&(this.setManualState(t.id,{mode:"manual",conditions:o}),this.chartWidgetFor(t.id)?.setFilterExpression(wI(o)),this.applyManualConditions(t),o.length||this.collapseExpandedFilter())}timeWindowField(e){return this.dateHistogramField(e)??cat(e.queryMeta)??this.catalogDateField(e)}catalogDateField(e){return this.ephemeralFilterFieldsCache.get(this.ephemeralKey(e))?.find(M=>M.type==="date")?.name??null}dateHistogramField(e){let t=null,M=n=>{if(!(t||!n||typeof n!="object")){if(Array.isArray(n)){n.forEach(M);return}for(let[r,o]of Object.entries(n)){if((r==="date_histogram"||r==="auto_date_histogram")&&o&&typeof o=="object"&&typeof o.field=="string"){t=o.field;return}M(o)}}};return M(e.queryMeta?.dsl),t}onFilterSubmit(e){if(e.widgetId){let t=Object.values(e.filters??{}),M=t.length===1&&typeof t[0]=="string"?t[0]:null;this.lastAppliedFilter.set(e.widgetId,t.length===0?"":(M??JSON.stringify(e.filters)).trim())}this.filterSubmit.emit(e)}onFilterChange(e){this.filterChange.emit(e)}chartWidgets;patchFilterSuggestions(e,t,M){this.observedFields.set(this.observed.fields()),this.filterCatalogs.update(r=>new Map(r).set(e,[...M])),this.chartWidgets?.find(r=>r.widgetId===e)?.patchControlSuggestions(t,this.rankCatalogForExpression(M))}rankCatalogForExpression(e){let t=e.filter(r=>r.type==="attribute"&&K2(r)),M=e.filter(r=>r.type!=="attribute");return[...e3(t,{onDashboard:this.observedFields(),recentlyUsed:this.recentlyUsedFields()}),...M]}openTweak(e){this.tweakTargetId=e,this.tweakPromptText="",this.tweakSubmitting=!1}useTweakExample(e){this.tweakPromptText=e}closeTweak(){this.tweakTargetId=null,this.tweakPromptText="",this.tweakSubmitting=!1}submitTweak(){let e=this.tweakTargetId,t=this.tweakPromptText.trim();!e||!t||this.tweakSubmitting||(this.tweakSubmitting=!0,this.tweakWidget.emit({widgetId:e,prompt:t}),this.closeTweak())}canShowChartTypePicker(e){return!this.showWidgetMenu||this.isFilterWidget(e)?!1:!!this.chartTypeFetcher?.changeAdhoc}canShowColorPicker(e){return!this.showWidgetMenu||this.isFilterWidget(e)?!1:hat(this.displayConfigFor(e))}canShowFilterPicker(e){return!this.showWidgetMenu||this.isFilterWidget(e)?!1:this.dashboardId?!!this.widgetFilterFetcher:!!this.adhocFilterFetcher}toggleChartTypePicker(e){if(this.chartTypePickerWidgetId===e){this.closeChartTypePicker();return}this.openChartTypePicker(e)}menuItemsFor(e){return(this.menuFor(e).items??[]).map(t=>{if(t.type==="custom")return{key:t.id,label:t.label,glyph:t.glyph,divider:t.divider,method:t.method,color:t.color,kind:"custom"};let M=t.downloadPng?"exportPng":t.downloadCsv?"exportCsv":"print";return{key:M,label:t.label??M,glyph:t.glyph,divider:t.divider,kind:M}})}chartMenuFor(e){return this.chartMenuDisabled}chartMenuDisabled={enabled:!1};nileChartElFor(e){return this.chartWidgets?.find(M=>M.widgetId===e)?.chartRef?.nativeElement??null}async runChartAction(e,t){let M=this.nileChartElFor(e.id);try{t==="exportPng"?await M?.exportChart?.("image/png"):t==="exportCsv"?await M?.downloadCsv?.():await M?.printChart?.()}catch{}}menuOpenWidgetId=null;hasOpenOverlay(e){return this.menuOpenWidgetId===e||this.chartTypePickerWidgetId===e||this.filterBuilderWidgetId===e||this.ephemeralFilterBuilderWidgetId===e||this.storyPickerWidgetId===e}closeWidgetMenu(e){if(!e?.hide)return;let t=()=>{e.hide?.()};typeof requestAnimationFrame=="function"?requestAnimationFrame(t):t()}onOwnMenuItem(e,t,M){this.closeWidgetMenu(M),t.kind==="custom"?this.onMenuAction(e,t.key):this.runChartAction(e,t.kind)}storyPickerWidgetId=null;storyOptions=[];storyLoading=!1;storySkeletons=Array.from({length:3});storyCommitting=null;storyPickerSeq=0;loadStoriesFor(e){this.storyPickerWidgetId!==e&&this.openStoryPicker(e)}async openStoryPicker(e){this.storyPickerWidgetId=e,this.storyOptions=[],this.storyLoading=!0;let t=++this.storyPickerSeq;this.cdr?.markForCheck();try{let M=await this.storiesFetcher?.listStories()??[];if(t!==this.storyPickerSeq)return;this.storyOptions=M}catch{t===this.storyPickerSeq&&(this.storyOptions=[])}finally{t===this.storyPickerSeq&&(this.storyLoading=!1,this.cdr?.markForCheck())}}closeStoryPicker(){this.storyPickerWidgetId=null,this.storyOptions=[],this.storyLoading=!1,this.storyCommitting=null,this.cdr?.markForCheck()}async chooseStory(e){let t=this.widgets.find(M=>M.id===this.storyPickerWidgetId);if(!(!this.storiesFetcher||!t||this.storyCommitting)){this.storyCommitting=e??"new",this.cdr?.markForCheck();try{let M=e??(await this.storiesFetcher.createStory(t.title??"")).id;if(!M)throw new Error("no story id");NB({storyId:M,widget:t,source:{kind:"dashboard",label:t.title??"Widget"}}),this.closeStoryPicker(),await this.router?.navigate(["/stories",M],{queryParams:{mode:"edit"}})}catch{this.storyCommitting=null,this.cdr?.markForCheck()}}}toggleFilterPicker(e){if(this.dashboardId){if(this.filterBuilderWidgetId===e){this.closeFilterBuilder();return}this.openFilterBuilder(e)}else{if(this.ephemeralFilterBuilderWidgetId===e){this.closeEphemeralFilterBuilder();return}this.openEphemeralFilterBuilder(e)}}chartTypePickerWidgetId=null;chartTypeOptions=[];chartTypeLoading=!1;chartTypeApplying=!1;chartTypeError=null;chartTypePickerSeq=0;chartTypeIcon(e){return a3(e)}sensibleChartTypes(){return this.chartTypeOptions.filter(e=>e.sensible)}otherChartTypes(){return this.chartTypeOptions.filter(e=>!e.sensible)}async openChartTypePicker(e){let t=this.widgets.find(n=>n.id===e);if(!t||!this.chartTypeFetcher)return;let M=++this.chartTypePickerSeq;this.chartTypePickerWidgetId=e,this.chartTypeOptions=[],this.chartTypeError=null,this.chartTypeLoading=!0,this.cdr?.markForCheck();try{let n=await this.chartTypeFetcher.list(t);if(M!==this.chartTypePickerSeq)return;this.chartTypeOptions=n}catch(n){if(M!==this.chartTypePickerSeq)return;this.chartTypeError=n instanceof Error?n.message:"Could not load chart types"}finally{M===this.chartTypePickerSeq&&(this.chartTypeLoading=!1),this.cdr?.markForCheck()}}closeChartTypePicker(){this.chartTypePickerWidgetId=null,this.chartTypeOptions=[],this.chartTypeLoading=!1,this.chartTypeApplying=!1,this.chartTypeApplyingComponent=null,this.chartTypeError=null}colorPickerWidgetId=null;colorPickerSeries(){let e=this.colorPickerWidgetId?this.widgets.find(t=>t.id===this.colorPickerWidgetId):null;return e?zat(this.displayConfigFor(e))??[]:[]}toggleColorPicker(e){if(this.colorPickerWidgetId===e){this.closeColorPicker();return}this.colorPickerWidgetId=e}closeColorPicker(){this.colorPickerWidgetId=null}selectSeriesColor(e,t){let M=this.colorPickerWidgetId,n=M?this.widgets.find(s=>s.id===M):null;if(!n)return;let r=this.ephemeralKey(n),o=this.displayConfigFor(n),a=xat(o,e,t);this.ephemeralChartOverride.set(r,{componentName:n.componentName??"",config:a}),this.cdr?.markForCheck(),this.widgetColorChanged.emit(_(x({},n),{config:a}))}chartTypeApplyingComponent=null;async selectChartType(e){let t=this.chartTypePickerWidgetId,M=t?this.widgets.find(r=>r.id===t):null,n=this.chartTypeFetcher?.changeAdhoc;if(!(!M||!n||this.chartTypeApplying)){this.chartTypeApplying=!0,this.chartTypeApplyingComponent=e,this.chartTypeError=null;try{let r=this.ephemeralKey(M),o=await n(M,e);this.ephemeralChartOverride.set(r,{componentName:o.componentName??e,config:o.config}),this.ephemeralFilters.delete(r),this.ephemeralFilterFieldsCache.delete(r),this.ephemeralFilterBaseConfig.delete(r),this.ephemeralFilterResult.delete(r),this.closeChartTypePicker()}catch(r){this.chartTypeError=r instanceof Error?r.message:"Chart type change failed"}finally{this.chartTypeApplying=!1,this.chartTypeApplyingComponent=null,this.cdr?.markForCheck()}}}filterBuilderWidgetId=null;filterBuilderField="";filterBuilderOperation="";filterBuilderValue="";filterBuilderValue2="";filterBuilderValues=[];filterBuilderApplying=!1;filterBuilderRemovingId=null;filterBuilderError=null;filterBuilderWidget(){let e=this.filterBuilderWidgetId;return e?this.widgets.find(t=>t.id===e)??null:null}filterBuilderFields(){let e=this.filterBuilderWidget();return e?this.ephemeralFilterFieldsCache.get(this.ephemeralKey(e))??[]:[]}filterBuilderSelectedField(){return this.filterBuilderFields().find(e=>e.name===this.filterBuilderField)}filterBuilderOperators(){let e=this.filterBuilderSelectedField();return e?ZD(e.type):[]}filterBuilderSelectedOperator(){return this.filterBuilderOperators().find(e=>e.value===this.filterBuilderOperation)}filterBuilderActiveFilters(){let t=this.filterBuilderWidget()?.config?._meta?.filters;return Array.isArray(t)?t:[]}resetFilterBuilderValues(){this.filterBuilderValue="",this.filterBuilderValue2="",this.filterBuilderValues=[]}async openFilterBuilder(e){this.filterBuilderWidgetId=e,this.resetFilterBuilderValues(),this.filterBuilderError=null,this.ephemeralFilterFieldsError=null,this.filterBuilderApplying=!1,this.filterBuilderRemovingId=null;let t=this.widgets.find(r=>r.id===e)??null,M=t?this.ephemeralKey(t):null;if(t&&M&&!this.ephemeralFilterFieldsCache.has(M)&&this.adhocFilterFetcher){this.ephemeralFilterFieldsLoading=!0,this.cdr?.markForCheck();try{let r=await this.adhocFilterFetcher.listFields([t]);this.ephemeralFilterFieldsCache.set(M,r)}catch(r){this.ephemeralFilterFieldsError=r instanceof Error?r.message:"Could not load filter fields"}finally{this.ephemeralFilterFieldsLoading=!1,this.cdr?.markForCheck()}}let n=this.filterBuilderFields()[0];this.filterBuilderField=n?.name??"",this.filterBuilderOperation=n?ZD(n.type)[0].value:"",t&&n&&this.ensureFilterValuesLoaded(t,n),this.cdr?.markForCheck()}closeFilterBuilder(){this.filterBuilderWidgetId=null,this.filterBuilderField="",this.filterBuilderOperation="",this.resetFilterBuilderValues(),this.filterBuilderError=null,this.filterBuilderApplying=!1,this.filterBuilderRemovingId=null}onFilterBuilderFieldChange(e){this.filterBuilderField=e;let t=this.filterBuilderFields().find(n=>n.name===e);this.filterBuilderOperation=t?ZD(t.type)[0].value:"",this.resetFilterBuilderValues();let M=this.filterBuilderWidget();M&&t&&this.ensureFilterValuesLoaded(M,t)}onFilterBuilderOperatorChange(e){this.filterBuilderOperation=e,this.resetFilterBuilderValues()}toggleFilterBuilderMultiValue(e){let t=this.filterBuilderValues.indexOf(e);t>=0?this.filterBuilderValues.splice(t,1):this.filterBuilderValues.push(e)}async submitFilterBuilder(){let e=this.filterBuilderWidget(),t=this.filterBuilderField,M=this.filterBuilderOperation;if(!e||!this.widgetFilterFetcher||!this.dashboardId||!t||!M||this.filterBuilderApplying)return;let n=this.filterBuilderOperators().find(o=>o.value===M);if(!n)return;let r;if(n.valueKind==="none")r={id:"",fieldId:t,operator:M};else if(n.valueKind==="multi-select"){if(this.filterBuilderValues.length===0)return;r={id:"",fieldId:t,operator:M,values:[...this.filterBuilderValues]}}else{let o=this.filterBuilderValue.trim();if(!o)return;let a=n.needsSecondValue?this.filterBuilderValue2.trim():void 0;if(n.needsSecondValue&&!a)return;r={id:"",fieldId:t,operator:M,value:o,value2:a}}this.filterBuilderApplying=!0,this.filterBuilderError=null;try{let o=await this.widgetFilterFetcher.add(this.dashboardId,e.id,Cm(r),this.persistToPublished);this.widgetFiltersChanged.emit(o),this.resetFilterBuilderValues()}catch(o){this.filterBuilderError=o instanceof Error?o.message:"Filter could not be applied"}finally{this.filterBuilderApplying=!1,this.cdr?.markForCheck()}}async removeFilterFromBuilder(e){let t=this.filterBuilderWidgetId,M=t?this.widgets.find(n=>n.id===t):null;if(!(!M||!this.widgetFilterFetcher||!this.dashboardId||this.filterBuilderRemovingId)){this.filterBuilderRemovingId=e,this.filterBuilderError=null;try{let n=await this.widgetFilterFetcher.remove(this.dashboardId,M.id,e,this.persistToPublished);this.widgetFiltersChanged.emit(n)}catch(n){this.filterBuilderError=n instanceof Error?n.message:"Filter could not be removed"}finally{this.filterBuilderRemovingId=null,this.cdr?.markForCheck()}}}ephemeralFilterBuilderWidgetId=null;ephemeralFilterBuilderFieldId=null;ephemeralFilterBuilderOperator=null;ephemeralFilterBuilderValue="";ephemeralFilterBuilderValue2="";ephemeralFilterBuilderValues=[];ephemeralFilterFieldsLoading=!1;ephemeralFilterFieldsError=null;ephemeralFilterValuesLoading=!1;ephemeralFilterApplying=!1;ephemeralFilterApplyError=null;toggleEphemeralFilterMultiValue(e){let t=this.ephemeralFilterBuilderValues.indexOf(e);t>=0?this.ephemeralFilterBuilderValues.splice(t,1):this.ephemeralFilterBuilderValues.push(e)}ephemeralFilterWidget(){let e=this.ephemeralFilterBuilderWidgetId;return e?this.widgets.find(t=>t.id===e)??null:null}async openEphemeralFilterBuilder(e){this.ephemeralFilterBuilderWidgetId=e,this.ephemeralFilterApplyError=null,this.ephemeralFilterFieldsError=null;let t=this.ephemeralFilterWidget(),M=t?this.ephemeralKey(t):null;if(t&&M&&!this.ephemeralFilterFieldsCache.has(M)&&this.adhocFilterFetcher){this.ephemeralFilterFieldsLoading=!0,this.cdr?.markForCheck();try{let r=await this.adhocFilterFetcher.listFields([t]);this.ephemeralFilterFieldsCache.set(M,r)}catch(r){this.ephemeralFilterFieldsError=r instanceof Error?r.message:"Could not load filter fields"}finally{this.ephemeralFilterFieldsLoading=!1,this.cdr?.markForCheck()}}let n=this.ephemeralFilterFields()[0];this.ephemeralFilterBuilderFieldId=n?.name??null,this.ephemeralFilterBuilderOperator=n?ZD(n.type)[0].value:null,this.resetEphemeralFilterBuilderValues(),t&&n&&this.ensureFilterValuesLoaded(t,n)}closeEphemeralFilterBuilder(){this.ephemeralFilterBuilderWidgetId=null}resetEphemeralFilterBuilderValues(){this.ephemeralFilterBuilderValue="",this.ephemeralFilterBuilderValue2="",this.ephemeralFilterBuilderValues=[]}ephemeralFilterFields(){let e=this.ephemeralFilterWidget();return e?this.ephemeralFilterFieldsCache.get(this.ephemeralKey(e))??[]:[]}ephemeralFilterSelectedField(){return this.ephemeralFilterFields().find(e=>e.name===this.ephemeralFilterBuilderFieldId)}async ensureFilterValuesLoaded(e,t){let M=`${this.ephemeralKey(e)}::${t.name}`;if(!(!r3(t.type)||this.filterValuesCache.has(M)||!this.adhocFilterFetcher)){this.ephemeralFilterValuesLoading=!0,this.cdr?.markForCheck();try{let n=await this.adhocFilterFetcher.fetchValues([e],t.name);this.filterValuesCache.set(M,n.values)}catch{this.filterValuesCache.set(M,[])}finally{this.ephemeralFilterValuesLoading=!1,this.cdr?.markForCheck()}}}filterValuesFor(e,t){return!e||!t?[]:this.filterValuesCache.get(`${this.ephemeralKey(e)}::${t}`)??[]}onEphemeralFilterFieldChange(e){this.ephemeralFilterBuilderFieldId=e;let t=this.ephemeralFilterFields().find(n=>n.name===e);this.ephemeralFilterBuilderOperator=t?ZD(t.type)[0].value:null,this.resetEphemeralFilterBuilderValues();let M=this.ephemeralFilterWidget();M&&t&&this.ensureFilterValuesLoaded(M,t)}onEphemeralFilterOperatorChange(e){this.ephemeralFilterBuilderOperator=e,this.resetEphemeralFilterBuilderValues()}ephemeralFilterOperators(){let e=this.ephemeralFilterSelectedField();return e?ZD(e.type):[]}ephemeralFilterSelectedOperator(){return this.ephemeralFilterOperators().find(e=>e.value===this.ephemeralFilterBuilderOperator)}ephemeralFilterActiveFilters(){let e=this.ephemeralFilterWidget();return e?this.ephemeralFilters.get(this.ephemeralKey(e))??[]:[]}ephemeralFilterChipLabel(e){let t=this.ephemeralFilterFields().find(M=>M.name===e.fieldId);return o3(e,t?.label??e.fieldId,t?.type??"string")}async reapplyEphemeralFilters(e,t,M){if(!this.adhocFilterFetcher)return!1;if(!M.length)return this.ephemeralFilterResult.delete(t),this.ephemeralFilterBaseConfig.delete(t),!0;let n=this.ephemeralChartOverride.get(t),r=this.ephemeralFilterBaseConfig.get(t)??_(x({},e),{componentName:n?.componentName??e.componentName,config:n?.config??e.config});this.ephemeralFilterApplying=!0,this.ephemeralFilterApplyError=null,this.cdr?.markForCheck();try{let o=M.map(Cm),a=await this.adhocFilterFetcher.apply(r,o);return this.ephemeralFilterBaseConfig.set(t,r),this.ephemeralFilterResult.set(t,a),!0}catch(o){return this.ephemeralFilterApplyError=o instanceof Error?o.message:"Filter could not be applied",!1}finally{this.ephemeralFilterApplying=!1,this.cdr?.markForCheck()}}async addEphemeralFilter(){let e=this.ephemeralFilterWidget(),t=this.ephemeralFilterBuilderFieldId,M=this.ephemeralFilterBuilderOperator;if(!e||!t||!M||this.ephemeralFilterApplying)return;let n=this.ephemeralFilterOperators().find(l=>l.value===M);if(!n)return;let r;if(n.valueKind==="none")r={id:`ef${++this.ephemeralFilterSeq}`,fieldId:t,operator:M};else if(n.valueKind==="multi-select"){if(this.ephemeralFilterBuilderValues.length===0)return;r={id:`ef${++this.ephemeralFilterSeq}`,fieldId:t,operator:M,values:[...this.ephemeralFilterBuilderValues]}}else{let l=this.ephemeralFilterBuilderValue.trim();if(!l)return;let N=n.needsSecondValue?this.ephemeralFilterBuilderValue2.trim():void 0;if(n.needsSecondValue&&!N)return;r={id:`ef${++this.ephemeralFilterSeq}`,fieldId:t,operator:M,value:l,value2:N}}let o=this.ephemeralKey(e),a=[...this.ephemeralFilters.get(o)??[],r];await this.reapplyEphemeralFilters(e,o,a)&&(this.ephemeralFilters.set(o,a),this.resetEphemeralFilterBuilderValues(),this.cdr?.markForCheck())}async removeEphemeralFilter(e){let t=this.ephemeralFilterWidget();if(!t||this.ephemeralFilterApplying)return;let M=this.ephemeralKey(t),n=(this.ephemeralFilters.get(M)??[]).filter(o=>o.id!==e);await this.reapplyEphemeralFilters(t,M,n)&&(n.length?this.ephemeralFilters.set(M,n):this.ephemeralFilters.delete(M),this.cdr?.markForCheck())}async clearEphemeralFilters(){let e=this.ephemeralFilterWidget();if(!e||this.ephemeralFilterApplying)return;let t=this.ephemeralKey(e);await this.reapplyEphemeralFilters(e,t,[]),this.ephemeralFilters.delete(t),this.cdr?.markForCheck()}quickTimePresets=yat;async applyQuickTimeFilter(e,t){let M=this.timeWindowField(e);if(!M)return;if(this.dashboardId){if(!this.widgetFilterFetcher||this.filterBuilderApplying)return;this.filterBuilderApplying=!0,this.filterBuilderError=null;try{let{from:s,to:l}=oB(t),N=await this.widgetFilterFetcher.add(this.dashboardId,e.id,{field:M,operation:"between",value:[s,l]},this.persistToPublished);this.widgetFiltersChanged.emit(N)}catch(s){this.filterBuilderError=s instanceof Error?s.message:"Filter could not be applied"}finally{this.filterBuilderApplying=!1,this.cdr?.markForCheck()}return}let n=this.ephemeralKey(e),r={id:`ef${++this.ephemeralFilterSeq}`,fieldId:M,operator:t},o=[...this.ephemeralFilters.get(n)??[],r];await this.reapplyEphemeralFilters(e,n,o)&&(this.ephemeralFilters.set(n,o),this.cdr?.markForCheck())}dslEditorWidgetId=null;dslQueryText="";dslPromptText="";dslGenerating=!1;dslApplying=!1;dslError=null;dslBaselineText="";dslTurns=[];dslPendingPrompt=null;dslValidity={ok:!1,error:"Query is empty"};dslExpandedTurn=-1;dslCopied=!1;dslCopiedTimer=null;dslDevMode=!1;toggleDslDevMode(){this.dslDevMode=!this.dslDevMode}forecastSettingsWidgetId=null;forecastDraft=null;forecastGranularities=["Weekly","Monthly","Quarterly","Yearly"];forecastConfidences=[80,90,95];get forecastSettingsWidget(){return this.widgets.find(e=>e.id===this.forecastSettingsWidgetId)??null}get forecastMaxHorizon(){let e=String(this.forecastSettingsWidgetId??"");return this.forecastable[e]?.maxHorizon??24}get forecastPeriodWord(){return{Weekly:"week",Monthly:"month",Quarterly:"quarter",Yearly:"year"}[this.forecastDraft?.granularity??"Monthly"]??"period"}get forecastProvenance(){let e=this.forecastSettingsWidget?.config?.forecast;if(!e?.enabled)return null;let t=[];e.modelFamily&&t.push({label:"Model",value:String(e.modelFamily)});let M=e.historyWindow?.points;if(Number.isFinite(M)){let a={Weekly:"weeks",Monthly:"months",Quarterly:"quarters",Yearly:"years"}[e.granularity]??"periods";t.push({label:"History",value:`${M} ${a}`})}if(Number.isFinite(e.typicalError)?t.push({label:"Typical error",value:`${Number(e.typicalError).toFixed(2)} MASE`}):t.push({label:"Typical error",value:"not scored \u2014 too little history to backtest"}),Number.isFinite(e.vsNaive)){let o=Math.round(Math.abs(Number(e.vsNaive))*100),a=Number(e.vsNaive)>=0?`${o}% better`:`${o}% worse`,s=Number.isFinite(e.naiveMase)?` (${e.naiveKey==="snaive"?"seasonal naive":"naive"} scores ${Number(e.naiveMase).toFixed(2)})`:"";t.push({label:"vs naive",value:`${a}${s}`})}e.boundaryPeriod&&t.push({label:"From",value:String(e.boundaryPeriod)});let n=Array.isArray(e.seriesSkipped)?e.seriesSkipped:[],r=Array.isArray(e.seriesForecast)?e.seriesForecast.length:0;if(n.length&&t.push({label:"Series",value:`${r} of ${r+n.length} forecast`}),e.lastComputedAt){let o=new Date(e.lastComputedAt);Number.isNaN(o.getTime())||t.push({label:"Computed",value:o.toLocaleString(void 0,{day:"numeric",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit"})})}return t.length?t:null}openForecastSettings(e){let M=this.widgets.find(n=>n.id===e)?.config?.forecast??{};this.forecastSettingsWidgetId=e,this.forecastDraft={horizon:Number(M.horizon)||6,granularity:String(M.granularity||"Monthly"),confidence:Number(M.confidence)||80}}closeForecastSettings(){this.forecastSettingsWidgetId=null,this.forecastDraft=null}onForecastHorizon(e){if(!this.forecastDraft)return;let t=Math.max(1,Math.min(this.forecastMaxHorizon,Math.floor(Number(e)||1)));this.forecastDraft=_(x({},this.forecastDraft),{horizon:t})}onForecastGranularity(e){this.forecastDraft&&(this.forecastDraft=_(x({},this.forecastDraft),{granularity:e}))}onForecastConfidence(e){this.forecastDraft&&(this.forecastDraft=_(x({},this.forecastDraft),{confidence:e}))}applyForecastSettings(){let e=this.forecastSettingsWidget,t=this.forecastDraft;!e||!t||(this.forecast.emit({widget:e,enable:!0,settings:x({},t)}),this.closeForecastSettings())}openDslEditor(e){let t=this.widgets.find(o=>o.id===e);this.dslEditorWidgetId=e;let M=this.dslCodeEditorLanguage,n=t?.queryMeta?.sql,r=n&&km(n,M)||n||"";this.dslQueryText=r,this.dslBaselineText=r,this.dslPromptText="",this.dslPendingPrompt=null,this.dslTurns=[],this.dslExpandedTurn=-1,this.dslGenerating=!1,this.dslApplying=!1,this.dslError=null,this.dslValidity=wj(r,M),this.dslDevMode=!1}get dslEditorWidget(){return this.widgets.find(e=>e.id===this.dslEditorWidgetId)??null}get dslChartTypeLabel(){let e=this.dslEditorWidget?.config?.chart?.type;return e?CZt[e]??`${e.charAt(0).toUpperCase()}${e.slice(1)} chart`:""}get dslCodeEditorLanguage(){let e=this.dslEditorWidget?.queryMeta?.adapterType;return e==="postgres"||e==="mssql"?"sql":"json"}static DSL_TERM_BY_ADAPTER={mssql:"SQL",postgres:"query"};dslTermFor(e){return e&&i.DSL_TERM_BY_ADAPTER[e]||"DSL"}dslMenuLabelFor(e){let t=e.queryMeta?.adapterType;return`Edit ${this.dslTermFor(t)}`}get dslTerm(){return this.dslTermFor(this.dslEditorWidget?.queryMeta?.adapterType)}get dslDirty(){return this.dslQueryText!==this.dslBaselineText}onDslTextChange(e){this.dslQueryText=e,this.dslValidity=wj(e,this.dslCodeEditorLanguage)}formatDslQuery(){let e=km(this.dslQueryText,this.dslCodeEditorLanguage);e!==null&&this.onDslTextChange(e)}async copyDslQuery(){try{await navigator.clipboard.writeText(this.dslQueryText),this.dslCopied=!0,this.dslCopiedTimer&&clearTimeout(this.dslCopiedTimer),this.dslCopiedTimer=setTimeout(()=>{this.dslCopied=!1,this.cdr?.markForCheck()},1500)}catch{}this.cdr?.markForCheck()}resetDslQuery(){this.dslQueryText=this.dslBaselineText,this.dslValidity=wj(this.dslBaselineText,this.dslCodeEditorLanguage),this.dslTurns=[],this.dslExpandedTurn=-1,this.dslError=null}toggleDslDiff(e){this.dslExpandedTurn=this.dslExpandedTurn===e?-1:e}undoDslTurn(e){let t=this.dslTurns[e];t&&(this.dslQueryText=t.before,this.dslValidity=wj(t.before,this.dslCodeEditorLanguage),this.dslTurns=this.dslTurns.slice(0,e),this.dslExpandedTurn=-1,this.dslError=null)}closeDslEditor(){this.dslApplying||!this.dslCloseAllowed()||this.resetDslEditorState()}onDslRequestClose(e){if(e.stopPropagation(),this.dslApplying||!this.dslCloseAllowed()){e.preventDefault();return}this.resetDslEditorState()}onDslDrawerHidden(){this.dslEditorWidgetId===null||this.dslApplying||(this.resetDslEditorState(),this.cdr?.markForCheck())}dslCloseAllowed(){return!this.dslDirty||typeof window>"u"?!0:window.confirm("Discard your unapplied changes to this query?")}onDslComposerSubmit(e){typeof e=="string"&&(this.dslPromptText=e),this.generateDsl()}dslRefFor(e){if(this.dashboardId&&e.id)return{widgetId:e.id};let t=e.config?.chart;return{componentName:e.componentName,type:t?.type,title:e.title,originalWidget:e}}async generateDsl(){let e=this.dslEditorWidget,t=this.dslPromptText.trim();if(!e||!t||this.dslGenerating||this.dslApplying||!this.dslEditorFetcher)return;let M=this.dslRefFor(e);if(!M)return;if(t.length>Oat){this.dslError=`That instruction is too long (${t.length} of ${Oat} characters).`;return}let n=this.dslQueryText;this.dslPromptText="",this.dslPendingPrompt=t,this.dslGenerating=!0,this.dslError=null;try{let r=this.dslTurns[this.dslTurns.length-1],o=await this.dslEditorFetcher.generate(M,t,{currentQuery:n,lastTurn:r?{prompt:r.prompt,summary:r.summary}:void 0}),a=km(o.sql,this.dslCodeEditorLanguage)??o.sql;this.dslQueryText=a,this.dslValidity=wj(a,this.dslCodeEditorLanguage);let s=lB(n,a),l=gB(s),N=o.wasModified===!0,D=o.summary??(N?"Updated the query.":"The assistant made no changes to the query.");this.dslTurns=[...this.dslTurns,{prompt:t,before:n,after:a,summary:D,wasModified:N,diff:s,changed:l}],this.dslExpandedTurn=-1}catch(r){this.dslError=r instanceof Error?r.message:"DSL generation failed",this.dslPromptText=t}finally{this.dslPendingPrompt=null,this.dslGenerating=!1,this.cdr?.markForCheck()}}async applyDsl(){let e=this.dslEditorWidget;if(!e||this.dslApplying||this.dslGenerating||!this.dslEditorFetcher)return;let t=this.dslRefFor(e);if(!t||!this.dslDirty)return;let M=wj(this.dslQueryText,this.dslCodeEditorLanguage);if(!M.ok){this.dslError=M.error;return}this.dslApplying=!0,this.dslError=null;try{let n=await this.dslEditorFetcher.apply(t,this.dslQueryText);this.dslWidgetUpdated.emit(n),this.closeDslEditorForce()}catch(n){this.dslError=n instanceof Error?n.message:"Apply failed"}finally{this.dslApplying=!1,this.cdr?.markForCheck()}}closeDslEditorForce(){this.resetDslEditorState()}resetDslEditorState(){let e=this.dslEditorWidgetId!==null;this.dslEditorWidgetId=null,this.dslPromptText="",this.dslPendingPrompt=null,this.dslQueryText="",this.dslBaselineText="",this.dslTurns=[],this.dslExpandedTurn=-1,this.dslError=null,this.dslCopied=!1,this.dslDevMode=!1,this.dslCopiedTimer&&(clearTimeout(this.dslCopiedTimer),this.dslCopiedTimer=null),e&&this.dslEditorClosed.emit()}syncGridsterItems(){let e=new Map;for(let t of this.gridsterItems)e.set(t.widgetId,t);this.gridsterItems=this.widgets.map(t=>{let M=e.get(t.id),n=t.layout,r=n?this.clampItemGeometry(n,t):null;return M&&r&&(M.x!==r.x||M.y!==r.y||M.cols!==r.cols||M.rows!==r.rows+this.expandedExtraRowsFor(t.id))?this.buildItem(t):M??this.buildItem(t)})}static HEADER_ALLOWANCE_PX=110;minRowsForDeclaredHeight(e,t){let M=e.config?.chart?.height;if(typeof M!="string")return t;let n=parseInt(M,10);if(!Number.isFinite(n)||n<=0)return t;let r=Math.ceil((n+i.HEADER_ALLOWANCE_PX)/72);return Math.max(t,r)}computeRowInflationOffsets(){let t=new Map,M=new Array(12).fill(0),n=this.widgets.filter(r=>!!r.layout).sort((r,o)=>r.layout.y-o.layout.y);for(let r of n){let o=Math.max(0,Math.min(r.layout.x,11)),a=Math.max(1,Math.min(r.layout.w,12-o)),s=0;for(let I=o;I<o+a;I++)s=Math.max(s,M[I]);let l=r.layout.y+s,N=r.layout.h,D=this.minRowsForDeclaredHeight(r,N);t.set(r.id,{y:l,rows:D});let c=s+(D-N);for(let I=o;I<o+a;I++)M[I]=Math.max(M[I],c)}return t}clampItemGeometry(e,t){let M=Math.max(1,Math.min(e.w,12)),n=Math.max(0,Math.min(e.x,12-M));if(!t)return{x:n,y:e.y,cols:M,rows:e.h};let r=this.computeRowInflationOffsets().get(t.id);return{x:n,y:r?.y??e.y,cols:M,rows:r?.rows??this.minRowsForDeclaredHeight(t,e.h)}}buildItem(e){let t=e.widgetType==="kpi"?4:6,M=e.widgetType==="kpi"?2:4,n=e.layout??{x:0,y:0,w:t,h:M},{x:r,y:o,cols:a,rows:s}=this.clampItemGeometry(n,e);return x({x:r,y:o,cols:a,rows:s+this.expandedExtraRowsFor(e.id),minItemCols:2,minItemRows:2,widgetId:e.id},this.isFilterWidget(e)?{layerIndex:i.FILTER_LAYER_INDEX}:{})}scheduleGestureReconcile(){setTimeout(()=>this.reconcileLayoutAfterGesture(),0)}reconcileLayoutAfterGesture(){let e=this.railShift();for(let t of this.widgets){if(this.isFilterWidget(t))continue;let M=t.id,n=t.layout;if(!n)continue;let r=this.getItemForWidget(t),a=!!e&&Number(n.y??0)>e.y?Number(r.y??0)+e.rows:Number(r.y??0),s={x:r.x,y:a,w:r.cols,h:r.rows-this.expandedExtraRowsFor(M)},l=this.clampItemGeometry(n);l.x===s.x&&l.y===s.y&&l.cols===s.w&&l.rows===s.h||this.updateLayout.emit({id:M,layout:s})}}static \u0275fac=function(t){return new(t||i)(ui(Vo),ui(fj),ui(O2,8),ui(Mm,8),ui(om,8),ui(nm,8),ui(rm,8),ui(am,8),ui(sm,8),ui(wh,8),ui(kl,8),ui(ll,8))};static \u0275cmp=oM({type:i,selectors:[["shared-dashboard-grid"]],viewQuery:function(t,M){if(t&1&&rd(CI,5),t&2){let n;Ic(n=dc())&&(M.chartWidgets=n)}},inputs:{widgets:"widgets",editMode:"editMode",dashboardId:"dashboardId",conversationId:"conversationId",persistToPublished:"persistToPublished",tweakingWidgetId:"tweakingWidgetId",forecastingWidgetId:"forecastingWidgetId",loading:"loading",outerMargin:"outerMargin",widgetsLoading:"widgetsLoading",showTweakInViewMode:"showTweakInViewMode",showEditDslInViewMode:"showEditDslInViewMode",canSetAlert:"canSetAlert",canAddToStory:"canAddToStory",canForecast:"canForecast",forecastable:"forecastable",showWidgetMenu:"showWidgetMenu",selectable:"selectable",selectedWidgetIds:"selectedWidgetIds",dashboardFilters:"dashboardFilters",resolvedFilters:"resolvedFilters",applySummary:"applySummary",filterExplanation:"filterExplanation"},outputs:{remove:"remove",editWidget:"editWidget",openAiBuilder:"openAiBuilder",updateLayout:"updateLayout",aiSend:"aiSend",tweakWidget:"tweakWidget",dslWidgetUpdated:"dslWidgetUpdated",dslEditorClosed:"dslEditorClosed",widgetChartTypeChanged:"widgetChartTypeChanged",widgetFiltersChanged:"widgetFiltersChanged",widgetColorChanged:"widgetColorChanged",filterSubmit:"filterSubmit",filterChange:"filterChange",selectionChange:"selectionChange",setAlert:"setAlert",addToStory:"addToStory",widgetClick:"widgetClick",forecast:"forecast"},features:[Jg([fj]),Ro],decls:57,vars:36,consts:[["widgetMenu",""],[3,"mode","conditions","catalog","expression","busy","valueFetcher"],[1,"canvas-wrap"],["role","status",1,"filter-explanation"],["aria-hidden","true",1,"loading-grid"],["class","empty-state",4,"ngIf"],[3,"options","grid-hidden",4,"ngIf"],["open","","hoist","","placement","bottom-start",1,"drill-context-menu",3,"left","top"],["label","Tweak widget",1,"tweak-dialog",3,"nile-request-close","open"],[1,"tweak-dialog__body"],[1,"tweak-dialog__hint"],[1,"tweak-dialog__examples"],["type","button",1,"tweak-dialog__example"],["rows","4","placeholder","Describe the tweak\u2026","autofocus","",1,"tweak-dialog__input",3,"ngModelChange","ngModel"],["slot","footer",1,"tweak-dialog__footer"],["variant","secondary","size","small",3,"click"],["variant","primary","size","small",3,"click"],["label","Edit DSL query","placement","end",1,"dsl-editor-drawer",3,"nile-request-close","nile-hide","open","preventOverlayClose"],["slot","label",1,"dsl-editor-drawer__label"],[1,"dsl-editor-drawer__title-row"],[1,"dsl-editor-drawer__title"],[1,"dsl-editor-drawer__badge"],["slot","header-actions",1,"dsl-editor-drawer__header-actions"],["variant","secondary","size","small"],["slot","prefix","method","stroke","size","14"],["role","alert",1,"dsl-pane__error","dsl-pane__error--global"],[1,"dsl-editor-drawer__body"],[1,"dsl-pane","dsl-pane--query"],[1,"dsl-pane","dsl-pane--assistant"],[1,"dsl-pane__toolbar"],[1,"dsl-pane__toolbar-label"],["name","smart-code","method","fill","size","14","color","#2970ff"],[1,"dsl-pane__toolbar-meta"],[1,"dsl-chat",3,"autoScroll"],[1,"dsl-chat__empty"],[1,"dsl-bubble","dsl-bubble--user",3,"role","message"],[1,"dsl-bubble","dsl-bubble--ai",3,"role","agent","icon","thinking","loading"],["slot","footer",1,"dsl-composer",3,"nile-input","nile-submit","placeholder","value","disabled","maxRows","submitOnEnter"],["slot","footer",1,"dsl-editor-drawer__footer"],[1,"dsl-editor-drawer__footer-note"],[1,"dsl-editor-drawer__footer-actions"],["label","Forecast settings","placement","end",1,"forecast-settings-drawer",3,"nile-request-close","nile-hide","open"],[3,"modeChange","conditionsChange","expressionRun","promptAsk","clearAll","mode","conditions","catalog","expression","busy","valueFetcher"],["name","ng-info-circle","method","stroke","size","16","color","var(--ng-colors-text-tertiary)"],[1,"filter-explanation__text"],[1,"loading-grid__kpis"],[1,"widget-card","sk-card","sk-card--kpi"],[1,"loading-grid__charts"],[1,"widget-card","sk-card","sk-card--chart"],["variant","text","width","65%","height","13"],["variant","text","width","90%","height","10"],["variant","text","width","45%","height","30",1,"sk-card__value"],["variant","text","width","40%","height","15"],["variant","text","width","55%","height","10"],[1,"sk-bars"],["variant","rectangular","width","100%","height","100%",1,"sk-bar",3,"height"],[1,"sk-legend"],["variant","rounded","width","100%","height","11"],["variant","rectangular","width","100%","height","100%",1,"sk-bar"],[1,"empty-state"],[1,"empty-state__graphic",3,"click","keydown.enter","keydown.space"],["viewBox","0 0 380 140","aria-hidden","true","preserveAspectRatio","xMidYMid meet"],["x","40","y","20","width","300","height","100","rx","8","fill","#fff","stroke","#80AED3","stroke-width","1.5","stroke-dasharray","4 4"],["x","56","y","36","width","84","height","68","rx","6","fill","#F7FAFC","stroke","#E6E9EB"],["x","64","y","44","width","40","height","3","rx","1.5","fill","#80AED3"],["x","64","y","80","width","6","height","20","rx","1","fill","#005EA6","opacity","0.7"],["attributeName","height","values","20;14;20","dur","2s","repeatCount","indefinite"],["attributeName","y","values","80;86;80","dur","2s","repeatCount","indefinite"],["x","76","y","74","width","6","height","26","rx","1","fill","#005EA6"],["attributeName","height","values","26;18;26","dur","2s","begin","0.2s","repeatCount","indefinite"],["attributeName","y","values","74;82;74","dur","2s","begin","0.2s","repeatCount","indefinite"],["x","88","y","68","width","6","height","32","rx","1","fill","#005EA6","opacity","0.85"],["attributeName","height","values","32;24;32","dur","2s","begin","0.4s","repeatCount","indefinite"],["attributeName","y","values","68;76;68","dur","2s","begin","0.4s","repeatCount","indefinite"],["x","100","y","78","width","6","height","22","rx","1","fill","#005EA6","opacity","0.6"],["attributeName","height","values","22;16;22","dur","2s","begin","0.6s","repeatCount","indefinite"],["attributeName","y","values","78;84;78","dur","2s","begin","0.6s","repeatCount","indefinite"],["x","112","y","66","width","6","height","34","rx","1","fill","#005EA6","opacity","0.85"],["attributeName","height","values","34;26;34","dur","2s","begin","0.8s","repeatCount","indefinite"],["attributeName","y","values","66;74;66","dur","2s","begin","0.8s","repeatCount","indefinite"],["x","148","y","36","width","84","height","68","rx","6","fill","#F7FAFC","stroke","#E6E9EB"],["x","156","y","44","width","40","height","3","rx","1.5","fill","#80AED3"],["cx","190","cy","78","r","14","fill","none","stroke","#E6EFF6","stroke-width","5"],["cx","190","cy","78","r","14","fill","none","stroke","#005EA6","stroke-width","5","stroke-linecap","round","stroke-dasharray","88","stroke-dashoffset","88","transform","rotate(-90 190 78)"],["attributeName","stroke-dashoffset","values","88;22;22;88","keyTimes","0;0.5;0.85;1","dur","2.6s","repeatCount","indefinite"],["x","240","y","36","width","84","height","68","rx","6","fill","#F7FAFC","stroke","#E6E9EB"],["x","248","y","44","width","40","height","3","rx","1.5","fill","#80AED3"],["d","M 250 92 L 264 80 L 278 86 L 292 72 L 306 78 L 320 64","fill","none","stroke","#005EA6","stroke-width","1.5","stroke-linecap","round","stroke-linejoin","round","stroke-dasharray","200","stroke-dashoffset","200"],["attributeName","stroke-dashoffset","values","200;0;0;200","keyTimes","0;0.5;0.85;1","dur","2.6s","repeatCount","indefinite"],["cx","320","cy","64","r","2.5","fill","#005EA6"],["attributeName","opacity","values","0;0;1;1;0","keyTimes","0;0.45;0.55;0.85;1","dur","2.6s","repeatCount","indefinite"],[4,"ngIf"],["variant","primary","class","empty-state__cta","aria-label","Add widget",3,"click",4,"ngIf"],["variant","primary","aria-label","Add widget",1,"empty-state__cta",3,"click"],["slot","prefix","name","ng-plus","size","16"],[3,"options"],[3,"item","gridster-item--menu-open"],[3,"item"],[1,"widget-card"],[1,"widget-card__filter-overlay"],[1,"widget-body",3,"click"],[3,"aiSend","filterSubmit","filterChange","chartClick","chartSelection","chartSelectionReset","cellFilter","dataViewFilterChange","gridFilterVerdict","menuAction","config","drilldownBy","widgetId","widgetTitle","loading","menu","dashboardFilters","resolvedFilters","dashboardId","conversationId","cellFilterEnabled"],["hoist","","stay-open-on-select","","placement","bottom-end","distance","6",1,"widget-menu"],["slot","prefix",1,"widget-drag-handle"],["slot","prefix",1,"widget-select"],["hoist","","placement","bottom-end","distance","6",1,"widget-header-dropdown",3,"open"],[2,"position","absolute","inset","auto 0 0 0","display","flex","justify-content","flex-end","padding","8px 16px","background","linear-gradient(to top, var(--ng-colors-bg-primary, #fff) 70%, transparent)","pointer-events","none"],[1,"widget-card__filter-overlay-label"],[3,"content"],["name","ng-alert-triangle","method","stroke","size","24","color","var(--ng-colors-border-warning)"],[1,"widget-card__filter-note"],["hoist","","stay-open-on-select","","placement","bottom-end","distance","6",1,"widget-menu",3,"nile-show","nile-hide"],["slot","trigger","type","button","aria-label","Widget actions",1,"widget-menu__trigger"],["name","ng-dots-vertical","method","stroke","size","16"],["role","separator",1,"widget-menu__sep"],[1,"widget-menu__item"],[1,"widget-menu__item",3,"click"],["hoist","","placement","right-start","distance","2",1,"widget-submenu"],["slot","trigger",1,"widget-menu__label"],["method","stroke","size","15",3,"name"],["name","ng-chevron-right","method","stroke","size","14",1,"widget-menu__chevron"],[1,"widget-submenu__menu"],["disabled",""],[1,"widget-submenu__new",3,"click"],["slot","prefix","name","ng-plus","method","stroke","size","14"],[3,"click"],[1,"widget-menu__label"],["size","15",3,"name","method","color"],["size","15",3,"name","method"],["name","ng-dots-grid","method","stroke",1,"drag-icon"],[3,"nile-change"],["hoist","","placement","bottom-end","distance","6",1,"widget-header-dropdown",3,"nile-hide","open"],["slot","trigger","type","button","tabindex","-1","aria-hidden","true",1,"widget-header-btn","widget-header-btn--hidden-anchor"],["name","ng-chart-bar","method","stroke","size","16"],[1,"type-picker__panel"],[1,"inline-action__loading"],[1,"inline-action__hint"],[1,"inline-action__error"],["size","16"],[1,"type-picker__section"],[1,"type-picker__grid"],["type","button",1,"type-picker__tile","type-picker__tile--sensible"],["type","button",1,"type-picker__tile","type-picker__tile--sensible",3,"click"],["method","stroke","size","16",3,"name"],["type","button",1,"type-picker__tile"],["type","button",1,"type-picker__tile",3,"click"],["name","ng-palette","method","stroke","size","16"],[1,"color-picker__panel"],[1,"color-picker__row"],[1,"color-picker__swatch-input"],["type","color",3,"change","value"],[1,"color-picker__name"],["name","ng-filter-lines","method","stroke","size","16"],[1,"filter-builder__panel"],[1,"filter-builder__active"],[1,"filter-builder__quick-time"],[1,"filter-builder__form"],[1,"filter-builder__chip"],["type","button",1,"filter-builder__chip-remove",3,"click"],["name","ng-x-close","method","stroke","size","10"],["type","button",1,"filter-builder__quick-time-chip"],["type","button",1,"filter-builder__quick-time-chip",3,"click"],[1,"filter-builder__select",3,"ngModelChange","ngModel"],[3,"value"],["variant","secondary","size","small",1,"filter-builder__add-btn",3,"click"],[1,"inline-action__loading","inline-action__loading--compact"],["type","text","placeholder","Value\u2026",1,"filter-builder__input",3,"ngModel"],[1,"filter-builder__multi"],[1,"filter-builder__select",3,"ngModel"],["type","text","placeholder","Value\u2026",1,"filter-builder__input",3,"ngModelChange","keydown.enter","ngModel"],["type","date",1,"filter-builder__input",3,"ngModelChange","ngModel"],[1,"filter-builder__and"],["type","number","placeholder","Value\u2026",1,"filter-builder__input",3,"ngModelChange","keydown.enter","ngModel"],["type","number","placeholder","Value\u2026",1,"filter-builder__input",3,"ngModelChange","ngModel"],[1,"filter-builder__multi-item"],["type","checkbox",3,"change","checked"],["value","","disabled",""],["size","12"],["type","button",2,"pointer-events","auto","border","0","border-radius","var(--ng-radius-md, 8px)","padding","6px 14px","font","600 12px/1.2 inherit","color","#fff","background","var(--ng-colors-bg-brand-solid, #155eef)","cursor","pointer",3,"click"],[1,"widget-card__filter-footer"],[1,"widget-card__manual-header"],[1,"widget-card__manual-titles"],[1,"widget-card__manual-title"],[1,"widget-card__manual-actions"],[1,"widget-card__manual",3,"conditionsChange","contentHeight","overflowCountChange","catalog","conditions","catalogLoading","disabled","valueFetcher","onDashboardFields","recentlyUsedFields","expanded"],[1,"widget-drag-handle"],["hoist","","placement","bottom-end"],["slot","trigger","type","button","aria-label","Widget actions",1,"widget-card__kebab"],["name","ng-dots-vertical","method","stroke","size","18"],[1,"widget-menu__list"],[1,"widget-menu__sub-item"],[1,"widget-menu__sub-item",3,"click"],["slot","prefix","name","ng-wand-sparkles","method","stroke","size","14"],["slot","prefix","name","ng-edit-02","method","stroke","size","14"],["slot","prefix","name","ng-trash-01","method","stroke","size","14"],["slot","prefix","name","ng-bell-01","method","stroke","size","14"],["slot","prefix","method","stroke","size","14",3,"name"],["role","button","tabindex","0",1,"widget-card__mode-link",3,"click","keydown.enter"],["open","","hoist","","placement","bottom-start",1,"drill-context-menu",3,"nile-after-hide"],["slot","trigger","aria-hidden","true",1,"drill-context-menu__anchor"],[1,"widget-menu__header"],[1,"widget-menu__divider"],["slot","prefix","name","filter","method","stroke","size","14"],["type","button",1,"tweak-dialog__example",3,"click"],["name","ng-wand-sparkles","method","stroke","size","12"],["slot","prefix","name","ng-refresh-ccw","method","stroke","size","14"],["name","ng-alert-circle","method","stroke","size","16"],[1,"dsl-pane__error-text"],["type","button","aria-label","Dismiss error",1,"dsl-pane__error-dismiss",3,"click"],["name","ng-x-close","method","stroke","size","14"],[1,"dsl-pane__toolbar-actions"],["type","button",1,"dsl-tool-btn",3,"click","disabled"],["name","ng-braces","method","stroke","size","13"],["type","button",1,"dsl-tool-btn",3,"click"],["method","stroke","size","13"],[1,"dsl-validity"],["multiline","","hasScroller","","lineNumbersMultiline","","enableFoldGutters","","enableSearch","",1,"dsl-pane__editor",3,"nile-change","expandable","value"],[1,"dsl-bubble","dsl-bubble--ai",3,"role","agent","icon"],[1,"dsl-turn__summary"],[1,"dsl-turn__diff"],[1,"dsl-turn__actions",3,"copy","copyValue"],["type","button",1,"dsl-turn__action"],["type","button",1,"dsl-turn__action",3,"disabled","title"],[1,"dsl-diff-line",3,"class"],[1,"dsl-diff-line"],[1,"dsl-diff-line__sign"],[1,"dsl-diff-line__text"],["type","button",1,"dsl-turn__action",3,"click"],["type","button",1,"dsl-turn__action",3,"click","disabled","title"],[1,"fc-panel"],["for","fc-horizon",1,"fc-label"],["id","fc-horizon","type","range","min","1",1,"fc-range",3,"input","value"],[1,"fc-hint"],[1,"fc-label"],["role","group","aria-label","Granularity",1,"fc-seg"],["type","button",1,"fc-seg__btn",3,"fc-seg__btn--on"],["role","group","aria-label","Confidence interval",1,"fc-seg"],["slot","footer",1,"fc-actions"],["type","button",1,"fc-seg__btn",3,"click"],[1,"fc-fact"]],template:function(t,M){if(t&1&&(xe(0,xvt,1,6,"shared-filter-rail",1),q(1,"div",2),xe(2,pvt,4,1,"div",3),xe(3,Evt,7,0,"div",4),e5(4,wvt,36,4,"div",5)(5,lZt,3,3,"gridster",6),xe(6,uZt,8,5,"nile-dropdown",7),q(7,"nile-dialog",8),Fe("nile-request-close",function(r){return r.stopPropagation(),M.closeTweak()}),q(8,"div",9)(9,"p",10),v(10,"Describe the change you want \u2014 or pick one of these to start:"),Me(),q(11,"div",11),xt(12,DZt,4,1,"button",12,da),Me(),q(14,"textarea",13),sl("ngModelChange",function(r){return al(M.tweakPromptText,r)||(M.tweakPromptText=r),r}),Me()(),q(15,"div",14)(16,"nile-button",15),Fe("click",function(){return M.closeTweak()}),v(17,"Cancel"),Me(),q(18,"nile-button",16),Fe("click",function(){return M.submitTweak()}),v(19," Apply tweak "),Me()()(),q(20,"nile-drawer",17),Fe("nile-request-close",function(r){return M.onDslRequestClose(r)})("nile-hide",function(){return M.onDslDrawerHidden()}),q(21,"div",18)(22,"span",19)(23,"span",20),v(24),Me(),xe(25,cZt,2,1,"span",21),Me()(),q(26,"div",22),xe(27,IZt,3,1,"nile-button",23),q(28,"nile-button",15),Fe("click",function(){return M.toggleDslDevMode()}),It(29,"nile-glyph",24),v(30," Open in editor "),Me()(),xe(31,dZt,6,1,"div",25),q(32,"div",26),xe(33,jZt,15,12,"section",27),q(34,"aside",28)(35,"header",29)(36,"span",30),It(37,"nile-glyph",31),v(38," Assistant "),Me(),xe(39,yZt,2,2,"span",32),Me(),q(40,"nile-ai-chat",33),xe(41,TZt,2,0,"p",34),xt(42,pZt,8,11,null,null,Yr),xe(44,LZt,1,2,"nile-ai-chat-bubble",35),xe(45,OZt,1,5,"nile-ai-chat-bubble",36),q(46,"nile-ai-prompt-input",37),Fe("nile-input",function(r){return M.dslPromptText=(r.detail==null?null:r.detail.value)??""})("nile-submit",function(r){return M.onDslComposerSubmit(r.detail==null?null:r.detail.value)}),Me()()()(),q(47,"div",38)(48,"span",39),v(49,"Applying re-runs the query and redraws this widget only."),Me(),q(50,"span",40)(51,"nile-button",15),Fe("click",function(){return M.closeDslEditor()}),v(52,"Cancel"),Me(),q(53,"nile-button",16),Fe("click",function(){return M.applyDsl()}),v(54," Apply changes "),Me()()()(),q(55,"nile-drawer",41),Fe("nile-request-close",function(){return M.closeForecastSettings()})("nile-hide",function(){return M.closeForecastSettings()}),xe(56,wZt,31,8),Me()()),t&2){let n;pe(!M.loading&&M.railVisible()?0:-1),m(),ji("view-mode",!M.editMode||M.loading),m(),pe(!M.loading&&M.filterExplanation?2:-1),m(),pe(M.loading?3:-1),m(),Lt("ngIf",!M.loading&&M.widgets.length===0),m(),Lt("ngIf",!M.loading),m(),pe((n=M.drillContextMenu)?6:-1,n),m(),Lt("open",M.tweakTargetId!==null),m(5),pt(M.tweakExamples),m(2),ol("ngModel",M.tweakPromptText),m(4),mt("disabled",M.tweakPromptText.trim()?null:""),m(2),Lt("open",M.dslEditorWidgetId!==null)("preventOverlayClose",M.dslApplying),m(4),it((M.dslEditorWidget==null?null:M.dslEditorWidget.title)||"Edit DSL query"),m(),pe(M.dslChartTypeLabel?25:-1),m(2),pe(M.dslDirty?27:-1),m(2),mt("name",M.dslDevMode?"ng-chevron-down":"ng-chevron-up"),m(2),pe(M.dslError?31:-1),m(2),pe(M.dslDevMode?33:-1),m(),ji("dsl-pane--assistant-full",!M.dslDevMode),m(5),pe(M.dslTurns.length?39:-1),m(),Lt("autoScroll",!0),m(),pe(!M.dslTurns.length&&!M.dslGenerating?41:-1),m(),pt(M.dslTurns),m(2),pe(M.dslPendingPrompt?44:-1),m(),pe(M.dslGenerating?45:-1),m(),Lt("placeholder","Describe a change to this query\u2026")("value",M.dslPromptText)("disabled",M.dslGenerating||M.dslApplying)("maxRows",6)("submitOnEnter",!0),m(5),mt("disabled",M.dslApplying?"":null),m(2),mt("loading",M.dslApplying?"":null)("disabled",!M.dslDirty||!M.dslValidity.ok||M.dslApplying||M.dslGenerating?"":null),m(2),Lt("open",M.forecastSettingsWidgetId!==null),m(),pe(M.forecastDraft?56:-1)}},dependencies:[Pa,c5,Oj,_ot,Pot,bh,kV,Q2,k2,Im,CI,M3,n3,W2,Kot],styles:['@charset "UTF-8";[_nghost-%COMP%]{display:block;height:100%;min-height:100%}shared-filter-rail[_ngcontent-%COMP%]{position:sticky;top:0;z-index:var(--z-sticky, 10);display:block}[_nghost-%COMP%]:has(.canvas-wrap:not(.view-mode)){width:100%;min-width:100%}.canvas-wrap[_ngcontent-%COMP%]{min-height:calc(100vh - var(--db-toolbar-height, 56px) - 64px);height:100%;border-radius:var(--ng-radius-xl, 12px);width:100%;min-width:100%;box-sizing:border-box;padding:8px;background-color:#eef2ff;background-image:radial-gradient(circle,#b8c5f5 1px,transparent 1px);background-size:24px 24px;box-shadow:inset 0 2px 8px #0000000a;transition:background .25s ease}[_nghost-%COMP%] gridster{min-height:calc(100vh - var(--db-toolbar-height, 56px) - 64px);background:transparent!important;border-radius:var(--ng-radius-xl, 12px)}[_nghost-%COMP%] gridster .gridster-row{border-top:1px solid #c7d4f7!important;border-bottom:1px solid #c7d4f7!important}[_nghost-%COMP%] gridster .gridster-column{border-left:1px solid #c7d4f7!important;border-right:1px solid #c7d4f7!important}.grid-hidden[_ngcontent-%COMP%]{display:none!important}.canvas-wrap.view-mode[_ngcontent-%COMP%]{box-shadow:none;padding-left:12px;background-image:none;background-color:transparent;width:100%}.canvas-wrap.view-mode[_ngcontent-%COMP%] gridster{border-color:transparent;box-shadow:none;gap:0}[_nghost-%COMP%] gridster-item{overflow:visible;background:transparent!important;border-radius:var(--ng-radius-xl, 12px)}[_nghost-%COMP%] .gridster-item-resizable-handler{z-index:var(--z-sticky)}.widget-card[_ngcontent-%COMP%]{display:flex;flex-direction:column;height:100%;min-height:0;border-radius:var(--ng-radius-xl, 12px);background:var(--ng-colors-bg-primary, #fff);box-shadow:var(--ng-shadow-sm);overflow:hidden;transition:box-shadow var(--ng-transition-duration-default, .25s) ease;position:relative}.loading-grid[_ngcontent-%COMP%]{display:flex;flex-direction:column;gap:16px;padding:8px}.loading-grid__kpis[_ngcontent-%COMP%]{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:16px}@media(max-width:900px){.loading-grid__kpis[_ngcontent-%COMP%]{grid-template-columns:repeat(2,minmax(0,1fr))}}.loading-grid__charts[_ngcontent-%COMP%]{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:16px}@media(max-width:900px){.loading-grid__charts[_ngcontent-%COMP%]{grid-template-columns:1fr}}.sk-card[_ngcontent-%COMP%]{padding:16px;gap:10px}.sk-card--kpi[_ngcontent-%COMP%]{min-height:128px}.sk-card--chart[_ngcontent-%COMP%]{min-height:300px}.sk-card__value[_ngcontent-%COMP%]{margin-top:auto}.sk-bars[_ngcontent-%COMP%]{flex:1;display:flex;align-items:flex-end;gap:8px;min-height:0;margin-top:8px}.sk-bars[_ngcontent-%COMP%] .sk-bar[_ngcontent-%COMP%]{flex:1}.sk-legend[_ngcontent-%COMP%]{display:flex;gap:12px;margin-top:12px}.sk-legend[_ngcontent-%COMP%] nile-skeleton-loader[_ngcontent-%COMP%]{flex:0 0 64px}.widget-drag-handle[_ngcontent-%COMP%]{display:inline-flex;align-items:center;justify-content:center;height:24px;cursor:grab;opacity:0;transition:opacity .15s ease}.widget-drag-handle[_ngcontent-%COMP%]:active{cursor:grabbing}.widget-drag-handle[_ngcontent-%COMP%] .drag-icon[_ngcontent-%COMP%]{display:inline-flex}.widget-card[_ngcontent-%COMP%]:hover .widget-drag-handle[_ngcontent-%COMP%], .widget-card[_ngcontent-%COMP%]:focus-within .widget-drag-handle[_ngcontent-%COMP%], .widget-drag-handle[_ngcontent-%COMP%]:active{opacity:1}.widget-select[_ngcontent-%COMP%]{display:inline-flex;align-items:center;justify-content:center;height:24px}.widget-menu-btn[_ngcontent-%COMP%]{display:inline-flex;align-items:center;justify-content:center;height:24px;padding:0 2px;border:0;outline:0;background:transparent;color:var(--ng-colors-text-tertiary-600, #535862);cursor:pointer;transition:color .15s}.widget-menu-btn[_ngcontent-%COMP%]:hover, .widget-menu-btn[_ngcontent-%COMP%]:focus, .widget-menu-btn[_ngcontent-%COMP%]:focus-visible, .widget-menu-btn[_ngcontent-%COMP%]:active{background:transparent;outline:0;color:var(--ng-colors-text-primary-900, #181d27)}.widget-menu__list[_ngcontent-%COMP%]{display:block;min-width:220px}.widget-menu__header[_ngcontent-%COMP%]{padding:8px 12px 4px;font-size:11px;font-weight:600;line-height:1.4;letter-spacing:.04em;text-transform:uppercase;color:var(--ng-colors-text-tertiary-600, #535862);pointer-events:none;-webkit-user-select:none;user-select:none}.widget-menu__sub-item[_ngcontent-%COMP%]::part(base){padding-inline-start:var(--ng-spacing-2xl, 24px)}.widget-menu__divider[_ngcontent-%COMP%]{height:1px;margin:4px 8px;background:var(--ng-colors-border-secondary, #e9eaeb)}.widget-card--filter-inactive[_ngcontent-%COMP%] .widget-body[_ngcontent-%COMP%]{filter:grayscale(1)}.widget-card--filter-inactive[_ngcontent-%COMP%] .widget-card__filter-overlay[_ngcontent-%COMP%]{position:absolute;inset:0;z-index:2;display:flex;align-items:center;justify-content:center;background:#fff9;cursor:not-allowed}.widget-card--filter-inactive[_ngcontent-%COMP%] .widget-card__filter-overlay-label[_ngcontent-%COMP%]{display:inline-flex;align-items:center;gap:6px;max-width:calc(100% - 32px);color:var(--ng-colors-border-warning);font-size:12px;font-weight:500}.widget-card--filter-inactive[_ngcontent-%COMP%] .widget-card__filter-note[_ngcontent-%COMP%]{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.widget-card--filter-inactive[_ngcontent-%COMP%] .widget-body[_ngcontent-%COMP%], .widget-card--filter-inactive[_ngcontent-%COMP%] .widget-drag-handle[_ngcontent-%COMP%], .widget-card--filter-inactive[_ngcontent-%COMP%] .widget-menu[_ngcontent-%COMP%]{pointer-events:none}.widget-body[_ngcontent-%COMP%]{flex:1;min-height:0;overflow:hidden}.widget-card--filter[_ngcontent-%COMP%], .widget-card--filter[_ngcontent-%COMP%] .widget-body[_ngcontent-%COMP%], .widget-card--filter[_ngcontent-%COMP%] shared-nile-chart-widget[_ngcontent-%COMP%]{overflow:visible}.widget-body--hidden[_ngcontent-%COMP%]{display:none}.widget-card__manual[_ngcontent-%COMP%]{flex:1;min-height:0}.widget-card__manual-header[_ngcontent-%COMP%]{display:flex;align-items:center;justify-content:space-between;gap:var(--ng-spacing-lg);padding:var(--nile-spacing-xl, var(--ng-spacing-xl)) var(--nile-spacing-3xl, var(--ng-spacing-3xl)) var(--nile-spacing-lg, var(--ng-spacing-lg));border-bottom:1px solid var(--ng-colors-border-secondary)}.widget-card__manual-titles[_ngcontent-%COMP%]{display:flex;flex-direction:column;align-items:flex-start;justify-content:center;min-width:0;flex:1 1 auto}.widget-card__manual-title[_ngcontent-%COMP%]{margin:0;font-family:var(--ng-font-family-display);font-size:var(--ng-font-size-text-l);font-weight:var(--ng-font-weight-semibold);color:var(--ng-colors-text-primary-900);line-height:1.3;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;min-width:0;width:100%}.widget-card__manual-actions[_ngcontent-%COMP%]{display:flex;align-items:center;gap:var(--ng-spacing-xs);flex-shrink:0}.widget-card__kebab[_ngcontent-%COMP%]{display:inline-flex;align-items:center;justify-content:center;padding:var(--ng-spacing-1);border:none;border-radius:var(--ng-radius-md);background:transparent;color:var(--ng-colors-fg-quaternary-400);cursor:pointer}.widget-card__kebab[_ngcontent-%COMP%]:hover{background:var(--ng-colors-bg-secondary);color:var(--ng-colors-text-primary-900)}.widget-card__filter-footer[_ngcontent-%COMP%]{position:absolute;right:var(--ng-spacing-3);bottom:var(--ng-spacing-1-5);z-index:1;display:flex;align-items:center;gap:var(--ng-spacing-2);justify-content:flex-end;pointer-events:none}.widget-card__mode-link[_ngcontent-%COMP%]{font-size:12px;cursor:pointer;pointer-events:auto;color:var(--ng-colors-fg-brand-primary-600)}.widget-card__mode-link[_ngcontent-%COMP%]:hover{text-decoration:underline}.empty-state[_ngcontent-%COMP%]{display:flex;flex-direction:column;align-items:center;justify-content:center;min-height:calc(100vh - var(--db-toolbar-height, 56px) - 128px);padding:var(--ng-spacing-12, 48px) var(--ng-spacing-6, 24px);text-align:center;gap:var(--ng-spacing-3, 12px)}.empty-icon-wrap[_ngcontent-%COMP%]{margin-bottom:var(--ng-spacing-3, 12px)}.empty-state__graphic[_ngcontent-%COMP%]{width:380px;max-width:100%;height:140px;margin-bottom:var(--ng-spacing-4, 16px);display:block;cursor:pointer;border-radius:12px;outline:none;transition:transform .15s ease,filter .15s ease}.empty-state__graphic[_ngcontent-%COMP%] svg[_ngcontent-%COMP%]{display:block;width:100%;height:100%}.empty-state__graphic[_ngcontent-%COMP%]:hover, .empty-state__graphic[_ngcontent-%COMP%]:focus-visible{transform:translateY(-2px);filter:drop-shadow(0 6px 18px rgba(0,94,166,.18))}.empty-state[_ngcontent-%COMP%] h3[_ngcontent-%COMP%]{margin:0;font-size:var(--ng-font-size-text-xl, 20px);font-weight:var(--ng-font-weight-semibold, 600);color:var(--ng-colors-text-primary-900, #181d27)}.empty-state[_ngcontent-%COMP%] p[_ngcontent-%COMP%]{margin:0;font-size:var(--ng-font-size-text-sm, 14px);color:var(--ng-colors-text-tertiary-600, #535862);max-width:380px;line-height:1.6}.tweak-dialog[_ngcontent-%COMP%]::part(panel){width:520px;max-width:92vw;border-radius:14px}.tweak-dialog__body[_ngcontent-%COMP%]{display:flex;flex-direction:column;gap:10px;padding:4px 0 12px}.tweak-dialog__hint[_ngcontent-%COMP%]{margin:0;font-size:13px;color:var(--ng-colors-text-tertiary-600, #535862);line-height:1.5}.tweak-dialog__examples[_ngcontent-%COMP%]{display:flex;flex-direction:column;gap:6px}.tweak-dialog__example[_ngcontent-%COMP%]{display:inline-flex;align-items:center;gap:8px;padding:8px 10px;border:1px solid var(--ng-colors-border-secondary, #e9eaeb);border-radius:10px;background:#fff;color:var(--ng-colors-text-secondary-700, #414651);font-size:12px;font-weight:500;text-align:left;cursor:pointer;transition:border-color .15s,background .15s,color .15s}.tweak-dialog__example[_ngcontent-%COMP%]:hover{border-color:#2970ff;color:#2970ff;background:#2970ff0a}.tweak-dialog__example[_ngcontent-%COMP%] nile-glyph[_ngcontent-%COMP%]{color:#2970ff;flex-shrink:0}.tweak-dialog__example[_ngcontent-%COMP%] span[_ngcontent-%COMP%]{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.tweak-dialog__input[_ngcontent-%COMP%]{width:100%;min-height:96px;padding:10px 12px;border:1px solid var(--ng-colors-border-secondary, #e9eaeb);border-radius:10px;background:#fff;font:inherit;font-size:14px;color:var(--ng-colors-text-primary-900, #181d27);resize:vertical;box-sizing:border-box;outline:0;transition:border-color .15s,box-shadow .15s}.tweak-dialog__input[_ngcontent-%COMP%]:focus{border-color:#2970ff;box-shadow:0 0 0 3px #2970ff26}.tweak-dialog__footer[_ngcontent-%COMP%]{display:flex;justify-content:flex-end;gap:8px}.widget-header-btn[_ngcontent-%COMP%]{position:relative;display:inline-flex;align-items:center;justify-content:center;width:26px;height:26px;padding:0;margin:0 2px;box-sizing:border-box;border:none;border-radius:6px;background:transparent;color:var(--ng-colors-fg-quaternary-400, #717680);cursor:pointer}.widget-header-btn[_ngcontent-%COMP%]:hover{background:var(--ng-colors-bg-secondary, #f5f5f6);color:var(--ng-colors-text-primary-900, #181d27)}.widget-header-btn--hidden-anchor[_ngcontent-%COMP%]{width:0;height:0;padding:0;margin:0;opacity:0;pointer-events:none;overflow:hidden}.widget-header-dropdown[_ngcontent-%COMP%]::part(panel){width:320px;max-width:92vw;overflow-y:auto}.type-picker__panel[_ngcontent-%COMP%], .filter-builder__panel[_ngcontent-%COMP%], .color-picker__panel[_ngcontent-%COMP%]{background:#fff;border:1px solid #e5e7eb;border-radius:12px;box-shadow:0 8px 24px #10182824;padding:10px;box-sizing:border-box;max-height:min(70vh,var(--auto-size-available-height, 70vh));overflow-y:auto}.inline-action__loading[_ngcontent-%COMP%]{display:flex;align-items:center;justify-content:center;gap:8px;min-height:56px;font-size:13px;color:#535862}.inline-action__hint[_ngcontent-%COMP%]{margin:0 0 6px;font-size:12px;color:#535862}.inline-action__error[_ngcontent-%COMP%]{margin:6px 0 0;font-size:12px;color:#d92d20}.type-picker__section[_ngcontent-%COMP%]{margin:6px 0 4px;font-size:11px;font-weight:600;letter-spacing:.02em;text-transform:uppercase;color:#717680}.type-picker__section[_ngcontent-%COMP%]:first-child{margin-top:0}.type-picker__grid[_ngcontent-%COMP%]{display:grid;grid-template-columns:repeat(3,1fr);gap:6px}.type-picker__tile[_ngcontent-%COMP%]{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:4px;padding:8px 4px;box-sizing:border-box;height:60px;border:1px solid #e9eaeb;border-radius:8px;background:#fff;color:#414651;font-size:11px;font-weight:500;cursor:pointer}.type-picker__tile[_ngcontent-%COMP%] nile-glyph[_ngcontent-%COMP%]{color:#717680}.type-picker__tile[_ngcontent-%COMP%]:hover:not(:disabled){border-color:#2970ff;color:#2970ff}.type-picker__tile[_ngcontent-%COMP%]:hover:not(:disabled) nile-glyph[_ngcontent-%COMP%]{color:#2970ff}.type-picker__tile[_ngcontent-%COMP%]:disabled{opacity:.5;cursor:default}.type-picker__tile--sensible[_ngcontent-%COMP%]{border-color:#2970ff47;background:#2970ff0a}.type-picker__tile--sensible[_ngcontent-%COMP%] nile-glyph[_ngcontent-%COMP%]{color:#2970ff}.color-picker__row[_ngcontent-%COMP%]{display:flex;align-items:center;gap:8px;padding:6px 4px;border-radius:6px;cursor:pointer}.color-picker__row[_ngcontent-%COMP%]:hover{background:#f5f5f6}.color-picker__swatch-input[_ngcontent-%COMP%]{display:inline-flex;width:22px;height:22px;border-radius:6px;overflow:hidden;border:1px solid #e9eaeb;flex:0 0 auto}.color-picker__swatch-input[_ngcontent-%COMP%] input[type=color][_ngcontent-%COMP%]{width:100%;height:100%;padding:0;border:none;cursor:pointer}.color-picker__swatch-input[_ngcontent-%COMP%] input[type=color][_ngcontent-%COMP%]::-webkit-color-swatch-wrapper{padding:0}.color-picker__swatch-input[_ngcontent-%COMP%] input[type=color][_ngcontent-%COMP%]::-webkit-color-swatch{border:none}.color-picker__swatch-input[_ngcontent-%COMP%] input[type=color][_ngcontent-%COMP%]::-moz-color-swatch{border:none}.color-picker__name[_ngcontent-%COMP%]{font-size:13px;color:#414651}.widget-menu__trigger[_ngcontent-%COMP%]{display:inline-flex;align-items:center;justify-content:center;padding:var(--ng-spacing-1);border:none;border-radius:var(--ng-radius-md);background:transparent;color:var(--ng-colors-text-tertiary-600);cursor:pointer}.widget-menu__trigger[_ngcontent-%COMP%]:hover{background:var(--ng-colors-bg-secondary);color:var(--ng-colors-text-primary-900)}.widget-menu__label[_ngcontent-%COMP%]{display:flex;align-items:center;gap:8px;width:100%}.widget-menu__label[_ngcontent-%COMP%] nile-glyph[_ngcontent-%COMP%]{flex:none;color:var(--ng-colors-text-tertiary-600)}.widget-menu__chevron[_ngcontent-%COMP%]{margin-left:auto}.widget-menu__sep[_ngcontent-%COMP%]{height:var(--ng-stroke-width-1);background:var(--ng-colors-border-secondary);margin:var(--ng-spacing-md)}.widget-submenu__menu[_ngcontent-%COMP%]{max-height:min(50vh,320px);overflow-y:auto}.widget-submenu__new[_ngcontent-%COMP%]{border-top:1px solid var(--ng-colors-border-secondary);color:var(--ng-colors-fg-brand-primary-600);font-weight:var(--ng-font-weight-semibold)}.widget-menu[_ngcontent-%COMP%]::part(base), .widget-submenu[_ngcontent-%COMP%]::part(base), .widget-header-dropdown[_ngcontent-%COMP%]::part(base){display:block}.widget-menu[_ngcontent-%COMP%]::part(panel), .widget-submenu[_ngcontent-%COMP%]::part(panel), .widget-header-dropdown[_ngcontent-%COMP%]::part(panel){z-index:var(--z-popover, 700)}.widget-card--menu-open[_ngcontent-%COMP%]{overflow:visible;z-index:1}.gridster-item--menu-open[_ngcontent-%COMP%]{z-index:var(--z-popover, 700)!important}.widget-card--menu-open[_ngcontent-%COMP%] nile-chart::part(chart-card){clip-path:none}.story-picker__panel[_ngcontent-%COMP%]{display:flex;flex-direction:column;width:264px;box-sizing:border-box;padding:10px;background:var(--ng-colors-bg-primary);border:1px solid var(--ng-colors-border-secondary);border-radius:var(--ng-radius-lg);max-height:min(60vh,var(--auto-size-available-height, 60vh))}.story-picker__section[_ngcontent-%COMP%]{margin:0 0 6px;font-size:var(--ng-font-size-text-xs);font-weight:var(--ng-font-weight-semibold);letter-spacing:.02em;text-transform:uppercase;color:var(--ng-colors-text-tertiary-600)}.story-picker__list[_ngcontent-%COMP%]{display:flex;flex-direction:column;gap:2px;overflow-y:auto;min-height:0}.story-picker__row[_ngcontent-%COMP%], .story-picker__new[_ngcontent-%COMP%]{display:flex;align-items:center;gap:8px;width:100%;padding:7px 8px;box-sizing:border-box;border:none;border-radius:var(--ng-radius-md);background:transparent;color:var(--ng-colors-text-secondary-700);font-size:var(--ng-font-size-text-sm);text-align:left;cursor:pointer}.story-picker__row[_ngcontent-%COMP%] nile-glyph[_ngcontent-%COMP%], .story-picker__new[_ngcontent-%COMP%] nile-glyph[_ngcontent-%COMP%]{color:var(--ng-colors-text-tertiary-600);flex:none}.story-picker__row[_ngcontent-%COMP%]:hover:not(:disabled), .story-picker__new[_ngcontent-%COMP%]:hover:not(:disabled){background:var(--ng-colors-bg-secondary);color:var(--ng-colors-text-primary-900)}.story-picker__row[_ngcontent-%COMP%]:disabled, .story-picker__new[_ngcontent-%COMP%]:disabled{opacity:.5;cursor:default}.story-picker__name[_ngcontent-%COMP%]{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.story-picker__count[_ngcontent-%COMP%]{flex:none;font-size:var(--ng-font-size-text-xs);color:var(--ng-colors-text-tertiary-600)}.story-picker__new[_ngcontent-%COMP%]{margin-top:6px;padding-top:10px;border-top:1px solid var(--ng-colors-border-secondary);border-radius:0;color:var(--ng-colors-fg-brand-primary-600);font-weight:var(--ng-font-weight-semibold)}.story-picker__new[_ngcontent-%COMP%] nile-glyph[_ngcontent-%COMP%]{color:var(--ng-colors-fg-brand-primary-600)}.filter-builder__active[_ngcontent-%COMP%]{display:flex;flex-wrap:wrap;gap:6px;margin-bottom:8px}.filter-builder__chip[_ngcontent-%COMP%]{display:inline-flex;align-items:center;gap:6px;padding:4px 8px;border-radius:999px;background:#2970ff14;color:#414651;font-size:12px}.filter-builder__chip-remove[_ngcontent-%COMP%]{display:inline-flex;border:none;background:none;padding:0;cursor:pointer;color:inherit}.filter-builder__quick-time[_ngcontent-%COMP%]{display:flex;flex-wrap:wrap;gap:6px;margin-bottom:8px}.filter-builder__quick-time-chip[_ngcontent-%COMP%]{padding:4px 9px;border-radius:999px;border:1px solid #e9eaeb;background:#fff;color:#414651;font-size:12px;cursor:pointer}.filter-builder__quick-time-chip[_ngcontent-%COMP%]:hover:not(:disabled){border-color:#2970ff;color:#2970ff}.filter-builder__quick-time-chip[_ngcontent-%COMP%]:disabled{opacity:.5;cursor:default}.filter-builder__form[_ngcontent-%COMP%]{display:flex;flex-wrap:wrap;align-items:center;gap:6px}.filter-builder__select[_ngcontent-%COMP%], .filter-builder__input[_ngcontent-%COMP%]{flex:1 1 100%;min-width:0;padding:7px 8px;box-sizing:border-box;border:1px solid #e9eaeb;border-radius:7px;background:#fff;font:inherit;font-size:12px;color:#181d27}.filter-builder__field-label[_ngcontent-%COMP%]{padding:6px 2px;font-size:12px;font-weight:600;color:#181d27}.filter-builder__and[_ngcontent-%COMP%]{font-size:12px;color:#535862}.filter-builder__multi[_ngcontent-%COMP%]{display:flex;flex-direction:column;gap:2px;max-height:160px;overflow-y:auto;width:100%}.filter-builder__multi-item[_ngcontent-%COMP%]{display:flex;align-items:center;gap:6px;padding:4px 2px;font-size:12px;color:#414651;cursor:pointer}.filter-builder__multi-item[_ngcontent-%COMP%] span[_ngcontent-%COMP%]{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.filter-builder__add-btn[_ngcontent-%COMP%]{flex:0 0 auto;align-self:flex-start;position:sticky;bottom:0;background:#fff;padding-top:4px;z-index:1}.filter-builder__add-btn[_ngcontent-%COMP%]::part(base){padding:4px 10px;font-size:12px;min-height:0}.inline-action__loading--compact[_ngcontent-%COMP%]{min-height:0;justify-content:flex-start;gap:6px;font-size:12px}.drill-context-menu[_ngcontent-%COMP%]{position:fixed;z-index:var(--z-popover, 700)}.filter-explanation[_ngcontent-%COMP%]{display:flex;align-items:center;gap:var(--ng-spacing-xs, 4px);margin:0 0 var(--ng-spacing-sm, 8px);color:var(--ng-colors-text-tertiary);font-size:var(--ng-font-size-text-s, 12px);line-height:1.4}.filter-explanation__text[_ngcontent-%COMP%]{min-width:0}.drill-context-menu__anchor[_ngcontent-%COMP%]{display:inline-block;width:0;height:0}.dsl-editor-drawer[_ngcontent-%COMP%]::part(base){z-index:var(--z-drawer, 900);left:var(--sidebar-width, 250px);width:calc(100vw - var(--sidebar-width, 250px));transition:left .25s ease,width .25s ease}.dsl-editor-drawer[_ngcontent-%COMP%]::part(overlay){left:var(--sidebar-width, 250px);transition:left .25s ease}.dsl-editor-drawer[_ngcontent-%COMP%]::part(panel){width:100%;max-width:none}.dsl-editor-drawer[_ngcontent-%COMP%]::part(header){align-items:flex-start;padding:14px 20px;border-bottom:1px solid var(--ng-colors-border-secondary, #e9eaeb)}.dsl-editor-drawer[_ngcontent-%COMP%]::part(body){padding:0;overflow:hidden}.dsl-editor-drawer[_ngcontent-%COMP%]::part(footer){padding:12px 20px;border-top:1px solid var(--ng-colors-border-secondary, #e9eaeb)}.dsl-editor-drawer__label[_ngcontent-%COMP%]{display:flex;flex-direction:column;gap:3px;min-width:0}.dsl-editor-drawer__title-row[_ngcontent-%COMP%]{display:flex;align-items:center;gap:8px;min-width:0}.dsl-editor-drawer__title[_ngcontent-%COMP%]{font-size:16px;font-weight:600;color:var(--ng-colors-text-primary-900, #181d27);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dsl-editor-drawer__badge[_ngcontent-%COMP%]{flex:0 0 auto;padding:1px 7px;border:1px solid var(--ng-colors-border-secondary, #e9eaeb);border-radius:6px;background:var(--ng-colors-bg-secondary, #fafafa);font-size:11px;font-weight:500;color:var(--ng-colors-text-tertiary-600, #535862);white-space:nowrap}.dsl-editor-drawer__header-actions[_ngcontent-%COMP%]{display:inline-flex;align-items:center;gap:8px}.dsl-editor-drawer__body[_ngcontent-%COMP%]{display:flex;align-items:stretch;height:100%;min-height:0;--dsl-toolbar-h: 42px}.dsl-pane[_ngcontent-%COMP%]{display:flex;flex-direction:column;min-height:0}.dsl-pane--query[_ngcontent-%COMP%]{flex:1 1 auto;min-width:0}.dsl-pane--assistant[_ngcontent-%COMP%]{flex:0 0 380px;width:380px;border-left:1px solid var(--ng-colors-border-secondary, #e9eaeb);background:var(--ng-colors-bg-secondary, #fcfcfd)}.dsl-pane--assistant.dsl-pane--assistant-full[_ngcontent-%COMP%]{flex:1 1 auto;width:auto;border-left:none}@media(max-width:1024px){.dsl-pane--assistant[_ngcontent-%COMP%]{flex-basis:320px;width:320px}}.dsl-pane__toolbar[_ngcontent-%COMP%]{flex:0 0 var(--dsl-toolbar-h, 42px);height:var(--dsl-toolbar-h, 42px);box-sizing:border-box;display:flex;align-items:center;justify-content:space-between;gap:8px;padding:0 16px;border-bottom:1px solid var(--ng-colors-border-secondary, #e9eaeb)}.dsl-pane__toolbar-label[_ngcontent-%COMP%]{display:inline-flex;align-items:center;gap:6px;font-size:12px;font-weight:600;color:var(--ng-colors-text-secondary-700, #414651)}.dsl-pane__toolbar-actions[_ngcontent-%COMP%]{display:inline-flex;align-items:center;gap:4px}.dsl-pane__toolbar-meta[_ngcontent-%COMP%]{font-size:11.5px;color:var(--ng-colors-text-tertiary-600, #535862)}.dsl-tool-btn[_ngcontent-%COMP%]{display:inline-flex;align-items:center;gap:5px;padding:4px 8px;border:0;border-radius:6px;background:transparent;font:inherit;font-size:12px;color:var(--ng-colors-text-secondary-700, #414651);cursor:pointer;transition:background .12s}.dsl-tool-btn[_ngcontent-%COMP%]:hover:not(:disabled){background:var(--ng-colors-bg-secondary, #f5f5f5)}.dsl-tool-btn[_ngcontent-%COMP%]:disabled{opacity:.5;cursor:default}.dsl-validity[_ngcontent-%COMP%]{display:inline-flex;align-items:center;gap:5px;margin-left:4px;padding:3px 9px;border-radius:999px;background:#fef3f2;font-size:11.5px;font-weight:500;color:#b42318;white-space:nowrap}.dsl-validity.dsl-validity--ok[_ngcontent-%COMP%]{background:#ecfdf3;color:#067647}.dsl-pane__editor[_ngcontent-%COMP%]{display:block;flex:1 1 auto;min-height:160px;overflow:hidden}.dsl-pane__editor[_ngcontent-%COMP%]::part(code-editor-base){height:100%;overflow-y:auto;box-sizing:border-box;border:0;border-radius:0}.dsl-pane__error[_ngcontent-%COMP%]{flex:0 0 auto;display:flex;align-items:flex-start;gap:8px;padding:10px 16px;border-top:1px solid #fda29b;background:#fffbfa;color:#b42318;font-size:12.5px;line-height:1.45}.dsl-pane__error[_ngcontent-%COMP%] nile-glyph[_ngcontent-%COMP%]{flex:0 0 auto;margin-top:1px}.dsl-pane__error--global[_ngcontent-%COMP%]{border-top:none;border-bottom:1px solid #fda29b}.dsl-pane__error-text[_ngcontent-%COMP%]{flex:1 1 auto;min-width:0;word-break:break-word}.dsl-pane__error-dismiss[_ngcontent-%COMP%]{flex:0 0 auto;padding:2px;border:0;border-radius:4px;background:transparent;color:inherit;cursor:pointer}.dsl-pane__error-dismiss[_ngcontent-%COMP%]:hover{background:#b4231814}.dsl-chat[_ngcontent-%COMP%]{flex:1 1 auto;min-height:0;display:block}.dsl-chat[_ngcontent-%COMP%]::part(viewport){padding:14px 12px}.dsl-chat[_ngcontent-%COMP%]::part(messages){gap:12px}.dsl-chat[_ngcontent-%COMP%]::part(footer){padding:10px 12px;border-top:1px solid var(--ng-colors-border-secondary, #e9eaeb);background:#fff}.dsl-chat__empty[_ngcontent-%COMP%]{margin:0 4px;font-size:12.5px;line-height:1.5;color:var(--ng-colors-text-tertiary-600, #535862)}.dsl-bubble--ai[_ngcontent-%COMP%]::part(message){display:flex;flex-direction:column;gap:8px}.dsl-bubble--user[_ngcontent-%COMP%]::part(message){font-size:12.5px;line-height:1.45}.dsl-turn__summary[_ngcontent-%COMP%]{margin:0 0 6px;font-size:13px;line-height:1.5;color:var(--ng-colors-text-primary-900, #181d27)}.dsl-turn__diff[_ngcontent-%COMP%]{max-height:220px;overflow-y:auto;overflow-x:hidden;border:1px solid var(--ng-colors-border-secondary, #e9eaeb);border-radius:8px;background:#fff;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:11.5px;line-height:1.55}.dsl-diff-line[_ngcontent-%COMP%]{display:flex;gap:6px;padding:1px 8px;white-space:pre-wrap;overflow-wrap:anywhere}.dsl-diff-line--add[_ngcontent-%COMP%]{background:#ecfdf3;color:#05603a}.dsl-diff-line--remove[_ngcontent-%COMP%]{background:#fef3f2;color:#b42318}.dsl-diff-line--context[_ngcontent-%COMP%]{color:var(--ng-colors-text-tertiary-600, #535862)}.dsl-diff-line__sign[_ngcontent-%COMP%]{flex:0 0 auto;width:8px;opacity:.75}.dsl-diff-line__text[_ngcontent-%COMP%]{flex:1 1 auto;min-width:0}.dsl-turn__actions[_ngcontent-%COMP%]{display:block}.dsl-turn__actions[_ngcontent-%COMP%]::part(base){align-items:center;gap:2px}.dsl-turn__action[_ngcontent-%COMP%]{padding:3px 6px;border:0;border-radius:6px;background:transparent;font:inherit;font-size:11.5px;color:#175cd3;cursor:pointer;transition:background .12s}.dsl-turn__action[_ngcontent-%COMP%]:hover:not(:disabled){background:#eff4ff}.dsl-turn__action[_ngcontent-%COMP%]:disabled{opacity:.5;cursor:default}.dsl-composer[_ngcontent-%COMP%]{display:block}.dsl-composer[_ngcontent-%COMP%]::part(textarea){font-size:13px}.dsl-editor-drawer__footer[_ngcontent-%COMP%]{display:flex;align-items:center;justify-content:space-between;gap:16px;width:100%}.dsl-editor-drawer__footer-note[_ngcontent-%COMP%]{font-size:12px;color:var(--ng-colors-text-tertiary-600, #535862)}.dsl-editor-drawer__footer-actions[_ngcontent-%COMP%]{display:inline-flex;gap:8px}.fc-panel[_ngcontent-%COMP%]{display:flex;flex-direction:column;gap:8px}.fc-label[_ngcontent-%COMP%]{font-size:14px;font-weight:600;color:var(--ng-colors-text-primary, #101828);margin-top:12px}.fc-label[_ngcontent-%COMP%]:first-child{margin-top:0}.fc-hint[_ngcontent-%COMP%]{font-size:13px;color:var(--ng-colors-text-tertiary, #475467);margin:0 0 4px}.fc-range[_ngcontent-%COMP%]{width:100%;accent-color:var(--ng-colors-bg-brand-solid, #7a5af8)}.fc-seg[_ngcontent-%COMP%]{display:flex;gap:4px;background:var(--ng-colors-bg-secondary, #f2f4f7);border-radius:8px;padding:3px}.fc-seg__btn[_ngcontent-%COMP%]{flex:1;border:0;background:transparent;border-radius:6px;padding:6px 8px;font:inherit;font-size:13px;color:var(--ng-colors-text-secondary, #344054);cursor:pointer}.fc-seg__btn--on[_ngcontent-%COMP%]{background:var(--ng-colors-bg-brand-solid, #7a5af8);color:#fff;font-weight:600}.fc-actions[_ngcontent-%COMP%]{display:inline-flex;gap:8px}.fc-fact[_ngcontent-%COMP%]{display:flex;justify-content:space-between;gap:12px;margin-top:6px;font-size:12px;color:#717680}.fc-fact[_ngcontent-%COMP%] strong[_ngcontent-%COMP%]{color:#414651;font-weight:600}']})};var D3="https://ui-cdn.dev.aqueralabs.com/maps",kZt={"custom/world":`${D3}/world.topo.json`,"custom/us-states":`${D3}/us-all.topo.json`,"custom/us-counties":`${D3}/us-counties.topo.json`,"custom/europe":`${D3}/europe.topo.json`},uB=new Map,wat=new WeakMap;function bZt(i){let e=uB.get(i);return e||(e=fetch(i).then(t=>{if(!t.ok)throw uB.delete(i),new Error(`Failed to fetch topo ${i}: ${t.status}`);return t.json()}),uB.set(i,e)),e}async function DB(i){if(typeof i!="string"||i==="none")return;let e=kZt[i];if(e)try{return await bZt(e)}catch(t){console.error("[map-topo] fetch failed:",t);return}}async function fat(i){if(typeof i.mapData!="string")return;let e=i.mapData,t=await DB(e);if(t===void 0){delete i.mapData;return}wat.set(i,e),i.mapData=t}async function vl(i){let e=i?.chart;if(!e||e.type!=="map")return;let t=[fat(e)];for(let M of e.options?.series??[])t.push(fat(M));await Promise.all(t)}async function Cat(i){await Promise.all(i.map(e=>vl(e.config??null)))}function Sat(i){if(typeof i.mapData=="string"||i.mapData==null)return x({},i);let e=wat.get(i);return e===void 0?x({},i):_(x({},i),{mapData:e})}function jA(i){let e=i?.chart;if(!e||e.type!=="map")return i;let t=e.options?.series,M=Array.isArray(t)?t.map(Sat):t,n=x(x({},Sat(e)),e.options!==void 0?{options:x(x({},e.options),M!==void 0?{series:M}:{})}:{});return _(x({},i),{chart:n})}function kat(i){let e=i;return e?.chart?.type!=="filter"||!Array.isArray(e.chart.controls)?i:_(x({},i),{chart:_(x({},e.chart),{controls:e.chart.controls.map(t=>_(x({},t),{value:""}))})})}function bm(i,e){let t=Array.isArray(i)?i:[],M=Array.isArray(e)?e:[],n=t.length;if(n===0)return{perField:[],anyPartial:!1};let r=M.map(({field:a,label:s})=>{let l=[],N=0;for(let D of t){let c=Array.isArray(D.skippedFilters)&&D.skippedFilters.includes(a),I=D.edited===!1||D.filterApplied===!1;c||I?l.push(D.title||D.id):(D.filterApplied===!0||D.edited===!0)&&(N+=1)}return{field:a,label:s||a,appliedCount:N,total:n,skippedWidgetTitles:l}}),o=r.some(a=>a.skippedWidgetTitles.length>0);return{perField:r,anyPartial:o}}function c3(i,e,t){let M=t?.timeRange?{timeRange:t.timeRange}:{};return t?.resolvedFilters?x({widgets:i,attribute:"attribute",filters:t.resolvedFilters},M):t?.mode==="prompt"&&typeof t.prompt=="string"&&t.prompt.trim()!==""?x({widgets:i,attribute:"prompt",prompt:t.prompt},M):x({widgets:i,filters:e},M)}function QZt(i,e){let t=new Map;for(let M of e)M?.id&&t.set(M.id,M);return i.map(M=>{let n=M?.id?t.get(M.id):void 0;if(n){let r=n.config,o=M.config;return _(x(x({},M),n),{config:r??o})}return bat(M)})}function bat(i){if(!("edited"in i||"reason"in i||"filterApplied"in i||"filteredRowCount"in i||"partial"in i||"skippedFilters"in i))return i;let l=i,{edited:t,reason:M,filterApplied:n,filteredRowCount:r,partial:o,skippedFilters:a}=l;return $e(l,["edited","reason","filterApplied","filteredRowCount","partial","skippedFilters"])}function UZt(i,e,t){let M=i.filter(a=>!t(a)),n=M.length===e.length,r=new Set,o=new Map;return e.forEach((a,s)=>{let l;if(a.title&&(l=i.find(N=>N.title===a.title&&!r.has(N.id))),!l&&n){let N=M[s];l=N&&!r.has(N.id)?N:void 0}l&&(r.add(l.id),o.set(l.id,a))}),o}var cB="dashboard-filter";function IB(){return{id:cB,title:"Filters",widgetType:"chart",componentName:"nile-filter-widget",layout:{x:0,y:0,w:12,h:2},summary:"Filter every widget on this dashboard.",config:{aq:{autocomplete:[]},chart:{type:"filter",controls:[{id:cB,label:"",description:"",value:"",defaultValue:"",autoApply:!1,selection:"single",variant:"prompt",showClearIcon:!0,suggestions:[],suggestionInsert:"replace",typeSpeedMs:60,pauseBeforeDeleteMs:1400,pauseBetweenMs:400,promptPlaceholders:["Filter by any field\u2026"],expressionPlaceholders:['field == "value"'],queryLanguage:{enabled:!1}}]}}}}function fg(i){return i.config?.chart?.type==="filter"||i.componentName==="nile-filter-widget"}function jB(i,e=2,t=12){let M=i.reduce((a,s)=>fg(s)?a+1:a,0);if(M===0)return i;let n=Array.from({length:M},(a,s)=>({x:0,y:s*e,w:t,h:e})),r=[...n],o=0;return i.map(a=>{if(fg(a))return _(x({},a),{layout:n[o++]});if(!a.layout)return a;let{x:s,w:l,h:N}=a.layout,D=a.layout.y,c=!0;for(;c;){c=!1;for(let d of r)s<d.x+d.w&&s+l>d.x&&D<d.y+d.h&&D+N>d.y&&(D=d.y+d.h,c=!0)}let I={x:s,y:D,w:l,h:N};return r.push(I),_(x({},a),{layout:I})})}function vZt(i){if(fg(i))return"filter";let e=i.config?.chart?.type;return i.componentName==="nile-kpi-chart"||e==="kpi"||i.widgetType==="kpi"?"kpi":i.componentName==="nile-data-grid"||e==="grid"||i.widgetType==="grid"?"grid":"chart"}var YZt=10,ZZt=88,_Zt=40,WZt=48,PZt=3,RZt=8;function VZt(i){let e=i.config?.chart,t=Number(e?.pagination?.pageSize)||YZt,M=e?.serverPagination===!0&&typeof e?.gridId=="string",n=Number(e?.totalItems),r=e?.data,o=Number.isFinite(n)?n:M?null:Array.isArray(r)?r.length:null,a=o==null?t:Math.min(o,t),s=ZZt+a*_Zt+WZt,l=Math.ceil(s/72);return Math.min(RZt,Math.max(PZt,l))}function BZt(i){let e=i.config?.chart?.sparkline;return Array.isArray(e)&&e.length>=2}function FZt(i){let e=i.config?.chart?.type;return i.componentName==="nile-master-detail-chart"||e==="master-detail"}function yB(i,e=12){let t=i.map(vZt),M=t.filter(Y=>Y==="filter").length,n=t.filter(Y=>Y==="kpi").length,r=0,o=r;r+=M*2;let a=r,s=n===2||n===3||n===4||n===6,l=s?n:Math.min(4,n),N=s?e/n:3,D=i.some((Y,B)=>t[B]==="kpi"&&BZt(Y))?3:2;r+=l?Math.ceil(n/l)*D:0;let c=4,I=Math.max(1,Math.floor(e/2)),d=[];{let Y=0,B=r;for(let X=0;X<i.length;X++)if(t[X]==="chart"){if(FZt(i[X])){Y!==0&&(Y=0,B+=c),d.push({x:0,y:B,w:e,h:c}),B+=c;continue}Y+I>e&&(Y=0,B+=c),d.push({x:Y,y:B,w:I,h:c}),Y+=I}if(Y===I){let X=d[d.length-1];X&&(X.w=e)}Y>0&&(B+=c),r=B}let y=r,A=i.filter((Y,B)=>t[B]==="grid").map(Y=>VZt(Y)),z=[];A.reduce((Y,B,X)=>(z[X]=Y,Y+B),0);let E=0,S=0,L=0,U=0;return i.map((Y,B)=>{let X;switch(t[B]){case"filter":{let W=E++;X={x:0,y:o+W*2,w:e,h:2};break}case"kpi":{let W=S++,Ne=Math.floor(W/l);X={x:W%l*N,y:a+Ne*D,w:N,h:D};break}case"grid":{let W=U++;X={x:0,y:y+z[W],w:e,h:A[W]};break}default:{X=d[L++];break}}return _(x({},Y),{layout:X})})}function dB(i,e){return!!i&&[i.x,i.y,i.w,i.h].every(Number.isFinite)&&i.x>=0&&i.y>=0&&i.w>0&&i.h>0&&i.x+i.w<=e}function HZt(i,e){return i.x<e.x+e.w&&i.x+i.w>e.x&&i.y<e.y+e.h&&i.y+i.h>e.y}function Qm(i,e=12){let t=i.map(n=>n.layout);return t.some(n=>!dB(n,e))||t.some((n,r)=>dB(n,e)&&t.slice(r+1).some(o=>dB(o,e)&&HZt(n,o)))?yB(i,e):i}function I3(i,e){let t=i.config?.chart;return typeof t?.gridId!="string"||!t.gridId.startsWith("tpl:")?i:_(x({},i),{config:_(x({},i.config),{chart:_(x({},t),{gridId:e})})})}var Wh=class i{stateSubject=new Ia(this.createEmpty("My Dashboard"));dirtySubject=new Ia(!1);mutationsSubject=new ca;filterBaseline=null;pendingLayoutBatch=null;layoutUndoStack=[];layoutRedoStack=[];static LAYOUT_HISTORY_LIMIT=50;canUndoLayoutSubject=new Ia(!1);canRedoLayoutSubject=new Ia(!1);state$=this.stateSubject.asObservable();dirty$=this.dirtySubject.asObservable();mutations$=this.mutationsSubject.asObservable();canUndoLayout$=this.canUndoLayoutSubject.asObservable();canRedoLayout$=this.canRedoLayoutSubject.asObservable();get snapshot(){return this.stateSubject.value}get isDirty(){return this.dirtySubject.value}get canUndoLayout(){return this.canUndoLayoutSubject.value}get canRedoLayout(){return this.canRedoLayoutSubject.value}get isAutoGenerated(){return this.snapshot.isAutoGenerated===!0}setDashboardName(e){this.patchState({name:e.trim()||"Untitled Dashboard"})}setDashboardId(e){!e||this.snapshot.id===e||this.patchState({id:e})}addWidget(e,t){if("type"in e&&!("widgetType"in e))return this.addChartWidget(e);let M=e,n=this.snapshot.widgets,r=M.widgetType==="kpi"?2:4,o=M.widgetType==="kpi"?4:6,a=t?.placeExplicitly&&M.layout?M.layout:{x:0,y:this.computeMaxY(n,r),w:Math.min(Math.max(1,M.layout?.w||o),12),h:Math.max(1,M.layout?.h||r)},s=crypto.randomUUID(),l=_(x({},I3(M,s)),{id:s,layout:a}),N=[...n,l],D=!t?.placeExplicitly&&this.isFilterWidget(l)?this.normalizeFilterLayouts(N):N;return this.patchState({widgets:D}),l.id}addWidgets(e){if(!e.length)return[];let t=this.snapshot.widgets,M=t.some(N=>fg(N)),n=M?e.filter(N=>!fg(N)):e,r=n.filter(N=>!fg(N)&&N.layout).map(N=>N.layout.y),o=M&&r.length?Math.min(...r):0,a=this.computeMaxY(t,0),s=[];for(let N of n){let D=N.widgetType==="kpi"?2:4,c=N.widgetType==="kpi"?4:6,I;fg(N)?I={x:0,y:0,w:12,h:2}:N.layout?I={x:N.layout.x,y:N.layout.y-o+a,w:Math.min(Math.max(1,N.layout.w||c),12),h:Math.max(1,N.layout.h||D)}:I={x:0,y:this.computeMaxY([...t,...s],D),w:c,h:D};let d=crypto.randomUUID();s.push(_(x({},I3(N,d)),{id:d,layout:I}))}let l=this.normalizeFilterLayouts([...t,...s]);return this.patchState({widgets:l}),s.map(N=>N.id)}addChartWidget(e){let n=e,{title:t}=n,M=$e(n,["title"]);return this.addWidget({title:t,widgetType:"chart",config:{chart:M,aq:{}}})}addKpiWidget(e){return this.addWidget({title:e.label,widgetType:"kpi",config:{chart:e,aq:{}}})}updateWidget(e,t){let M=this.snapshot.widgets.map(n=>n.id===e?x(x({},n),t):n);this.patchState({widgets:M})}applyFilterView(e){if(!e.length)return;this.filterBaseline||(this.filterBaseline=this.snapshot.widgets.map(n=>x({},n)));let t=new Map(e.map(n=>[n.id,n])),M=this.snapshot.widgets.map(n=>{let r=t.get(n.id);return r?_(x(x({},n),r),{layout:n.layout??r.layout}):n});this.stateSubject.next(_(x({},this.snapshot),{widgets:M}))}restoreFilterBaseline(){if(!this.filterBaseline)return!1;let e=this.filterBaseline;return this.filterBaseline=null,this.stateSubject.next(_(x({},this.snapshot),{widgets:e})),!0}updateWidgetLayout(e,t){this.recordLayoutUndo(e);let M=this.snapshot.widgets.map(n=>n.id===e?_(x({},n),{layout:t}):n);this.patchState({widgets:M})}hasFilterWidget(){return this.snapshot.widgets.some(e=>fg(e))}toggleFilterWidget(){let e=this.snapshot.widgets.find(r=>fg(r));if(e){let r=e.layout,o=r?r.y+r.h:0,a=r?.h??0;this.patchState({widgets:this.snapshot.widgets.filter(s=>s.id!==e.id).map(s=>!s.layout||s.layout.y<o?s:_(x({},s),{layout:_(x({},s.layout),{y:Math.max(0,s.layout.y-a)})}))});return}let n=IB(),{id:t}=n,M=$e(n,["id"]);this.addWidget(M)}removeWidget(e){this.patchState({widgets:this.snapshot.widgets.filter(t=>t.id!==e)})}updateWidgetLayouts(e){if(!e.length)return;e.forEach(n=>this.recordLayoutUndo(n.id));let t=new Map(e.map(n=>[n.id,n.layout])),M=this.snapshot.widgets.map(n=>{let r=t.get(n.id);return r?_(x({},n),{layout:x({},r)}):n});this.patchState({widgets:M})}undoLayout(){let e=this.layoutUndoStack.pop();e&&(this.applyLayoutEntries(e,"before"),this.layoutRedoStack.push(e),this.syncLayoutHistoryFlags())}redoLayout(){let e=this.layoutRedoStack.pop();e&&(this.applyLayoutEntries(e,"after"),this.layoutUndoStack.push(e),this.syncLayoutHistoryFlags())}recordLayoutUndo(e){if(this.pendingLayoutBatch||(this.pendingLayoutBatch=new Map,queueMicrotask(()=>this.commitPendingLayoutBatch())),this.pendingLayoutBatch.has(e))return;let t=this.snapshot.widgets.find(M=>M.id===e)?.layout;t&&this.pendingLayoutBatch.set(e,t)}commitPendingLayoutBatch(){let e=this.pendingLayoutBatch;if(this.pendingLayoutBatch=null,!e||e.size===0)return;let t=[];for(let[M,n]of e){let r=this.snapshot.widgets.find(o=>o.id===M)?.layout;r&&!this.layoutsEqual(n,r)&&t.push({id:M,before:n,after:x({},r)})}t.length&&(this.layoutUndoStack.push(t),this.layoutUndoStack.length>i.LAYOUT_HISTORY_LIMIT&&this.layoutUndoStack.shift(),this.layoutRedoStack=[],this.syncLayoutHistoryFlags())}applyLayoutEntries(e,t){let M=new Map(e.map(r=>[r.id,r[t]])),n=this.snapshot.widgets.map(r=>{let o=M.get(r.id);return o?_(x({},r),{layout:x({},o)}):r});this.patchState({widgets:n})}layoutsEqual(e,t){return e.x===t.x&&e.y===t.y&&e.w===t.w&&e.h===t.h}syncLayoutHistoryFlags(){this.canUndoLayoutSubject.next(this.layoutUndoStack.length>0),this.canRedoLayoutSubject.next(this.layoutRedoStack.length>0)}clearLayoutHistory(){this.pendingLayoutBatch=null,this.layoutUndoStack=[],this.layoutRedoStack=[],this.syncLayoutHistoryFlags()}replaceDashboard(e){let t=e.widgets.map((n,r)=>_(x({},n),{widgetType:n.widgetType??"chart",layout:n.layout??{x:0,y:r*4,w:n.widgetType==="kpi"?4:6,h:n.widgetType==="kpi"?2:4}})),M=_(x({},e),{widgets:Qm(this.normalizeFilterLayouts(this.clampLayoutsToCols(t)))});this.filterBaseline=null,this.clearLayoutHistory(),this.stateSubject.next(M),this.dirtySubject.next(!1)}clampLayoutsToCols(e,t=12){let M=[];return e.map(n=>{let r=n.layout;if(!r)return n;let o=Math.max(1,Math.min(r.w,t)),a=Math.max(0,Math.min(r.x,t-o)),s=r.h,l=r.y,N=I=>M.some(d=>a<d.x+d.w&&a+o>d.x&&I<d.y+d.h&&I+s>d.y),D=Math.max(s,1);for(;N(l);)l+=D;let c={x:a,y:l,w:o,h:s};return M.push(c),_(x({},n),{layout:c})})}isFilterWidget(e){return fg(e)}normalizeFilterLayouts(e,t=2,M=12){return jB(e,t,M)}resetDashboard(){this.filterBaseline=null,this.clearLayoutHistory(),this.stateSubject.next(this.createEmpty("My Dashboard")),this.dirtySubject.next(!1)}markClean(){this.dirtySubject.next(!1)}createEmpty(e){return{id:crypto.randomUUID(),name:e,widgets:[],updatedAt:new Date().toISOString()}}computeMaxY(e,t){return e.reduce((M,n)=>{let r=n.layout?.y??0,o=n.layout?.h??t;return Math.max(M,r+o)},0)}patchState(e){let t=_(x(x({},this.snapshot),e),{updatedAt:new Date().toISOString()});this.stateSubject.next(t),this.dirtySubject.next(!0),this.mutationsSubject.next(t)}static \u0275fac=function(t){return new(t||i)};static \u0275prov=Yt({token:i,factory:i.\u0275fac,providedIn:"root"})};function JZt(i){return!i?.chart||i.chart.type!=="grid"||i.chart.stickyHeader!==void 0?i:_(x({},i),{chart:_(x({},i.chart),{stickyHeader:!0})})}function GZt(i,e){return{title:i.title,widgetType:i.widgetType,layout:i.layout,dataSourceId:e??i.dataSourceId,config:i.config,drilldownBy:i.drilldownBy}}var Ph=class i{http=Be(co);tokenStore=Be(Cr);dashboardsPath=Be(m2);inFlightSaves=new Map;lastSentCustomerId=null;lastSentProductId=null;get customerId(){return this.tokenStore.tenantId()??""}withPublished(e,t){return t===void 0?e:`${e}${e.includes("?")?"&":"?"}published=${t}`}mcpGatewayUrl(){return`${Tt.baseUrl}/dviz-mcp`}async callMcpTool(e,t={}){let M=this.customerId,n=Oi(),r={};M!==this.lastSentCustomerId&&(r.customerId=M),n!==this.lastSentProductId&&(r.productId=n);let o;try{o=await ii(this.http.post(this.mcpGatewayUrl(),{jsonrpc:"2.0",id:Date.now(),method:"tools/call",params:{name:e,arguments:t}},{headers:{Accept:"application/json, text/event-stream"},params:r})),this.lastSentCustomerId=M,this.lastSentProductId=n}catch(s){throw s instanceof qM?new Error(s.error?.error?.message||s.error?.message||s.message):s}if(o.error)throw new Error(o.error.message);let a=o.result;if(a?.isError)throw new Error(a.structuredContent?.error?.message??a.content?.[0]?.text??`${e} failed`);return a?.structuredContent??{}}async publishToApi(e,t,M){return t?(await this.updateDashboardMeta(t,e),t):await this.createDashboard(e,void 0,M)}async updateDashboardMeta(e,t){if(!Tt.MCP_GATEWAY_ENABLED){let M=null;try{M=await ii(this.http.put(`${Tt.baseUrl}/api/customers/${this.customerId}/products/${Oi()}/${this.dashboardsPath}/${e}`,{name:t,description:t}))}catch(n){throw n instanceof qM?new Error(n.error?.error||n.message):n}if(M?.success===!1)throw new Error(M.error||"Failed to update dashboard");return}await this.callMcpTool("updateDashboard",{dashboardId:e,name:t,description:t})}async renameDashboard(e,t){await this.updateDashboardMeta(e,t)}async publishDashboard(e,t){if(!Tt.MCP_GATEWAY_ENABLED){let M=null,n={};t&&(n.name=t,n.description=t);try{M=await ii(this.http.post(`${Tt.baseUrl}/api/customers/${this.customerId}/products/${Oi()}/${this.dashboardsPath}/${e}/publish`,n))}catch(r){throw r instanceof qM?new Error(r.error?.error||r.message):r}if(M?.success===!1)throw new Error(M.error||"Failed to publish dashboard");return}await this.callMcpTool("publishDashboard",{dashboardId:e})}async saveDraft(e,t){let n=(this.inFlightSaves.get(e)??Promise.resolve()).catch(()=>{}).then(()=>this.runSaveDraft(e,t));this.inFlightSaves.set(e,n);try{await n}finally{this.inFlightSaves.get(e)===n&&this.inFlightSaves.delete(e)}}async runSaveDraft(e,t){let M=Qm(t.widgets).map(n=>({id:n.id,title:n.title,summary:n.summary,widgetType:n.widgetType,componentName:n.componentName,layout:n.layout??{x:0,y:0,w:6,h:4},config:jA(n.config),queryMeta:n.queryMeta,dataSourceId:n.dataSourceId,drilldownBy:n.drilldownBy}));if(!Tt.MCP_GATEWAY_ENABLED){let n=`${Tt.baseUrl}/api/customers/${this.customerId}/products/${Oi()}/${this.dashboardsPath}/${e}?published=false`;await ii(this.http.put(n,{widgets:M}));return}await this.callMcpTool("updateDashboard",{dashboardId:e,widgets:M,published:!1})}async listDashboards(e){if(!Tt.MCP_GATEWAY_ENABLED){let n={};e?.published!==void 0&&(n.published=e.published),e?.limit!==void 0&&(n.limit=String(e.limit)),e?.offset!==void 0&&(n.offset=String(e.offset)),e?.conversationId!==void 0&&(n.conversationId=e.conversationId);let r=await ii(this.http.get(`${Tt.baseUrl}/api/customers/${this.customerId}/products/${Oi()}/${this.dashboardsPath}`,{params:n})),o=r?.data??r;return Array.isArray(o)?o:[]}let t={};return e?.published!==void 0&&(t.published=e.published),e?.limit!==void 0&&(t.limit=e.limit),e?.offset!==void 0&&(t.offset=e.offset),e?.conversationId!==void 0&&(t.conversationId=e.conversationId),(await this.callMcpTool("listDashboards",t))?.dashboards??[]}async createDashboard(e,t,M){if(!Tt.MCP_GATEWAY_ENABLED){let o;try{o=await ii(this.http.post(`${Tt.baseUrl}/api/customers/${this.customerId}/products/${Oi()}/${this.dashboardsPath}`,x({name:e,description:t??e},M??{})))}catch(s){throw s instanceof qM?new Error(s.error?.error||s.message):s}if(o?.success===!1)throw new Error(o.error||"Failed to create dashboard");let a=o?.data?.id??o?.id;if(!a)throw new Error("No dashboard ID returned from API");return a}let r=(await this.callMcpTool("createDashboard",x({name:e,description:t??e},M??{})))?.dashboard?.id;if(!r)throw new Error("No dashboard ID returned from API");return r}async deleteWidget(e,t,M){if(!Tt.MCP_GATEWAY_ENABLED){let r=`${Tt.baseUrl}/api/customers/${this.customerId}/products/${Oi()}/${this.dashboardsPath}/${e}/widgets/${t}`;await ii(this.http.delete(this.withPublished(r,M)));return}let n={dashboardId:e,widgetId:t};M!==void 0&&(n.published=M),await this.callMcpTool("removeDashboardWidget",n)}async listChartTypes(e){let t;try{t=await ii(this.http.post(`${Tt.baseUrl}/api/customers/${this.customerId}/products/${Oi()}/workforce/widget/chart-types`,{widgetConfig:e}))}catch(M){throw M instanceof qM?new Error(M.error?.error||M.message):M}if(t?.success===!1)throw new Error(t?.error||"Could not load chart types");return t?.types??[]}async changeAdhocChartType(e,t){let M;try{M=await ii(this.http.post(`${Tt.baseUrl}/api/customers/${this.customerId}/products/${Oi()}/workforce/widget/change-type`,{widgetConfig:e,newChartType:t}))}catch(n){throw n instanceof qM?new Error(n.error?.error||n.message):n}if(M?.success===!1||!M?.chart)throw new Error(M?.error||"Chart type change failed");return M.chart}async listAdhocFilterFields(e){let t;try{t=await ii(this.http.post(`${Tt.baseUrl}/api/customers/${this.customerId}/products/${Oi()}/workforce/widget/filter-fields`,{widgets:e}))}catch(M){throw M instanceof qM?new Error(M.error?.error||M.message):M}if(t?.success===!1)throw new Error(t?.error||"Could not load filter fields");return t?.fields??[]}async fetchAdhocFilterValues(e,t,M=""){let n;try{n=await ii(this.http.post(`${Tt.baseUrl}/api/customers/${this.customerId}/products/${Oi()}/workforce/widget/filter-values`,{widgets:e,field:t,prefix:M}))}catch(r){throw r instanceof qM?new Error(r.error?.error||r.message):r}if(n?.success===!1)throw new Error(n?.error||"Could not load filter values");return{field:t,values:n?.values??[],complete:n?.complete??!0}}async applyAdhocFilter(e,t){let M;try{M=await ii(this.http.post(`${Tt.baseUrl}/api/customers/${this.customerId}/products/${Oi()}/workforce/widget/filter-apply`,{widgetConfig:e,filters:t}))}catch(n){throw n instanceof qM?new Error(n.error?.error||n.message):n}if(M?.success===!1||!M?.chart)throw new Error(M?.error||"Filter could not be applied");return M.chart}async changeWidgetChartType(e,t,M,n){let r=`${Tt.baseUrl}/api/customers/${this.customerId}/products/${Oi()}/${this.dashboardsPath}/${e}/widgets/${t}`,o;try{o=await ii(this.http.patch(this.withPublished(r,n),{chartType:M}))}catch(a){throw a instanceof qM?new Error(a.error?.error||a.message):a}if(o?.success===!1||!o?.data)throw new Error(o?.error||"Chart type change failed");return o.data}async addWidgetFilter(e,t,M,n){let r=`${Tt.baseUrl}/api/customers/${this.customerId}/products/${Oi()}/${this.dashboardsPath}/${e}/widgets/${t}/filters`,o;try{o=await ii(this.http.post(this.withPublished(r,n),M))}catch(a){throw a instanceof qM?new Error(a.error?.error||a.message):a}if(o?.success===!1||!o?.data)throw new Error(o?.error||"Filter could not be applied");return o.data}async removeWidgetFilter(e,t,M,n){let r=`${Tt.baseUrl}/api/customers/${this.customerId}/products/${Oi()}/${this.dashboardsPath}/${e}/widgets/${t}/filters/${M}`,o;try{o=await ii(this.http.delete(this.withPublished(r,n)))}catch(a){throw a instanceof qM?new Error(a.error?.error||a.message):a}if(o?.success===!1||!o?.data)throw new Error(o?.error||"Filter could not be removed");return o.data}async setFilterDefault(e,t,M,n,r){let o=`${Tt.baseUrl}/api/customers/${this.customerId}/products/${Oi()}/${this.dashboardsPath}/${e}/widgets/${t}/filter-default`,a;try{a=await ii(this.http.patch(this.withPublished(o,r),{defaultValue:M,autoApply:n}))}catch(s){throw s instanceof qM?new Error(s.error?.error||s.message):s}if(a?.success===!1||!a?.data)throw new Error(a?.error||"Default filter could not be updated");return a.data}async deleteDashboard(e){if(!Tt.MCP_GATEWAY_ENABLED){await ii(this.http.delete(`${Tt.baseUrl}/api/customers/${this.customerId}/products/${Oi()}/${this.dashboardsPath}/${e}`));return}await this.callMcpTool("deleteDashboard",{dashboardId:e})}async discardDraft(e){if(!Tt.MCP_GATEWAY_ENABLED){let t=`${Tt.baseUrl}/api/customers/${this.customerId}/products/${Oi()}/${this.dashboardsPath}/${e}`;await ii(this.http.delete(this.withPublished(t,!1)));return}await this.callMcpTool("deleteDashboard",{dashboardId:e,published:!1})}async refreshDashboard(e){if(!Tt.MCP_GATEWAY_ENABLED){let M=await ii(this.http.post(`${Tt.baseUrl}/api/customers/${this.customerId}/products/${Oi()}/${this.dashboardsPath}/${e}/refresh`,{}));if(M?.success===!1)throw new Error(M.error||"Failed to refresh dashboard");return{widgets:await this.mapAndHydrateWidgets(M?.data?.widgets)}}let t=await this.callMcpTool("refreshDashboard",{dashboardId:e});return{widgets:await this.mapAndHydrateWidgets(t?.refresh?.widgets)}}async rearrangeDashboard(e,t){let M=e.map(s=>{let l=s.config?.chart?.type;return{id:s.id,title:s.title??"",widgetType:s.widgetType??"chart",chartType:l,layout:s.layout}});if(!Tt.MCP_GATEWAY_ENABLED){let s;try{s=await ii(this.http.post(`${Tt.baseUrl}/api/customers/${this.customerId}/products/${Oi()}/${this.dashboardsPath}/rearrange`,{widgets:M,dashboardId:t??void 0}))}catch(I){if(I instanceof qM){let d=new Error(I.error?.error||I.message);throw d.status=I.status,d}throw I}if(s?.success===!1)throw new Error(s.error||"Failed to rearrange dashboard");let l=s?.data??s,D=(Array.isArray(l)?l:l?.widgets??[]).filter(I=>I?.id&&I?.layout).map(I=>({id:String(I.id),layout:I.layout})),c=s?.meta?.count??D.length;return{layouts:D,widgetCount:c}}let n=await this.callMcpTool("rearrangeDashboardWidgets",{widgets:M}),o=(n?.widgets??[]).filter(s=>s?.id&&s?.layout).map(s=>({id:String(s.id),layout:s.layout})),a=n?.count??o.length;return{layouts:o,widgetCount:a}}async fetchDashboardSummary(e,t){let M=`${Tt.baseUrl}/api/customers/${this.customerId}/products/${Oi()}/${this.dashboardsPath}/${e}/summary`,n=await ii(this.http.post(this.withPublished(M,t),{})),r=n?.data??n;return typeof r=="string"?r:r?.summary??""}async runExecutiveSummaryChat(e,t){let M=await ii(this.http.get(`${Tt.baseUrl}/api/customers/${this.customerId}/products/${Oi()}/${this.dashboardsPath}/${e}`)),n=(M?.data??M)?.conversationId??null;if(!n)throw new Error("This dashboard has no conversation to summarise yet.");let r=this.tokenStore.accessToken()??"",o=`${Tt.baseUrl}/api/customers/${this.customerId}/products/${Oi()}/workforce`,a=await fetch(`${o}/v1/conversations/chat`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`},body:JSON.stringify({conversationId:n,message:t,dashboardId:e})});if(!a.ok||!a.body){let I=await a.text().catch(()=>a.statusText);throw new Error(`Request failed (${a.status}): ${I}`)}let s=a.body.getReader(),l=new TextDecoder,N="",D="",c=I=>{let d=I.trim();if(!d)return;let y=d.indexOf(":");if(!(y===-1||d.slice(0,y)!=="0"))try{D+=JSON.parse(d.slice(y+1))?.text??""}catch{}};for(;;){let{done:I,value:d}=await s.read();if(I)break;N+=l.decode(d,{stream:!0});let y=N.split(`
|