import{a as J,af as W,r as c,W as q,c as g,J as G,O as H,b as w,f as C,u as r,ac as K,i as s,w as d,h as u,ag as Q,ah as S,ai as X,g as T,t as $,a0 as Y}from"./jwt-decode.esm-BUhVyVlz.js";import{_ as x}from"./AbstraButton.vue_vue_type_script_setup_true_lang-B-6Kt_bn.js";import"./router--fZPWl_4.js";import{a as Z}from"./project-0z4ss282.js";import{T as ee}from"./tables-Dl6wbkmy.js";import{F as ae}from"./folder-Da3hAD4e.js";import{u as te}from"./organizationSwitcher-BEVyUYF-.js";import{n as A}from"./string-DGCBHlx5.js";import{S as ne}from"./index-BdAu_anO.js";import{A as oe}from"./index-Bg5_zFCB.js";(function(){try{var i=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},m=new Error().stack;m&&(i._sentryDebugIds=i._sentryDebugIds||{},i._sentryDebugIds[m]="e3670ab1-0a5a-4abb-a648-52480b95b5de",i._sentryDebugIdIdentifier="sentry-dbid-e3670ab1-0a5a-4abb-a648-52480b95b5de")}catch{}})();const be=J({__name:"CreateTableModal",props:{open:{type:Boolean},organizationId:{},folderId:{},projectId:{}},emits:["update:open","created"],setup(i,{emit:m}){const o=i,h=m,M=W(),y=te(),z=c(null),f=c(!1),I=c(!1),b=c([]),p=c({}),j=c({}),n=q({path:[],name:""}),B=g(()=>n.path[0]||""),L=g(()=>n.path[1]||""),_=g(()=>n.path[2]||""),k=g(()=>n.name.trim().length>0&&B.value.length>0&&L.value.length>0&&_.value.length>0),R=(e,a)=>e.filter(t=>t.folderId===a).sort((t,l)=>t.name.localeCompare(l.name)).map(t=>({value:t.id,label:t.name,isLeaf:!0})),F=(e,a)=>{const t=j.value[e]||[];return a.slice().sort((l,v)=>l.name.localeCompare(v.name)).map(l=>{const v=t.filter(N=>N.folderId===l.id);return{value:l.id,label:l.name,isLeaf:v.length===0,children:v.length>0?R(t,l.id):void 0}})},U=()=>y.organizations.slice().sort((e,a)=>e.name.localeCompare(a.name)).map(e=>{const a=p.value[e.id];return{value:e.id,label:e.name,isLeaf:!1,children:a?F(e.id,a):void 0}}),O=async e=>{if(p.value[e])return;const a=new ae,[t,l]=await Promise.all([a.list(e),Z.list(e)]);p.value[e]=t,j.value[e]=l},V=async e=>{const a=e[e.length-1];if(e.length===1){const t=a.value;if(p.value[t])return;a.loading=!0;try{await O(t),a.children=F(t,p.value[t])}catch(l){console.error("Failed to load data for org",l),a.children=[]}finally{a.loading=!1}b.value=[...b.value]}},P=async()=>{y.organizations.length===0&&await y.fetchOrganizations(),o.organizationId&&await O(o.organizationId),b.value=U()};G(P),H(()=>o.open,async e=>{if(e){n.name="",n.path=[],I.value=!0;try{await P(),o.organizationId&&o.folderId&&o.projectId?n.path=[o.organizationId,o.folderId,o.projectId]:o.organizationId&&o.folderId?n.path=[o.organizationId,o.folderId]:o.organizationId&&(n.path=[o.organizationId])}finally{I.value=!1}Y(()=>z.value?.focus())}});const E=()=>{h("update:open",!1)},D=async()=>{if(!(!k.value||f.value)){f.value=!0;try{const e=await ee.create(_.value,n.name.trim());h("created",{id:e.id,name:e.name}),h("update:open",!1),M.push(`/projects/${_.value}/tables/${e.id}`)}catch(e){console.error("Failed to create table",e)}finally{f.value=!1}}};return(e,a)=>(C(),w(r(K),{open:i.open,title:r(s).translate("i18n_breadcrumb_create_table"),"onUpdate:open":a[4]||(a[4]=t=>e.$emit("update:open",t))},{footer:d(()=>[u(x,{onClick:E},{default:d(()=>[T($(r(s).translate("i18n_breadcrumb_cancel")),1)]),_:1}),u(x,{type:"primary",loading:f.value,disabled:!k.value,onClick:D},{default:d(()=>[T($(r(s).translate("i18n_breadcrumb_create")),1)]),_:1},8,["loading","disabled"])]),default:d(()=>[u(r(Q),{model:n,layout:"vertical"},{default:d(()=>[u(r(S),{label:r(s).translate("i18n_breadcrumb_location"),name:"path"},{default:d(()=>[I.value?(C(),w(r(ne),{key:0,active:"",paragraph:!1,title:{width:"100%"}})):(C(),w(r(oe),{key:1,value:n.path,"onUpdate:value":a[0]||(a[0]=t=>n.path=t),options:b.value,"load-data":V,placeholder:r(s).translate("i18n_breadcrumb_select_project"),"expand-trigger":"hover","change-on-select":""},null,8,["value","options","placeholder"]))]),_:1},8,["label"]),u(r(S),{label:r(s).translate("i18n_breadcrumb_table_name"),name:"name"},{default:d(()=>[u(r(X),{ref_key:"inputRef",ref:z,value:n.name,"onUpdate:value":a[1]||(a[1]=t=>n.name=t),placeholder:r(s).translate("i18n_breadcrumb_enter_table_name"),onBlur:a[2]||(a[2]=t=>n.name=r(A)(n.name,!1)),onInput:a[3]||(a[3]=t=>n.name=r(A)(n.name,!0)),onPressEnter:D},null,8,["value","placeholder"])]),_:1},8,["label"])]),_:1},8,["model"])]),_:1},8,["open","title"]))}});export{be as _};
//# sourceMappingURL=CreateTableModal.vue_vue_type_script_setup_true_lang-BFUox8Ip.js.map
