Liferay.Loader.define("portal-workflow-kaleo-designer-web@5.0.115/designer/js/definition-builder/diagram-builder/util/populateNotificationsData",["module","exports","require","liferay!frontend-js-dependencies-web$react-flow-renderer","../../util/fetchUtil"],(function(e,i,t){window;Object.defineProperty(i,"__esModule",{value:!0}),i.default=void 0;var n=t("liferay!frontend-js-dependencies-web$react-flow-renderer"),a=t("../../util/fetchUtil");var _default=(e,i,t)=>{for(let o=0;o<i.length;o++){const r=i[o];if((0,n.isNode)(r)&&r.data.notifications){r.data.notifications.recipients.map(((n,r)=>{var s,l,d,c,f,u;if(void 0!==n[0]&&(n=n[0]),"roleId"===(null===(s=n)||void 0===s||null===(l=s.assignmentType)||void 0===l?void 0:l[0]))(0,a.retrieveRoleById)(n.roleId).then((e=>e.json())).then((e=>{i[o].data.notifications.recipients[r][0].sectionsData={id:e.id,name:e.name,roleType:e.roleType},t([...i])}));else if("roleType"===(null===(d=n)||void 0===d||null===(c=d.assignmentType)||void 0===c?void 0:c[0]))Promise.all([(0,a.retrieveRoles)(),(0,a.retrieveAccountRoles)(e)]).then((([e,n])=>Promise.all([e.json(),n.json()]).then((([e,n])=>{const a=e.items.concat(n.items);i[o].data.notifications.recipients[r].roleKey.forEach((e=>{const t=a.find((i=>i.externalReferenceCode===e||i.displayName===e));i[o].data.notifications.recipients[r].roleName||(i[o].data.notifications.recipients[r].roleName=[]),i[o].data.notifications.recipients[r].roleName.push(null==t?void 0:t.name)})),t([...i])}))));else if("user"===(null===(f=n)||void 0===f||null===(u=f.assignmentType)||void 0===u?void 0:u[0])&&(n.emailAddress||n.screenName||n.userId)){const e=[];let s=Object.keys(n)[1];const l=Object.values(n)[1];"screenName"===s?s="alternateName":"userId"===s&&(s=s.toLocaleLowerCase().replace("user","")),(0,a.retrieveUsersBy)(s,l).then((e=>e.json())).then((({items:i})=>{i.forEach(((i,t)=>{e.push({emailAddress:i.emailAddress,identifier:"".concat(Date.now(),"-").concat(t),name:i.name,screenName:i.alternateName,userId:i.id})}))})).then((()=>{i[o].data.notifications.recipients[r][0].sectionsData=e,t([...i])}))}}))}}};i.default=_default}));
//# sourceMappingURL=populateNotificationsData.js.map