import{d as D,eB as R,eA as h,r as x,H as O,a as A,b as p,ev as E,u as s,c as j,ex as w,f as d,w as f,a$ as $,bO as B,cz as F}from"./outputWidgets.af28e799.js";import{a as M}from"./asyncComputed.b5c1c387.js";import{a as S}from"./ant-design.d5765e08.js";import"./router.1c71e909.js";import"./index.da0ed47e.js";import{P as g}from"./project.027e0bfb.js";import{O as T}from"./organization.6a3ecef1.js";import{C as U}from"./CrudView.73997f30.js";import{e as V,q as L,I as q,D as G}from"./icons.f637ef04.js";import{A as H}from"./FormItem.3cdd6f35.js";import{M as J}from"./Modal.1a697377.js";import"./index.d378dbbb.js";import"./index.cf4c23b9.js";import"./record.e8631664.js";import"./pubsub.77765f07.js";import"./Paragraph.3b796a14.js";import"./Base.9fc088e8.js";import"./Typography.9914ebec.js";import"./Form.a90bb6e2.js";import"./hasIn.b3665b9b.js";import"./DocsButton.vue_vue_type_script_setup_true_lang.7282d72e.js";import"./url.5810758c.js";import"./index.4fe7f349.js";import"./Title.f1c7fcfe.js";import"./Text.abf96dfc.js";import"./index.7dc34d3f.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]="34fe865b-bb31-4ab9-8e4c-fe633e2aa2b7",l._sentryDebugIdIdentifier="sentry-dbid-34fe865b-bb31-4ab9-8e4c-fe633e2aa2b7")}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}))),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 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();u({key:o.id})}},n=x({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: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:u},{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 p(),E($,null,[s(r)?(p(),j(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"])):w("",!0),d(s(J),{open:n.value.state==="renaming",title:"Rename organization",onCancel:e[1]||(e[1]=o=>b(!1)),onOk:e[2]||(e[2]=o=>b(!0))},{default:f(()=>[n.value.state==="renaming"?(p(),j(a,{key:0,layout:"vertical"},{default:f(()=>[d(s(H),{label:"New name"},{default:f(()=>[d(s(B),{value:n.value.newName,"onUpdate:value":e[0]||(e[0]=o=>n.value.newName=o)},null,8,["value"])]),_:1})]),_:1})):w("",!0)]),_:1},8,["open"])],64)}}});export{ve as default};
//# sourceMappingURL=Projects.05583f3a.js.map
