import{bF as y,aU as C,C as N,cn as S,ae as k,af as D,ag as R,ah as w,j as v,a9 as I,ao as E,aq as L,q as b}from"./index-BJkJ93Lr.js";import{r,J as O,j as e}from"./vendor-tanstack-BVzzyDEt.js";import{I as M,Z as j}from"./vendor-date-2jFo9aCm.js";import{S as B}from"./index-BCjE1NvU.js";const F=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M21 9H3",key:"1338ky"}],["path",{d:"M21 15H3",key:"9uk58r"}]],W=y("rows-3",F),$=({logs:s,taskRun:t,onBottomReached:n,virtualize:d=!0,className:h})=>{const c=r.useRef(null),i=r.useRef(s);i.current=s;const m=r.useCallback(a=>i.current[a]?.id??a,[]),o=O({count:s.length,getScrollElement:()=>c.current,estimateSize:()=>75,overscan:5,getItemKey:m}),g=r.useCallback(a=>{a&&o.measureElement(a)},[o]),x=d?o.getVirtualItems():Array.from({length:s.length},(a,l)=>({index:l,size:75,start:l*75})),u=x.at(-1)?.index;r.useEffect(()=>{u!==void 0&&u>=s.length-1&&n()},[s.length,u,n]);const f=a=>{if(a===0)return!0;const l=s[a-1],p=s[a];return!M(l.timestamp,p.timestamp)};return s.length===0?e.jsx("div",{className:"flex flex-col gap-2 bg-muted p-2 rounded-md font-mono",children:e.jsx("span",{className:"text-muted-foreground",children:"No logs found"})}):e.jsx("div",{ref:c,className:C("bg-muted rounded-md font-mono p-4 overflow-y-auto",h),role:"log",children:e.jsx("ol",{className:"relative",style:{height:`${o.getTotalSize()}px`},children:x.map(a=>{const l=s[a.index],p=f(a.index);return e.jsxs("li",{"data-index":a.index,ref:g,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${a.start}px)`},children:[p&&e.jsx(V,{date:new Date(l.timestamp)}),e.jsx(T,{log:l,taskRunName:t?.name})]},l.id)})})})},T=({log:s,taskRunName:t})=>e.jsxs("div",{className:"grid grid-cols-[84px_minmax(0,1fr)_150px] gap-2 text-sm",children:[e.jsx("div",{children:e.jsx(z,{level:s.level})}),e.jsx("div",{className:"select-auto whitespace-pre-wrap break-words",children:s.message}),e.jsxs("div",{className:"text-xs grid grid-cols-1 gap-1 justify-items-end text-muted-foreground truncate",children:[e.jsx("span",{children:j(s.timestamp,"pp")}),t&&e.jsx("span",{children:t}),e.jsx("span",{className:"font-bold break-all whitespace-normal",children:s.name})]})]}),U=S("gap-1",{variants:{level:{CRITICAL:"bg-red-600 text-red-50 hover:bg-red-600",ERROR:"bg-red-600 text-red-50 hover:bg-red-600",WARNING:"bg-orange-600 text-orange-50 hover:bg-orange-600",INFO:"bg-sky-600 text-blue-50 hover:bg-sky-600",DEBUG:"bg-gray-700 text-gray-50 hover:bg-gray-700",CUSTOM:"bg-gray-700 text-gray-50 hover:bg-gray-700"}}}),z=({level:s})=>{const t=A(s);return e.jsx(N,{className:U({level:t}),children:t})};function A(s){const[t]=s.toString();switch(t){case"5":return"CRITICAL";case"4":return"ERROR";case"3":return"WARNING";case"2":return"INFO";case"1":return"DEBUG";default:return"CUSTOM"}}const V=({date:s})=>e.jsxs("div",{className:"flex flex-row justify-center items-center gap-2",children:[e.jsx("div",{className:"h-[1px] w-full bg-muted-foreground/30"}),e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:j(s,"MMM d, yyyy")}),e.jsx("div",{className:"h-[1px] w-full bg-muted-foreground/30"})]}),J=({open:s,onOpenChange:t,currentState:n,label:d,onConfirm:h,isLoading:c=!1})=>{const[i,m]=r.useState(void 0),[o,g]=r.useState("");r.useEffect(()=>{s||(m(void 0),g(""))},[s]);const x=()=>{i&&h({type:i,message:o||void 0})},u=!i||c;return e.jsx(k,{open:s,onOpenChange:t,children:e.jsxs(D,{"aria-describedby":void 0,children:[e.jsx(R,{children:e.jsxs(w,{children:["Change ",d," State"]})}),e.jsxs("div",{className:"space-y-4",children:[n&&e.jsxs("div",{children:[e.jsx(v,{className:"mb-2 block",children:"Current State"}),e.jsx(I,{type:n.type,name:n.name})]}),e.jsxs("div",{children:[e.jsx(v,{htmlFor:"desired-state",className:"mb-2 block",children:"Desired State"}),e.jsx(B,{value:i,onValueChange:m,terminalOnly:!0})]}),e.jsxs("div",{children:[e.jsx(v,{htmlFor:"message",className:"mb-2 block",children:"Reason (Optional)"}),e.jsx(E,{id:"message",value:o,onChange:f=>g(f.target.value),placeholder:"State changed manually via UI"})]})]}),e.jsxs(L,{children:[e.jsx(b,{type:"button",variant:"outline",onClick:()=>t(!1),disabled:c,children:"Close"}),e.jsx(b,{type:"button",onClick:x,disabled:u,loading:c,children:"Change"})]})]})})},K=()=>{const[s,t]=r.useState(!1),n=r.useCallback(()=>t(!0),[]),d=r.useCallback(()=>t(!1),[]);return{open:s,onOpenChange:t,openDialog:n,closeDialog:d}};export{J as C,W as R,$ as a,K as u};
//# sourceMappingURL=index-DZTWMzXC.js.map
