import{t as l}from"./theme-colors-BFneJNsI.js";const c={QUEUED:l.grayShade2,RUNNING:l.primaryShade1,PLANNING:l.labels.purple,FINISHED:l.primaryShade1,BLOCKED:l.labels.red,USER_ERROR:l.labels.orange,CANCELED:l.labels.orange,INSUFFICIENT_RESOURCES:l.labels.yellow,EXTERNAL:l.labels.red,UNKNOWN_ERROR:l.labels.redShade2},G={AriaChartFill:"var(--quartz-primary-shade1)",AreaChartStroke:"var(--quartz-primary)"};function H(t){switch(t.state){case"QUEUED":case"PLANNING":case"FINISHED":return c[t.state];case"STARTING":case"FINISHING":case"RUNNING":return t.queryStats&&t.queryStats.fullyBlocked?c.BLOCKED:c.RUNNING;case"FAILED":switch(t.errorType){case"USER_ERROR":return t.errorCode.name==="USER_CANCELED"?c.CANCELED:c.USER_ERROR;case"EXTERNAL":case"INSUFFICIENT_RESOURCES":return c[t.errorType];default:return c.UNKNOWN_ERROR}default:return c.QUEUED}}const P=t=>{switch(t){case"QUEUED":return c.QUEUED;case"PLANNING":return c.PLANNING;case"STARTING":case"FINISHING":case"RUNNING":return c.RUNNING;case"FAILED":return c.UNKNOWN_ERROR;case"FINISHED":return c.FINISHED;default:return c.QUEUED}},K=t=>{if(t.state!=="RUNNING")return 100;const e=t.queryStats.progressPercentage||0;return Math.round(e)},U=t=>{var e;if(t.state==="RUNNING"){let r="RUNNING";if(t.scheduled&&t.queryStats.totalDrivers>0&&t.queryStats.runningDrivers>=0)return t.queryStats.fullyBlocked&&(r="BLOCKED",((e=t.queryStats.blockedReasons)==null?void 0:e.length)>0&&(r+=`(${t.queryStats.blockedReasons.join(", ")})`)),t.memoryPool==="reserved"&&(r+=" (RESERVED)"),r}if(t.state==="FAILED"){let r="";switch(t.errorType){case"USER_ERROR":r="USER ERROR",t.errorCode.name==="USER_CANCELED"&&(r="USER CANCELED");break;case"INTERNAL_ERROR":r="INTERNAL ERROR";break;case"INSUFFICIENT_RESOURCES":r="INSUFFICIENT RESOURCES";break;case"EXTERNAL":r="EXTERNAL ERROR";break;default:r="INTERNAL ERROR"}return t.errorCode&&t.errorCode.name&&(r+=` - ${t.errorCode.name}`),r}return t.state},g=300,h=.2;function Q(t,e){return e.length===0?e.concat([t]):e.concat([t]).slice(Math.max(e.length-g,0))}function x(t,e){if(e.length===0)return e.concat([t]);let r=t*h+e[e.length-1]*(1-h);return t<1&&(r=0),e.concat([r]).slice(Math.max(e.length-g,0))}function W(t,e){return t&&t.length>e?`${t.substring(0,e)}...`:t}function S(t){return t.slice(t.indexOf(".")+1,t.length)}function z(t){return Number.parseInt(S(S(t)),10)}function X(t){let{hostname:e}=new URL(t);return e.charAt(0)==="["&&e.charAt(e.length-1)==="]"&&(e=e.substring(1,e.length-1)),e}function y(t,e){return e===0?0:t/e*1e3}function D(t){return t===null?"":t===void 0?"n/a":t<10?t.toFixed(2):t<100?t.toFixed(1):Math.round(t).toString()}function V(t){if(t==null)return"";let e="ms",r=t;return r>1e3&&(r/=1e3,e="s"),e==="s"&&r>60&&(r/=60,e="m"),e==="m"&&r>60&&(r/=60,e="h"),e==="h"&&r>24&&(r/=24,e="d"),e==="d"&&r>7&&(r/=7,e="w"),D(r)+e}function Z(t){return t===1?"1 row":`${L(t)} rows`}function L(t){if(t===null)return"";let e="",r=t;return r>1e3&&(r/=1e3,e="K"),r>1e3&&(r/=1e3,e="M"),r>1e3&&(r/=1e3,e="B"),r>1e3&&(r/=1e3,e="T"),r>1e3&&(r/=1e3,e="Q"),D(r)+e}function j(t){return A(t,"")}function k(t){return A(t,"B")}function A(t,e){if(t===null)return"";let r=e;if(t===0)return`0${r}`;let s=t;return s>=1024&&(s/=1024,r=`K${e}`),s>=1024&&(s/=1024,r=`M${e}`),s>=1024&&(s/=1024,r=`G${e}`),s>=1024&&(s/=1024,r=`T${e}`),s>=1024&&(s/=1024,r=`P${e}`),`${D(s)}${r}`}function C(t){const r=/^\s*(\d+(?:\.\d+)?)\s*([a-zA-Z]+)\s*$/.exec(t);if(r===null)return null;const s=parseFloat(r[1]);switch(r[2]){case"B":return s;case"kB":return s*2**10;case"MB":return s*2**20;case"GB":return s*2**30;case"TB":return s*2**40;case"PB":return s*2**50;default:return null}}function B(t){const e=C(t);return e==null?"":k(e)}function d(t){const r=/^\s*(\d+(?:\.\d+)?)\s*([a-zA-Z]+)\s*$/.exec(t);if(r===null)return null;const s=parseFloat(r[1]);switch(r[2]){case"ns":return s/1e6;case"us":return s/1e3;case"ms":return s;case"s":return s*1e3;case"m":return s*1e3*60;case"h":return s*1e3*60*60;case"d":return s*1e3*60*60*24;default:return null}}function v(t){return t?F(new Date(t)):"..."}function $(t){const e=t.getHours()%12||12,r=`${(t.getMinutes()<10?"0":"")+t.getMinutes()}`;return`${e}:${r}${t.getHours()>=12?"pm":"am"}`}function F(t){const e=t.getFullYear(),r=`${t.getMonth()+1}`,s=`${t.getDate()}`,u=s[1]?s:`0${s[0]}`,n=r[1]?r:`0${r[0]}`;return`${e}-${n}-${u} ${$(t)}`}const J=t=>p(t,[],"",""),p=(t,e,r,s)=>{let u=`${s}${r}${b(t)}
`;if(t.stack){let n=0;e!==null&&(n=_(t.stack,e));for(let o=0;o<t.stack.length-n;o+=1)u+=`${s}	at ${t.stack[o]}
`;n!==0&&(u+=`${s}	... ${n} more
`)}if(t.suppressed)for(let n=0;n<t.suppressed.length;n+=1)u+=p(t.suppressed[n],t.stack,"Suppressed: ",`${s}	`);return t.cause&&(u+=p(t.cause,t.stack,"Caused by: ",s)),u},_=(t,e)=>{let r=0;const s=Math.min(t.length,e.length);for(;r<s&&t[t.length-1-r]===e[e.length-1-r];)r+=1;return r},b=t=>t.message!==null?`${t.type} : ${t.message}`:t.type,T={TASKE_CREATED:l.primaryShade1,FIRST_SPLIT_STARTED:l.labels.purple,LAST_SPLIT_STARTED:l.labels.blue,LAST_SPLIT_ENDED:l.primary},Y=t=>{const e=t.flatMap(i=>i.tasks).map(i=>({taskId:S(i.taskStatus.taskId),time:{create:i.stats.createTime,firstStart:i.stats.firstStartTime,lastStart:i.stats.lastStartTime,lastEnd:i.stats.lastEndTime,end:i.stats.endTime}})),r=[],s=[];for(let i=0;i<e.length;i+=1){const a=e[i],N=a.taskId.substring(0,a.taskId.indexOf("."));S(a.taskId)==="0.0"&&r.push({id:N,title:`Stage ${N}`}),s.push({id:`${a.taskId} - created`,taskId:a.taskId,group:N,title:`${a.taskId} - created`,startTime:new Date(a.time.create).getTime(),endTime:new Date(a.time.firstStart).getTime(),backgroundColor:T.TASKE_CREATED}),s.push({id:`${a.taskId} - first split started`,taskId:a.taskId,group:N,title:`${a.taskId} - first split started`,startTime:new Date(a.time.firstStart).getTime(),endTime:new Date(a.time.lastStart).getTime(),backgroundColor:T.FIRST_SPLIT_STARTED}),s.push({id:`${a.taskId} - last split started`,taskId:a.taskId,group:N,title:`${a.taskId} - last split started`,startTime:new Date(a.time.lastStart).getTime(),endTime:new Date(a.time.lastEnd).getTime(),backgroundColor:T.LAST_SPLIT_STARTED}),s.push({id:`${a.taskId} - last split ended`,taskId:a.taskId,group:N,title:`${a.taskId} - last split ended`,startTime:new Date(a.time.lastEnd).getTime(),endTime:new Date(a.time.end).getTime(),backgroundColor:T.LAST_SPLIT_ENDED})}if(s.length===0)return;const u=s.map(i=>i.startTime).filter(Number.isFinite),n=s.map(i=>i.endTime).filter(Number.isFinite),o=u.length?Math.min(...u):void 0,E=n.length?Math.max(...n):void 0;return{timelineStartTime:o,timelineEndTime:E,groups:r,items:s}},I={RUNNING:t=>!(t.state==="QUEUED"||t.state==="FINISHED"||t.state==="FAILED"),QUEUED:t=>t.state==="QUEUED",FINISHED:t=>t.state==="FINISHED"},f={USER_ERROR:t=>t.state==="FAILED"&&t.errorType==="USER_ERROR",INTERNAL_ERROR:t=>t.state==="FAILED"&&t.errorType==="INTERNAL_ERROR",INSUFFICIENT_RESOURCES:t=>t.state==="FAILED"&&t.errorType==="INSUFFICIENT_RESOURCES",EXTERNAL:t=>t.state==="FAILED"&&t.errorType==="EXTERNAL"},m={CREATED:t=>Date.parse(t.queryStats.createTime),ELAPSED:t=>d(t.queryStats.elapsedTime),EXECUTION:t=>d(t.queryStats.executionTime),CPU:t=>d(t.queryStats.totalCpuTime),CUMULATIVE_MEMORY:t=>t.queryStats.cumulativeUserMemory,CURRENT_MEMORY:t=>C(t.queryStats.userMemoryReservation)},R={ASCENDING:t=>t,DESCENDING:t=>typeof t=="number"?-t:t},O=(t,e,r)=>{t.sort((s,u)=>{var E,i,a,N;const n=(E=m[e])==null?void 0:E.call(m,s),o=(i=m[e])==null?void 0:i.call(m,u);return typeof n=="number"&&typeof o=="number"?+((a=R[r])==null?void 0:a.call(R,n))-+((N=R[r])==null?void 0:N.call(R,o)):0})},q=(t,e,r,s)=>{O(t,e,r),t.length>s&&t.splice(s,t.length-s)},tt=(t,e,r,s)=>{const u=t.filter(n=>e.some(o=>{var E;return o&&((E=I[o])==null?void 0:E.call(I,n))})||r.some(o=>{var E;return o&&((E=f[o])==null?void 0:E.call(f,n))}));return s===""?u:u.filter(n=>{var E,i;const o=s.toLowerCase();return[n.queryId,U(n),n.queryTextPreview,n.sessionUser,n.sessionSource,(E=n.resourceGroupId)==null?void 0:E.join("."),(i=n.errorCode)==null?void 0:i.name,...n.clientTags||[],n.traceToken].some(a=>a==null?void 0:a.toLowerCase().includes(o))})},et=t=>(d(t.addInputWall)||0)+(d(t.getOutputWall)||0)+(d(t.finishWall)||0)+(d(t.blockedWall)||0),rt=t=>(d(t.addInputCpu)||0)+(d(t.getOutputCpu)||0)+(d(t.finishCpu)||0);export{z as A,T as B,G as C,v as D,f as E,Y as F,g as M,I as S,j as a,tt as b,x as c,Q as d,L as e,$ as f,D as g,U as h,H as i,K as j,P as k,k as l,d as m,S as n,X as o,B as p,y as q,C as r,q as s,V as t,F as u,J as v,Z as w,W as x,et as y,rt as z};
