import{R as v,j as a,h as g,i as C,ek as N,ej as L,a3 as k,au as I,k as R,dk as _,l as D,b as F,o as O,a4 as U,aR as E}from"./app-BgLa5dit.js";import{u as M}from"./8Im-OACs.chunk.js";import{O as m}from"./DNClpFKN.chunk.js";import{C as P}from"./BPRDISw7.chunk.js";import{C as V,a as G}from"./8iu0vnCW.chunk.js";import{D as H}from"./C4BcftDO.chunk.js";import{a as s,C as $}from"./Bl0YdmfD.chunk.js";import{T as q}from"./lZO4aq5x.chunk.js";import{H as B}from"./wvigAl7i.chunk.js";import{C as d}from"./c3I67AiW.chunk.js";import{C as Y}from"./CQCJQXSQ.chunk.js";import"./g56uS58q.chunk.js";import"./3nM7jLnE.chunk.js";import"./CPXlV0fg.chunk.js";import"./ChrB5FYK.chunk.js";import"./DR2FaZH9.chunk.js";import"./KUnagq9Z.chunk.js";import"./DULWIWQR.chunk.js";import"./CCcwLDvu.chunk.js";import"./DDfKZ_ng.chunk.js";import"./Zwjmkasg.chunk.js";import"./DeKZULrh.chunk.js";import"./itQZri94.chunk.js";import"./C8_78Eqq.chunk.js";import"./DG_07YWO.chunk.js";function z(t){var i;const e={application:C.CRM_STUDIO,action:g.CrmStudio.ADD_CUSTOMERS_TO_ORGANISATION,args:[t.id]},n=v.useMemo(()=>[s.name(),s.id(),s.status(),s.type(),s.cft(),s.removeCustomer(t.id)],[t.id]);return a.jsx("div",{className:"mt-3",children:a.jsx(H,{heading:"Customers in organisation",disableCollapse:!0,buttonText:t.canAddCustomer?"Add customer":"",buttonAppLink:e,children:(i=t.customers)!=null&&i.length?a.jsxs(a.Fragment,{children:[a.jsx($,{data:t.customers,columns:n}),(t.hasMore||t.isFetching)&&a.jsx(N,{isFetching:t.isFetching,fetchNext:t.fetchNext,nextCursor:t.nextCursor,fetchOnScroll:!0})]}):a.jsx("p",{className:"px-3 pt-3",children:"There are currently no customers in this organisation."})})})}const J="_row_jkuru_1",K={row:J},p=L(),Q={title:()=>p.accessor("title",{id:"title",header:"",cell:t=>{const e=t.getValue();return a.jsx("div",{className:"font-label",children:e})}}),value:()=>p.accessor(t=>t,{id:"value",header:"",cell:t=>{const e=t.getValue();return e.copyable?a.jsx(B,{value:e.value,applink:null}):a.jsx("div",{children:e.value})}}),edit:()=>p.accessor(t=>t,{id:"edit",header:"",cell:t=>{const e=t.getValue();return e.canEdit&&e.appLink.args&&a.jsx(k,{actions:[{appLink:{application:e.appLink.application,action:e.appLink.action,args:[...e.appLink.args,e.value]},svg:I,button:!0}],className:"w-100 justify-content-end pe-2",actionsDropdownClassName:"btn btn-link ms-1"})}})};function W(t){var i,r,c;const e=[{title:"Organisation master ID",value:((i=t.organisation)==null?void 0:i.id)||"-",copyable:!0},{title:"Name",value:((r=t.organisation)==null?void 0:r.name)||"-",canEdit:!0,appLink:{application:C.CRM_STUDIO,action:g.CrmStudio.UPDATE_ORGANISATION_NAME,args:[t.organisation.id]}},{title:"Type",value:Y.mapOrgTypeToLabel(+((c=t.organisation)==null?void 0:c.orgType))||"-",canEdit:!0,appLink:{application:C.CRM_STUDIO,action:g.CrmStudio.UPDATE_ORGANISATION_TYPE,args:[t.organisation.id]}}],n={...d,header:"d-none",row:`${d.row} ${K.row}`,cell:`${d.cell} pt-1 pb-1`};return a.jsx(q,{data:e,columns:Object.values(Q).map(u=>u()),theme:n})}function St(t){const e=R(),n=_(),i=D(),{hasPermissions:r}=F(),[c,u]=v.useState(!1),T=O(E.currentUser()),l=O(m.getOrganisation(t.id));function h(o){return m.getCustomersFromOrganisation(t.id,o)}function f(o){return n(h(o))}const{items:y,isFetching:x,hasMore:S,nextCursor:j}=M(h,f);async function A(o){u(!0);try{await e(m.updateOrganisation(t.id,{name:l.data.name,orgType:o})),i.success("Successfully updated the organisation type")}catch{i.error("Failed to update organisation type. Please try again.")}finally{u(!1)}}const w=r(U.CrmStudioOrganisation),b=l.hasCompleted&&T.hasCompleted;return a.jsx(V,{view:G.Organisations,children:a.jsxs(P,{title:"Overview",currentTabId:"overview",id:t.id,loading:!b,children:[a.jsx(W,{organisation:l.data,onTypeChange:A,isLoadingType:c}),a.jsx(z,{id:t.id,customers:y,isFetching:x,hasMore:S,nextCursor:j,fetchNext:f,canAddCustomer:w})]})})}export{St as OrganisationOverviewView};
//# sourceMappingURL=BZV6a5BZ.chunk.js.map
