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