import{Hy as e,i_ as t,ii as n,lh as r,n_ as i,ph as a,r_ as o}from"./index-DDwwBb9e.js";var s=e();function c({organizationId:e,kind:n,entityId:c,value:l,costCenters:u,onAssigned:d,width:f}){let p=r.costCenters.assignUser.useMutation(),m=r.costCenters.assignTeam.useMutation(),h=r.costCenters.assignProject.useMutation(),g=p.isPending||m.isPending||h.isPending,_=async t=>{try{n===`user`?await p.mutateAsync({organizationId:e,userId:c,costCenterId:t}):n===`team`?await m.mutateAsync({organizationId:e,teamId:c,costCenterId:t}):await h.mutateAsync({organizationId:e,projectId:c,costCenterId:t}),a.create({title:`Cost center updated`,type:`success`}),await d()}catch(e){a.create({title:`Assignment failed`,description:e instanceof Error?e.message:String(e),type:`error`})}};return(0,s.jsxs)(t,{size:`sm`,...f?{width:f}:{minW:`160px`,maxW:`220px`},disabled:g,children:[(0,s.jsxs)(i,{value:l??``,onChange:e=>void _(e.target.value||null),children:[(0,s.jsx)(`option`,{value:``,children:`Unassigned`}),u.map(e=>(0,s.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,s.jsx)(o,{})]})}function l(e){let{enabled:t}=n(`release_ui_ai_governance_enabled`,{organizationId:e,enabled:!!e}),i=!!e&&t,a=r.costCenters.list.useQuery({organizationId:e},{enabled:i,refetchOnWindowFocus:!1}),o=r.costCenters.assignments.useQuery({organizationId:e},{enabled:i,refetchOnWindowFocus:!1}),s=r.useUtils(),c=a.data??[],l=o.data,u=new Map(l?.users.map(e=>[e.id,e.costCenterId])??[]),d=new Map(l?.teams.map(e=>[e.id,e.costCenterId])??[]),f=new Map(l?.projects.map(e=>[e.id,e.costCenterId])??[]);return{show:t&&c.length>0,costCenters:c,byUser:u,byTeam:d,byProject:f,refetch:()=>s.costCenters.assignments.invalidate({organizationId:e})}}export{c as n,l as t};
//# sourceMappingURL=useCostCenterColumn-DrSQN5gK.js.map