import{cd as b,g,W as w,aM as I,v,aw as R,ce as E,cf as _,cg as x,a8 as M,N as A,i as D,j as F}from"./B08CJtNn.js";const $={settings:"s",advisor:"i",metricview:"v",help:"h",commandcenter:"meta_k",showAllEntries:"ctrl_n",piniaDebug:"meta_d"},m={meta:"",ctrl:"",alt:"",win:"⊞",command:"⌘",shift:"⇧",control:"⌃",option:"⌥",enter:"↵",delete:"⌦",backspace:"⌫",escape:"⎋",tab:"⇥",capslock:"⇪",arrowup:"↑",arrowright:"→",arrowdown:"↓",arrowleft:"←",pageup:"⇞",pagedown:"⇟",home:"↖",end:"↘"},k=()=>{const r=g(()=>navigator&&navigator.userAgent&&navigator.userAgent.match(/Macintosh;/)),l=w({meta:" ",alt:" ",ctrl:" "});I(()=>{l.meta=r.value?m.command:"Ctrl",l.ctrl=r.value?m.control:"Ctrl",l.alt=r.value?m.option:"Alt"});function c(o){if(o)return["meta","alt","ctrl"].includes(o)?l[o]:m[o]||o.toUpperCase()}return{macOS:r,getKbdKey:c}},L=b(k),N=/^[^-]+.*-.*[^-]+$/,T=/^[^_]+.*_.*[^_]+$/,j=["arrowleft","arrowright","arrowup","arrowright","tab","escape","enter","backspace"];function B(r,l={}){const c=v([]),o=()=>{c.value.splice(0,c.value.length)},f=R(o,l.chainDelay??800),{macOS:h}=L(),d=E(),K=e=>{if(!e.key)return;const n=/^[a-z]{1}$/i.test(e.key),a=j.includes(e.key.toLowerCase());let i;if(c.value.push(e.key),c.value.length>=2){i=c.value.slice(-2).join("-");for(const s of t.value.filter(u=>u.chained))if(s.key===i){s.enabled&&(e.preventDefault(),s.handler(e)),o();return}}for(const s of t.value.filter(u=>!u.chained))if(e.key.toLowerCase()===s.key&&e.metaKey===s.metaKey&&e.ctrlKey===s.ctrlKey&&!((n||a)&&e.shiftKey!==s.shiftKey)){s.enabled&&(e.preventDefault(),s.handler(e)),o();return}f()},y=g(()=>{const e=d.value?.tagName,n=d.value?.contentEditable;return e==="INPUT"||e==="TEXTAREA"||n==="true"||n==="plaintext-only"?d.value?.name||!0:!1}),t=g(()=>Object.entries(_(r)).map(([e,n])=>{if(!n)return null;let a;e.includes("-")&&e!=="-"&&!e.includes("_")&&!e.match(N)?.length&&console.trace(`[Shortcut] Invalid key: "${e}"`),e.includes("_")&&e!=="_"&&!e.match(T)?.length&&console.trace(`[Shortcut] Invalid key: "${e}"`);const i=e.includes("-")&&e!=="-"&&!e.includes("_");if(i)a={key:e.toLowerCase(),metaKey:!1,ctrlKey:!1,shiftKey:!1,altKey:!1};else{const u=e.toLowerCase().split("_").map(p=>p);a={key:u.filter(p=>!["meta","command","ctrl","shift","alt","option"].includes(p)).join("_"),metaKey:u.includes("meta")||u.includes("command"),ctrlKey:u.includes("ctrl"),shiftKey:u.includes("shift"),altKey:u.includes("alt")||u.includes("option")}}if(a.chained=i,!h.value&&a.metaKey&&!a.ctrlKey&&(a.metaKey=!1,a.ctrlKey=!0),typeof n=="function"?a.handler=n:typeof n=="object"&&(a={...a,handler:n.handler}),!a.handler)return console.trace("[Shortcut] Invalid value"),null;let s=!0;return n.usingInput?typeof n.usingInput=="string"&&(s=y.value===n.usingInput):s=!y.value,a.enabled=s,a}).filter(Boolean));return x("keydown",K)}const O=M("TestrunnerStore",()=>{const r=v({}),l=v(!0),{kapi:c}=A(),o=D(),f=v(null),h=async(t,e=!1)=>{if(t&&!(r.value[t]&&!e)){l.value=!0;try{const{lastRunInSeconds:n,nextRunInSeconds:a,isFirstRun:i}=await c("System").then(S=>S.getNextLastFullRun(Number(t))),s=n+a,u=Math.floor(n/s*100),p=100/s;r.value[String(t)]={nextRunInMs:a*1e3,progress:u,progressPerSecond:p,isFirstRun:i}}catch(n){console.error(n)}finally{l.value=!1,f.value=t}}},d=(t,e)=>{if(!t||!r.value[t])return;const n=r.value[t],a=n.progress+n.progressPerSecond*e,i=n.nextRunInMs-e*1e3;r.value[t].nextRunInMs=i,r.value[t].progress=a};return F(()=>o.params.sid,t=>{t&&t!==f.value&&(f.value=t,h(t))},{immediate:!0}),{runnerState:r,polling:l,initiateRunner:h,overrideSidRunner:d,getRunnerState:t=>r.value[t],overrideFirstRunState:t=>{t&&r.value[t]&&(r.value[t].isFirstRun=!1)}}});export{L as a,B as d,$ as s,O as u};
