(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[79851],{25182:(e,t,l)=>{"use strict";l.d(t,{A:()=>r});let r=(0,l(99537).A)("eye",[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",key:"1nclc0"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]])},88737:(e,t,l)=>{Promise.resolve().then(l.bind(l,97616))},97616:(e,t,l)=>{"use strict";l.r(t),l.d(t,{default:()=>w});var r=l(95155),s=l(73321),n=l(3765),i=l(92571),a=l(25182);let c=(0,l(99537).A)("text-wrap",[["path",{d:"m16 16-3 3 3 3",key:"117b85"}],["path",{d:"M3 12h14.5a1 1 0 0 1 0 7H13",key:"18xa6z"}],["path",{d:"M3 19h6",key:"1ygdsz"}],["path",{d:"M3 5h18",key:"1u36vt"}]]);var o=l(12115),u=l(18189),d=l(96301),f=l(64233),m=l(53972);let h=new Map,x=new Map;function p({cwd:e,initialFile:t}){let{setSidebarSection:l,removeSidebarSection:s,closeSidebar:w}=(0,n.E2)(),[g,j]=(0,o.useState)(()=>t||h.get(e)||null),[v,k]=(0,o.useState)(null),[y,b]=(0,o.useState)(!1),[N,S]=(0,o.useState)(!1),[E,C]=(0,o.useState)(!1),F=(0,o.useRef)(0);(0,o.useEffect)(()=>{"1"===localStorage.getItem("cockpit-files-wrap")&&S(!0),"1"===localStorage.getItem("cockpit-files-preview")&&C(!0)},[]);let M=(0,o.useCallback)(()=>{S(e=>{let t=!e;return localStorage.setItem("cockpit-files-wrap",t?"1":"0"),t})},[]),_=(0,o.useCallback)(()=>{C(e=>{let t=!e;return localStorage.setItem("cockpit-files-preview",t?"1":"0"),t})},[]),A=(0,o.useCallback)(t=>{j(t),h.set(e,t),window.innerWidth<768&&w()},[e,w]);if((0,o.useEffect)(()=>(l({id:"file-tree",title:"Files",content:(0,r.jsx)(d.h,{cwd:e,selectedFile:g,onSelectFile:A}),order:30}),()=>s("file-tree")),[e,g,A,l,s]),(0,o.useEffect)(()=>{if(!g)return void k(null);let e=x.get(g);if(e)return void k(e);let t=++F.current;b(!0),fetch(`/api/filesystem/read?path=${encodeURIComponent(g)}`).then(e=>{if(!e.ok)throw Error("Failed to read file");return e.json()}).then(e=>{if(F.current===t){if(x.size>=50){let e=x.keys().next().value;void 0!==e&&x.delete(e)}x.set(g,e),k(e)}}).catch(()=>{F.current===t&&k(null)}).finally(()=>{F.current===t&&b(!1)})},[g]),!g)return(0,r.jsx)("div",{className:"flex items-center justify-center h-full text-sm text-muted-foreground",children:"Select a file to view"});if(y)return(0,r.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,r.jsx)(i.A,{className:"h-5 w-5 animate-spin text-muted-foreground"})});if(!v)return(0,r.jsx)("div",{className:"flex items-center justify-center h-full text-sm text-muted-foreground",children:"Failed to read file"});let I=function(e,t){if(t.startsWith(e)){let l=t.slice(e.length);return l.startsWith("/")?l.slice(1):l}return t}(e,g),z=(0,m.uk)(g)||g,W=I.slice(0,I.length-z.length),$=(0,u.WG)(g),B="markdown"===$||"mdx"===$,D=B&&E;return(0,r.jsxs)("div",{className:"flex flex-col h-full min-h-0",children:[(0,r.jsxs)("div",{className:"shrink-0 flex items-center gap-1 border-b px-4 py-2 font-mono text-xs",children:[W&&(0,r.jsx)("span",{className:"text-muted-foreground",children:W}),(0,r.jsx)("span",{className:"font-bold",children:z}),v.truncated&&(0,r.jsx)("span",{className:"ml-2 text-muted-foreground",children:"(truncated to 100KB)"}),(0,r.jsxs)("div",{className:"ml-auto flex items-center gap-1",children:[B&&(0,r.jsx)("button",{type:"button",onClick:_,"aria-label":E?"Show source":"Show preview","aria-pressed":E,title:E?"Show source":"Show preview",className:`flex items-center justify-center rounded p-1 hover:bg-accent ${E?"text-foreground":"text-muted-foreground"}`,children:(0,r.jsx)(a.A,{className:"h-3.5 w-3.5"})}),!D&&(0,r.jsx)("button",{type:"button",onClick:M,"aria-label":N?"Disable line wrap":"Enable line wrap","aria-pressed":N,title:N?"Disable line wrap":"Enable line wrap",className:`flex items-center justify-center rounded p-1 hover:bg-accent ${N?"text-foreground":"text-muted-foreground"}`,children:(0,r.jsx)(c,{className:"h-3.5 w-3.5"})})]})]}),v.binary?(0,r.jsx)("div",{className:"flex items-center justify-center flex-1 text-sm text-muted-foreground",children:"Binary file"}):D?(0,r.jsx)(f.Y,{content:v.content,className:"flex-1 min-h-0 overflow-y-auto p-4"}):(0,r.jsx)("div",{className:"flex-1 min-h-0 overflow-auto",children:(0,r.jsx)(u.NG,{code:v.content,language:$,dark:!("u"<typeof document)&&document.documentElement.classList.contains("dark"),fullHeight:!0,wrap:N})})]})}function w(){let e=(0,s.useSearchParams)(),t=e.get("cwd")||"",l=e.get("file");return((0,n.si)("Files"),(0,n.mq)(t||void 0),t)?(0,r.jsx)(p,{cwd:t,initialFile:l}):(0,r.jsx)("div",{className:"flex items-center justify-center h-full text-sm text-muted-foreground",children:"No working directory specified."})}}},e=>{e.O(0,[989,11242,3765,28441,93794,77358],()=>e(e.s=88737)),_N_E=e.O()}]);