import{e as q,K as J,r as c,N as K,b as g,O as Q,q as C,g as w,s as r,M as G,J as s,C as d,x as u,P as H,Q as S,R as W,S as D,T,U as X}from"./jwt-decode.esm-rEBc1yJt.js";import{_ as x}from"./AbstraButton.vue_vue_type_script_setup_true_lang-CQ398DyA.js";import"./router-BaFu-do7.js";import{P as Y}from"./project-D1d7g0j_.js";import{T as Z}from"./tables-DdYqLMX_.js";import{F as ee}from"./cascaderStore-Dimdeu3o.js";import{u as ae}from"./organizationSwitcher-DLmZV2E5.js";import{n as $}from"./string-BwJCihDb.js";import{S as te}from"./index-D9LKNmUT.js";import{A as ne}from"./index-BYDOvbpL.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]="baa463eb-3587-494b-b14e-dcd4ec12095e",i._sentryDebugIdIdentifier="sentry-dbid-baa463eb-3587-494b-b14e-dcd4ec12095e")}catch{}})();const fe=q({__name:"CreateTableModal",props:{open:{type:Boolean},organizationId:{},folderId:{},projectId:{}},emits:["update:open","created"],setup(i,{emit:m}){const o=i,h=m,A=J(),y=ae(),z=c(null),f=c(!1),I=c(!1),b=c([]),p=c({}),j=c({}),n=K({path:[],name:""}),M=g(()=>n.path[0]||""),B=g(()=>n.path[1]||""),_=g(()=>n.path[2]||""),k=g(()=>n.name.trim().length>0&&M.value.length>0&&B.value.length>0&&_.value.length>0),L=(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})),P=(e,a)=>{const t=j.value[e]||[];return a.slice().sort((l,v)=>l.name.localeCompare(v.name)).map(l=>{const v=t.filter(E=>E.folderId===l.id);return{value:l.id,label:l.name,isLeaf:v.length===0,children:v.length>0?L(t,l.id):void 0}})},R=()=>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?P(e.id,a):void 0}}),F=async e=>{if(p.value[e])return;const a=new ee,[t,l]=await Promise.all([a.list(e),Y.list(e)]);p.value[e]=t,j.value[e]=l},U=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 F(t),a.children=P(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]}},N=async()=>{y.organizations.length===0&&await y.fetchOrganizations(),o.organizationId&&await F(o.organizationId),b.value=R()};Q(()=>o.open,async e=>{if(e){n.name="",n.path=[],I.value=!0;try{await N(),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}X(()=>z.value?.focus())}});const V=()=>{h("update:open",!1)},O=async()=>{if(!(!k.value||f.value)){f.value=!0;try{const e=await Z.create(_.value,n.name.trim());h("created",{id:e.id,name:e.name}),h("update:open",!1),A.push(`/projects/${_.value}/tables/${e.id}`)}catch(e){console.error("Failed to create table",e)}finally{f.value=!1}}};return(e,a)=>(w(),C(r(G),{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:V},{default:d(()=>[D(T(r(s).translate("i18n_breadcrumb_cancel")),1)]),_:1}),u(x,{type:"primary",loading:f.value,disabled:!k.value,onClick:O},{default:d(()=>[D(T(r(s).translate("i18n_breadcrumb_create")),1)]),_:1},8,["loading","disabled"])]),default:d(()=>[u(r(H),{model:n,layout:"vertical"},{default:d(()=>[u(r(S),{label:r(s).translate("i18n_breadcrumb_location"),name:"path"},{default:d(()=>[I.value?(w(),C(r(te),{key:0,active:"",paragraph:!1,title:{width:"100%"}})):(w(),C(r(ne),{key:1,value:n.path,"onUpdate:value":a[0]||(a[0]=t=>n.path=t),options:b.value,"load-data":U,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(W),{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($)(n.name,!1)),onInput:a[3]||(a[3]=t=>n.name=r($)(n.name,!0)),onPressEnter:O},null,8,["value","placeholder"])]),_:1},8,["label"])]),_:1},8,["model"])]),_:1},8,["open","title"]))}});export{fe as _};
//# sourceMappingURL=CreateTableModal.vue_vue_type_script_setup_true_lang-EmXnbY8I.js.map
