import{d as h,eB as x,eA as z,r as D,G as O,a as A,b as d,ev as E,u as s,c as j,ex as w,f as p,w as f,bq as F,bH as B,cw as M}from"./outputWidgets.3c34606b.js";import{e as $,u as S,K as T,F as U}from"./icons.e6ec075a.js";import{a as V}from"./asyncComputed.8707f293.js";import"./router.56692652.js";import"./index.c3f2d302.js";import{P as g}from"./project.d605460b.js";import{O as G}from"./organization.8d89f32c.js";import{C as L}from"./CrudView.7c2b0e6f.js";import{a as q}from"./ant-design.8f4f3ad4.js";import{A as H}from"./FormItem.895a8678.js";import{M as J}from"./Modal.10b1f4fc.js";import"./index.dd5bce3f.js";import"./index.cf4c23b9.js";import"./record.c46cf28f.js";import"./pubsub.28c1e0e3.js";import"./Title.f4855332.js";import"./Text.aa4a1cf1.js";import"./Form.d74c49d4.js";import"./hasIn.01f4de81.js";import"./DocsButton.vue_vue_type_script_setup_true_lang.36eacc0b.js";import"./url.425cd9cb.js";import"./index.507e77a0.js";import"./index.5cd5e321.js";(function(){try{var l=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},c=new Error().stack;c&&(l._sentryDebugIds=l._sentryDebugIds||{},l._sentryDebugIds[c]="ec420e3b-100f-4c5f-b68e-cc9b780d8bfe",l._sentryDebugIdIdentifier="sentry-dbid-ec420e3b-100f-4c5f-b68e-cc9b780d8bfe")}catch{}})();const be=h({__name:"Projects",setup(l){const c=[{key:"name",label:"Project Name"}],m=x().params.organizationId,k=z(),{loading:C,result:r,refetch:y}=V(()=>Promise.all([g.list(m),G.get(m)]).then(([t,e])=>({projects:t,organization:e}))),u=({key:t})=>k.push({name:"project",params:{projectId:t}}),P=async t=>{const e=await g.create({organizationId:m,name:t.name});u({key:e.id})},I=async({key:t})=>{var o,a;if(await q("Are you sure you want to delete this project?"))try{await((a=(o=r.value)==null?void 0:o.projects.find(i=>i.id===t))==null?void 0:a.delete())}catch(i){M.error({message:"Error deleting project",description:String(i)})}finally{await y()}},_=async({key:t})=>{var o;const e=(o=r.value)==null?void 0:o.projects.find(a=>a.id===t);if(e){const a=await e.duplicate();u({key:a.id})}},n=D({state:"idle"});function N(t){n.value={state:"renaming",projectId:t.id,newName:t.name}}async function b(t){if(n.value.state==="renaming"&&t){const{projectId:e,newName:o}=n.value;await g.rename(e,o),y()}n.value={state:"idle"}}const R=O(()=>{var t,e;return{columns:[{name:"Project Name",align:"left"},{name:"",align:"right"}],rows:(e=(t=r.value)==null?void 0:t.projects.map(o=>{var a,i;return{key:o.id,cells:[{type:"link",text:o.name,to:`/projects/${encodeURIComponent(o.id)}`},{type:"actions",actions:[{icon:$,label:"Go to project",onClick:u},{icon:S,label:"Rename project",onClick:()=>N(o)},...(i=(a=r.value)==null?void 0:a.organization)!=null&&i.featureFlags.DUPLICATE_PROJECTS?[{icon:T,label:"Duplicate",onClick:_}]:[],{icon:U,label:"Delete",onClick:I,dangerous:!0}]}]}}))!=null?e:[]}});return(t,e)=>{const o=A("ant-form");return d(),E(F,null,[s(r)?(d(),j(L,{key:0,"entity-name":"project",loading:s(C),title:`${s(r).organization.name}'s Projects`,description:"Organize your team's work into different Projects, each with it's own subdomain.","create-button-text":"Create Project","empty-title":"No projects here yet",table:R.value,fields:c,onCreate:P},null,8,["loading","title","table"])):w("",!0),p(s(J),{open:n.value.state==="renaming",title:"Rename organization",onCancel:e[1]||(e[1]=a=>b(!1)),onOk:e[2]||(e[2]=a=>b(!0))},{default:f(()=>[n.value.state==="renaming"?(d(),j(o,{key:0,layout:"vertical"},{default:f(()=>[p(s(H),{label:"New name"},{default:f(()=>[p(s(B),{value:n.value.newName,"onUpdate:value":e[0]||(e[0]=a=>n.value.newName=a)},null,8,["value"])]),_:1})]),_:1})):w("",!0)]),_:1},8,["open"])],64)}}});export{be as default};
//# sourceMappingURL=Projects.2bd510a7.js.map
