import{c as _,y as D,u as j,f as z,H as B,h as $,m as t,l as n,I as k,B as p,p as T,S as H,G as E,t as G,J as O}from"./index-Cl9Gy4vs.js";var J=G('<form class="flex flex-col gap-4 p-6 pt-0"><div class="flex items-center gap-2 text-12-regular text-text-weak"><span class=truncate>/</span></div><div class="flex flex-col gap-2"><div class="flex items-center gap-2 text-12-regular text-text-weaker"><div class="flex-1 h-px bg-border-base"></div><span>or create blank</span><div class="flex-1 h-px bg-border-base"></div></div></div><div class="flex justify-end gap-2">'),K=G('<div class="flex flex-col gap-4 p-6 pt-0"><div class="flex items-center gap-2 text-12-regular text-text-weak"><span class=truncate>/</span></div><div class="flex justify-end gap-2">');function N(c){const h=_(),u=D(),C=j(),s=z(),m=()=>C.data.path.home||"",f=()=>m()+"/.turtlecode",[o,g]=B({name:"",busy:!1}),[w,d]=$(!1);function y(){d(!0)}async function r(){const e=o.name.trim();if(!e||o.busy)return;const a=`${f()}/${e}`;g("busy",!0);try{await u.fetch(`${u.url}/global/mkdir`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:a})}).then(l=>{if(!l.ok)throw new Error(`mkdir failed: ${l.status}`);return l.json()}),c.onSelect(c.multiple?[a]:a),h.close()}catch{O({variant:"error",title:s.t("dialog.directory.create.error")})}finally{g("busy",!1)}}function i(e){e.preventDefault(),r()}return t(E,{get title(){return s.t("dialog.directory.create")},class:"w-full max-w-[400px] mx-auto min-h-fit!",get children(){return[(()=>{var e=J(),a=e.firstChild,l=a.firstChild,x=l.firstChild,b=a.nextSibling,P=b.firstChild,S=b.nextSibling;return e.addEventListener("submit",i),n(a,t(k,{name:"folder-add-left",size:"small",class:"shrink-0 text-icon-weak"}),l),n(l,f,x),n(b,t(p,{type:"button",variant:"secondary",size:"large",class:"w-full",onClick:y,get children(){return[t(k,{name:"github",size:"small",class:"mr-2"}),"Clone from GitHub"]}}),P),n(b,t(T,{autofocus:!0,type:"text",get placeholder(){return s.t("dialog.directory.create.placeholder")},get value(){return o.name},onChange:v=>g("name",v),onKeyDown:v=>{v.key==="Enter"&&(v.preventDefault(),r())}}),null),n(S,t(p,{type:"button",variant:"ghost",size:"large",onClick:()=>h.close(),get children(){return s.t("common.cancel")}}),null),n(S,t(p,{type:"submit",variant:"primary",size:"large",get disabled(){return!o.name.trim()||o.busy},get children(){return s.t("dialog.directory.create.action")}}),null),e})(),t(H,{get when(){return w()},get children(){return t(I,{onSelect:e=>{d(!1),c.onSelect(e)},onClose:()=>d(!1)})}})]}})}function I(c){const h=_(),[u,C]=$(""),[s,m]=$(!1),f=z(),o=D(),g=j(),w=()=>g.data.path.home||"",d=()=>w()+"/.turtlecode";async function y(){const r=u().trim();if(!r||s())return;const i=r.split("/").pop()?.replace(/\.git$/,"")||"repo",e=`${d()}/${i}`;m(!0);try{await o.fetch(`${o.url}/global/clone`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:r,target:e})}).then(a=>{if(!a.ok)throw new Error(`clone failed: ${a.status}`);return a.json()}),c.onSelect(e),h.close()}catch{O({variant:"error",title:f.t("dialog.directory.create.error")})}finally{m(!1)}}return t(E,{title:"Clone from GitHub",class:"w-full max-w-[400px] mx-auto min-h-fit!",get children(){var r=K(),i=r.firstChild,e=i.firstChild,a=e.firstChild,l=i.nextSibling;return n(i,t(k,{name:"folder-add-left",size:"small",class:"shrink-0 text-icon-weak"}),e),n(e,d,a),n(r,t(T,{autofocus:!0,type:"text",placeholder:"https://github.com/user/repo",get value(){return u()},onChange:C,onKeyDown:x=>{x.key==="Enter"&&(x.preventDefault(),y())}}),l),n(l,t(p,{type:"button",variant:"ghost",size:"large",get onClick(){return c.onClose},get children(){return f.t("common.cancel")}}),null),n(l,t(p,{type:"button",variant:"primary",size:"large",get disabled(){return!u().trim()||s()},onClick:y,children:"Clone"}),null),r}})}export{N as DialogCreateProject};
