const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dialog-create-project-Dw9WU914.js","assets/index-Cl9Gy4vs.js","assets/index-b2zsFxHN.css","assets/dialog-clone-project-w2gsbuNI.js"])))=>i.map(i=>d[i]);
import{u as K,y as B,c as G,f as M,h as V,i as b,z as Z,m,l as y,I as z,A as D,C as q,E as R,_ as j,G as H,t as S}from"./index-Cl9Gy4vs.js";import{L as N,f as Y}from"./list-CbLd2QpP.js";var P=S('<div class="w-full flex items-center justify-between rounded-md"><div class="flex items-center gap-x-3 grow min-w-0"><span class="text-14-regular text-text-interactive-base">'),J=S('<div class="w-full flex items-center justify-between rounded-md"><div class="flex items-center gap-x-3 grow min-w-0"><div class="flex items-center text-14-regular min-w-0"><span class="text-text-strong whitespace-nowrap">~</span><span class="text-text-weak whitespace-nowrap">/'),Q=S('<div class="w-full flex items-center justify-between rounded-md"><div class="flex items-center gap-x-3 grow min-w-0"><div class="flex items-center text-14-regular min-w-0"><span class="text-text-weak whitespace-nowrap overflow-hidden overflow-ellipsis truncate min-w-0"></span><span class="text-text-strong whitespace-nowrap"></span><span class="text-text-weak whitespace-nowrap">/');const $="__clone__";function W(r){return((r??"").split(/\r?\n/)[0]??"").replace(/[\u0000-\u001F\u007F]/g,"").trim()}function U(r){const e=r.replaceAll("\\","/");return e.startsWith("//")&&!e.startsWith("///")?"//"+e.slice(2).replace(/\/+/g,"/"):e.replace(/\/+/g,"/")}function w(r){const e=U(r);return/^[A-Za-z]:$/.test(e)?e+"/":e}function _(r){const e=w(r);return e==="/"||e==="//"||/^[A-Za-z]:\/$/.test(e)?e:e.replace(/\/+$/,"")}function X(r){const e=w(r);return e.startsWith("//")?"//":e.startsWith("/")?"/":/^[A-Za-z]:\//.test(e)?e.slice(0,3):""}function ee(r){const e=w(r.trim());return e?e.startsWith("~")?"tilde":X(e)?"absolute":"relative":"relative"}function E(r,e){const i=_(r);if(!e)return"";const n=_(e),a=i.toLowerCase(),c=n.toLowerCase();return a===c?"~":a.startsWith(c+"/")?"~"+i.slice(n.length):""}function A(r,e,i){const n=_(r);return ee(e)==="absolute"?n:E(n,i)||n}function te(r,e,i){const n=_(r),a=E(n,e),c=o=>o?o.endsWith("/")?o:o+"/":"",d=Array.from(new Set([n,c(n),a,c(a),R(n)].filter(Boolean))).join(`
`);return{absolute:n,search:d,group:i}}function re(r){const e=new Set;return r.filter(i=>e.has(i.absolute)?!1:(e.add(i.absolute),!0))}function ne(r){const e=new Map;let i=0;const n=async c=>{const d=_(c),o=e.get(d);if(o)return o;const g=r.sdk.client.file.list({directory:d,path:""}).then(h=>h.data??[]).catch(()=>[]).then(h=>h.filter(u=>u.type==="directory").map(u=>({name:u.name,absolute:_(w(u.absolute))})));return e.set(d,g),g},a=async(c,d,o)=>{const g=await n(c);return d?Y.go(d,g,{key:"name",limit:o}).map(h=>h.obj.absolute):g.slice(0,o).map(h=>h.absolute)};return async c=>{const d=++i,o=()=>d===i,g=W(c),h=_(r.start()??"");if(!h)return[];const u=w(g),v=u.startsWith("~/")?u.slice(2):u.replace(/^\/+/,""),x=await a(h,v.split("/")[0]??"",50);return o()?Array.from(new Set(x)).slice(0,50):[]}}function ie(r){const e=K(),i=B(),n=G(),a=M(),[c,d]=V("");let o;const g=b(()=>!(e.data.path.home||e.data.path.directory)),[h]=Z(()=>g()?!0:void 0,async()=>i.client.path.get().then(t=>t.data).catch(()=>{}),{initialValue:void 0}),u=b(()=>e.data.path.home||h.latest?.home||""),v=b(()=>u()+"/.turtlecode"),x=b(()=>v()),L=ne({sdk:i,start:x}),F={absolute:"__create__",search:a.t("dialog.directory.create")+`
new blank project`,group:"create"},I={absolute:$,search:a.t("dialog.clone.title")+`
clone github import`,group:"create"},O=async t=>{const s=(await L(t)).map(f=>te(f,u(),"folders"));return[F,I,...re(s)]};function k(t){r.onSelect(r.multiple?[t]:t),n.close()}return m(H,{get title(){return r.title??a.t("command.project.open")},get children(){return m(N,{get search(){return{placeholder:a.t("dialog.directory.search.placeholder"),autofocus:!0}},get emptyMessage(){return a.t("dialog.directory.empty")},get loadingMessage(){return a.t("common.loading")},items:O,key:t=>t.absolute,filterKeys:["search"],groupBy:t=>t.group,sortGroupsBy:(t,l)=>t.category===l.category?0:t.category==="create"?-1:l.category==="create"?1:t.category==="recent"?-1:1,groupHeader:t=>{if(t.category!=="create")return t.category==="recent"?a.t("home.recentProjects"):a.t("command.project.open")},ref:t=>o=t,onFilter:t=>d(W(t)),onKeyEvent:(t,l)=>{if(t.key!=="Tab"||t.shiftKey||!l)return;t.preventDefault(),t.stopPropagation();const s=A(l.absolute,c(),u());o?.setFilter(s.endsWith("/")?s:s+"/")},onSelect:t=>{if(t){if(t.absolute==="__create__"){n.close(),setTimeout(()=>{j(()=>import("./dialog-create-project-Dw9WU914.js"),__vite__mapDeps([0,1,2])).then(l=>{n.show(()=>m(l.DialogCreateProject,{get multiple(){return r.multiple},get onSelect(){return r.onSelect}}),()=>r.onSelect(null))})});return}if(t.absolute===$){n.close(),setTimeout(()=>{j(()=>import("./dialog-clone-project-w2gsbuNI.js"),__vite__mapDeps([3,1,2])).then(l=>{n.show(()=>m(l.DialogCloneProject,{onSelect:s=>s&&k(s)}),()=>r.onSelect(null))})});return}k(t.absolute)}},children:t=>{if(t.absolute==="__create__")return(()=>{var s=P(),f=s.firstChild,p=f.firstChild;return y(f,m(z,{name:"plus",size:"small",class:"shrink-0 size-4 text-icon-interactive-base"}),p),y(p,()=>a.t("dialog.directory.create")),s})();if(t.absolute===$)return(()=>{var s=P(),f=s.firstChild,p=f.firstChild;return y(f,m(z,{name:"branch",size:"small",class:"shrink-0 size-4 text-icon-interactive-base"}),p),y(p,()=>a.t("dialog.clone.title")),s})();const l=A(t.absolute,c(),u());return l==="~"?(()=>{var s=J(),f=s.firstChild,p=f.firstChild;return y(f,m(D,{get node(){return{path:t.absolute,type:"directory"}},class:"shrink-0 size-4"}),p),s})():(()=>{var s=Q(),f=s.firstChild,p=f.firstChild,C=p.firstChild,T=C.nextSibling;return y(f,m(D,{get node(){return{path:t.absolute,type:"directory"}},class:"shrink-0 size-4"}),p),y(C,()=>q(l)),y(T,()=>R(l)),s})()}})}})}export{ie as DialogSelectDirectory};
