const c={QUEUED:"var(--quartz-colors-grayShade2)",RUNNING:"var(--quartz-colors-primaryShade1)",PLANNING:"var(--quartz-colors-labels-purple)",FINISHED:"var(--quartz-colors-primaryShade1)",BLOCKED:"var(--quartz-colors-labels-red-_light)",USER_ERROR:"var(--quartz-colors-labels-orange)",CANCELED:"var(--quartz-colors-labels-orange-_dark)",INSUFFICIENT_RESOURCES:"var(--quartz-colors-yellow-700)",EXTERNAL:"var(--quartz-colors-labels-red-_dark)",UNKNOWN_ERROR:"var(--quartz-colors-labels-redShade2)"},M={AriaChartFill:"#89f7d4ff",AreaChartStroke:"#229570"};function w(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 G=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}},z=t=>{if(t.state!=="RUNNING")return 100;const e=t.queryStats.progressPercentage||0;return Math.round(e)},C=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,D=.2;function H(t,e){return e.length===0?e.concat([t]):e.concat([t]).slice(Math.max(e.length-g,0))}function P(t,e){if(e.length===0)return e.concat([t]);let r=t*D+e[e.length-1]*(1-D);return t<1&&(r=0),e.concat([r]).slice(Math.max(e.length-g,0))}function v(t,e){return t&&t.length>e?`${t.substring(0,e)}...`:t}function m(t){return t.slice(t.indexOf(".")+1,t.length)}function K(t){return Number.parseInt(m(m(t)),10)}function Q(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 x(t,e){return e===0?0:t/e*1e3}function p(t){return t===null?"":t===void 0?"n/a":t<10?t.toFixed(2):t<100?t.toFixed(1):Math.round(t).toString()}function W(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"),p(r)+e}function X(t){return t===1?"1 row":`${U(t)} rows`}function U(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"),p(r)+e}function y(t){return h(t,"")}function L(t){return h(t,"B")}function h(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}`),`${p(s)}${r}`}function A(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 V(t){const e=A(t);return e==null?"":L(e)}function E(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 Z(t){return t?$(new Date(t)):"..."}function k(t){const e=t.getHours()%12||12,r=`${(t.getMinutes()<10?"0":"")+t.getMinutes()}`;return`${e}:${r}${t.getHours()>=12?"pm":"am"}`}function $(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} ${k(t)}`}const j=t=>f(t,[],"",""),f=(t,e,r,s)=>{let u=`${s}${r}${_(t)}
`;if(t.stack){let n=0;e!==null&&(n=F(t.stack,e));for(let i=0;i<t.stack.length-n;i+=1)u+=`${s}	at ${t.stack[i]}
`;n!==0&&(u+=`${s}	... ${n} more
`)}if(t.suppressed)for(let n=0;n<t.suppressed.length;n+=1)u+=f(t.suppressed[n],t.stack,"Suppressed: ",`${s}	`);return t.cause&&(u+=f(t.cause,t.stack,"Caused by: ",s)),u},F=(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},_=t=>t.message!==null?`${t.type} : ${t.message}`:t.type,T={TASKE_CREATED:"var(--quartz-colors-primaryShade1)",FIRST_SPLIT_STARTED:"var(--quartz-colors-labels-purple)",LAST_SPLIT_STARTED:"var(--quartz-colors-labels-blue)",LAST_SPLIT_ENDED:"var(--quartz-colors-primary)"},B=t=>{const e=t.flatMap(o=>o.tasks).map(o=>({taskId:m(o.taskStatus.taskId),time:{create:o.stats.createTime,firstStart:o.stats.firstStartTime,lastStart:o.stats.lastStartTime,lastEnd:o.stats.lastEndTime,end:o.stats.endTime}})),r=[],s=[];for(let o=0;o<e.length;o+=1){const a=e[o],d=a.taskId.substring(0,a.taskId.indexOf("."));m(a.taskId)==="0.0"&&r.push({id:d,title:`Stage ${d}`}),s.push({id:`${a.taskId} - created`,taskId:a.taskId,group:d,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:d,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:d,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:d,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(o=>o.startTime).filter(Number.isFinite),n=s.map(o=>o.endTime).filter(Number.isFinite),i=u.length?Math.min(...u):void 0,l=n.length?Math.max(...n):void 0;return{timelineStartTime:i,timelineEndTime:l,groups:r,items:s}},S={RUNNING:t=>!(t.state==="QUEUED"||t.state==="FINISHED"||t.state==="FAILED"),QUEUED:t=>t.state==="QUEUED",FINISHED:t=>t.state==="FINISHED"},I={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"},N={CREATED:t=>Date.parse(t.queryStats.createTime),ELAPSED:t=>E(t.queryStats.elapsedTime),EXECUTION:t=>E(t.queryStats.executionTime),CPU:t=>E(t.queryStats.totalCpuTime),CUMULATIVE_MEMORY:t=>t.queryStats.cumulativeUserMemory,CURRENT_MEMORY:t=>A(t.queryStats.userMemoryReservation)},R={ASCENDING:t=>t,DESCENDING:t=>typeof t=="number"?-t:t},b=(t,e,r)=>{t.sort((s,u)=>{var l,o,a,d;const n=(l=N[e])==null?void 0:l.call(N,s),i=(o=N[e])==null?void 0:o.call(N,u);return typeof n=="number"&&typeof i=="number"?+((a=R[r])==null?void 0:a.call(R,n))-+((d=R[r])==null?void 0:d.call(R,i)):0})},J=(t,e,r,s)=>{b(t,e,r),t.length>s&&t.splice(s,t.length-s)},Y=(t,e,r,s)=>{const u=t.filter(n=>e.some(i=>{var l;return i&&((l=S[i])==null?void 0:l.call(S,n))})||r.some(i=>{var l;return i&&((l=I[i])==null?void 0:l.call(I,n))}));return s===""?u:u.filter(n=>{var l,o;const i=s.toLowerCase();return[n.queryId,C(n),n.queryTextPreview,n.sessionUser,n.sessionSource,(l=n.resourceGroupId)==null?void 0:l.join("."),(o=n.errorCode)==null?void 0:o.name,...n.clientTags||[],n.traceToken].some(a=>a==null?void 0:a.toLowerCase().includes(i))})},q=t=>(E(t.addInputWall)||0)+(E(t.getOutputWall)||0)+(E(t.finishWall)||0)+(E(t.blockedWall)||0),tt=t=>(E(t.addInputCpu)||0)+(E(t.getOutputCpu)||0)+(E(t.finishCpu)||0);export{K as A,T as B,M as C,Z as D,I as E,B as F,g as M,S,y as a,Y as b,P as c,H as d,U as e,k as f,p as g,C as h,w as i,z as j,G as k,L as l,E as m,m as n,Q as o,V as p,x as q,A as r,J as s,v as t,W as u,$ as v,j as w,X as x,q as y,tt as z};
