import{r as a,j as e}from"./vendor-react-wBh_31cN.js";import{G as F,a0 as N,h as w}from"./index-dNe6i2rS.js";import{C as b}from"./code-input-W_9wcAaJ.js";import{I as y,a as E}from"./input-DFI7JniT.js";import{u as I}from"./useDebounce-BiuGz9t2.js";import{b as k}from"./index-B3Hxcv-8.js";import{c as $,d as G}from"./file-utils-B4k-DQmp.js";import{u as L}from"./FileContent-BERXb-dA.js";import{P as M}from"./PopupWithTitle-DxbkhXOh.js";import{A as S}from"./AnimatedLoadingIcon-mddZBUgk.js";import{c as A}from"./vendor-router-D1GqFWiT.js";import{i as D}from"./ifElse-D151OpR6.js";import{i as O}from"./includes-ucXR_9jq.js";import{a as T}from"./always-oSAuSdys.js";const z=D(O("."),w(t=>$({fileName:t}),G),T(void 0)),B=({checkingFile:t,content:o,fileExist:h,fileName:f,isCreating:m,isOpen:i,isSuccess:c,mode:n,popupTitle:u,rightIcon:p,children:s,handleSave:x,setContent:l,setFileName:d,setIsOpen:r})=>e.jsxs(e.Fragment,{children:[s==null?void 0:s({onOpen:()=>r(!0)}),e.jsx(M,{titleContent:u,isOpen:i,onClose:()=>r(!1),footer:e.jsxs("div",{className:"flex gap-3",children:[e.jsx(F,{variant:"secondary",onClick:()=>r(!1),children:"Cancel"}),e.jsx(F,{onClick:x,disabled:t||m,children:h?"Overwrite File":"Create File"})]}),children:e.jsxs("div",{className:"flex h-full min-h-0 w-full flex-col gap-5",children:[e.jsxs("div",{className:"shrink-0",children:[e.jsxs("div",{className:"relative",children:[e.jsx(y,{placeholder:"name.py",value:f,onChange:g=>d(g.target.value),autoFocus:!0}),p&&e.jsx("div",{className:"absolute right-2 top-1",children:p})]}),c&&e.jsx(E,{intent:"error",children:"File with same name already exists. Saving will overwrite the existing file."})]}),e.jsx(b,{value:o,onChange:l,mode:n,height:"100%",className:"h-full min-h-0 flex-1"})]})})]}),ee=a.memo(B),te=({specifiedUploadPath:t,onSuccess:o})=>{const{id:h}=A(),[f,m]=a.useState(!1),[i,c]=a.useState(""),[n,u]=a.useState(""),p=z(i),s=I(i,400),{currentData:x,isFetching:l,isError:d,isSuccess:r}=k({id:+h,path:`${t}/${s}`},{skip:!s.trim()}),{create:g,isCreating:C}=L(),v=a.useCallback(async()=>{g({fileName:i,content:n,path:t,overwrite:r,onSuccess:()=>{m(!1),c(""),u(""),o==null||o(`${t}/${i}`)}})},[n,g,i,r,o,t]),j=a.useMemo(()=>{if(l)return e.jsx(S,{size:"lg"});if(d)return e.jsx(N,{icon:"validate",color:"primary"});if(r&&s.trim())return e.jsx(N,{icon:"info",color:"labels.orange"})},[l,d,r,s]);return a.useMemo(()=>({checkingFile:l,content:n,fileExist:x,fileName:i,isCreating:C,isOpen:f,isSuccess:r&&!!s.trim(),mode:p,popupTitle:`Create new file in ${t}`,rightIcon:j,handleSave:v,setContent:u,setFileName:c,setIsOpen:m}),[l,n,s,x,i,C,f,r,p,j,t,v,u,c,m])};export{ee as C,te as u};
