import{d as D,eB as R,eA as h,r as x,H as O,a as A,b as u,ev as E,u as s,c as w,ex as b,f as p,w as f,a$ as $,bO as B,cz as F}from"./outputWidgets.12d07fe6.js";import{a as M}from"./asyncComputed.4b96df58.js";import{a as S}from"./ant-design.7bb70225.js";import"./router.d820a159.js";import"./index.a1296999.js";import{P as g}from"./project.72347f9d.js";import{O as T}from"./organization.8450b28c.js";import{C as U}from"./CrudView.1d47b402.js";import{e as V,q as L,I as q,D as G}from"./icons.f2b4f37f.js";import{A as H}from"./FormItem.791863a4.js";import{M as J}from"./Modal.f73330d1.js";import"./index.209174e2.js";import"./index.cf4c23b9.js";import"./record.9ee5b79a.js";import"./pubsub.1984cbae.js";import"./Paragraph.01fbd56d.js";import"./Base.24118e9f.js";import"./Typography.45a7b8d7.js";import"./Form.a87331b6.js";import"./hasIn.7e305b7d.js";import"./DocsButton.vue_vue_type_script_setup_true_lang.0bca7c74.js";import"./url.f2a2de62.js";import"./index.04a061be.js";import"./Title.cc650707.js";import"./Text.6b94c3bc.js";import"./index.d055bc8b.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]="d09d7c12-11ad-4c30-a41c-f758d5be58c7",l._sentryDebugIdIdentifier="sentry-dbid-d09d7c12-11ad-4c30-a41c-f758d5be58c7")}catch{}})();const ve=D({__name:"Projects",setup(l){const c=[{key:"name",label:"Project Name"}],m=R().params.organizationId,k=h(),{loading:C,result:r,refetch:y}=M(()=>Promise.all([g.list(m),T.get(m)]).then(([t,e])=>({projects:t,organization:e}))),d=({key:t})=>k.push({name:"project",params:{projectId:t}}),P=async t=>{const e=await g.create({organizationId:m,name:t.name});d({key:e.id})},I=async({key:t})=>{var a,o;if(await S("Are you sure you want to delete this project?"))try{await((o=(a=r.value)==null?void 0:a.projects.find(i=>i.id===t))==null?void 0:o.delete())}catch(i){F.error({message:"Error deleting project",description:String(i)})}finally{await y()}},_=async({key:t})=>{var a;const e=(a=r.value)==null?void 0:a.projects.find(o=>o.id===t);if(e){const o=await e.duplicate();d({key:o.id})}},n=x({state:"idle"});function N(t){n.value={state:"renaming",projectId:t.id,newName:t.name}}async function j(t){if(n.value.state==="renaming"&&t){const{projectId:e,newName:a}=n.value;await g.rename(e,a),y()}n.value={state:"idle"}}const z=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(a=>{var o,i;return{key:a.id,cells:[{type:"link",text:a.name,to:`/projects/${encodeURIComponent(a.id)}`},{type:"actions",actions:[{icon:V,label:"Go to project",onClick:d},{icon:L,label:"Rename project",onClick:()=>N(a)},...(i=(o=r.value)==null?void 0:o.organization)!=null&&i.featureFlags.DUPLICATE_PROJECTS?[{icon:q,label:"Duplicate",onClick:_}]:[],{icon:G,label:"Delete",onClick:I,dangerous:!0}]}]}}))!=null?e:[]}});return(t,e)=>{const a=A("ant-form");return u(),E($,null,[s(r)?(u(),w(U,{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:z.value,fields:c,onCreate:P},null,8,["loading","title","table"])):b("",!0),p(s(J),{open:n.value.state==="renaming",title:"Rename organization",onCancel:e[1]||(e[1]=o=>j(!1)),onOk:e[2]||(e[2]=o=>j(!0))},{default:f(()=>[n.value.state==="renaming"?(u(),w(a,{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]=o=>n.value.newName=o)},null,8,["value"])]),_:1})]),_:1})):b("",!0)]),_:1},8,["open"])],64)}}});export{ve as default};
//# sourceMappingURL=Projects.a0a72c8c.js.map
