import{d as h,eB as x,eA as z,r as D,G 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,bq as F,bH as B,cw as M}from"./outputWidgets.ed48fa42.js";import{e as $,u as S,K as T,F as U}from"./icons.92b5bc38.js";import{a as V}from"./asyncComputed.bb2b1403.js";import"./router.1b12d634.js";import"./index.5e38be4e.js";import{P as g}from"./project.74c1366e.js";import{O as G}from"./organization.96c70a51.js";import{C as L}from"./CrudView.2b6e0547.js";import{a as q}from"./ant-design.2e0784cc.js";import{A as H}from"./FormItem.c1c36356.js";import{M as J}from"./Modal.f08a6e4a.js";import"./index.60984836.js";import"./index.cf4c23b9.js";import"./record.2ea2ab4d.js";import"./pubsub.90864e85.js";import"./Title.89d211e5.js";import"./Text.b5b9d884.js";import"./Form.471d6bcc.js";import"./hasIn.a220eabf.js";import"./DocsButton.vue_vue_type_script_setup_true_lang.8c8873a1.js";import"./url.c9588410.js";import"./index.2264b72c.js";import"./index.7ed642ed.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]="d3d8cd93-f2af-46e2-a0c3-d4e08b2b742c",l._sentryDebugIdIdentifier="sentry-dbid-d3d8cd93-f2af-46e2-a0c3-d4e08b2b742c")}catch{}})();const je=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}))),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 q("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){M.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=D({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 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(a=>{var o,i;return{key:a.id,cells:[{type:"link",text:a.name,to:`/projects/${encodeURIComponent(a.id)}`},{type:"actions",actions:[{icon:$,label:"Go to project",onClick:d},{icon:S,label:"Rename project",onClick:()=>N(a)},...(i=(o=r.value)==null?void 0:o.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 a=A("ant-form");return u(),E(F,null,[s(r)?(u(),w(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"])):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{je as default};
//# sourceMappingURL=Projects.52c581b1.js.map
