Liferay.Loader.define("account-admin-web@2.0.71/account_entries_admin/js/InviteUsersForm",["module","exports","require","@frontend-taglib-clay$clayui/button","@frontend-taglib-clay$clayui/form","@frontend-taglib-clay$clayui/icon","@frontend-taglib-clay$clayui/layout","frontend-js-web","liferay!frontend-js-react-web$react","./InviteUsersFormGroup"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var a=_interopRequireDefault(r("@frontend-taglib-clay$clayui/button")),n=_interopRequireDefault(r("@frontend-taglib-clay$clayui/form")),o=_interopRequireDefault(r("@frontend-taglib-clay$clayui/icon")),i=_interopRequireDefault(r("@frontend-taglib-clay$clayui/layout")),l=r("frontend-js-web"),c=function _interopRequireWildcard(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=_getRequireWildcardCache();if(t&&t.has(e))return t.get(e);var r={},a=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var n in e)if(Object.prototype.hasOwnProperty.call(e,n)){var o=a?Object.getOwnPropertyDescriptor(e,n):null;o&&(o.get||o.set)?Object.defineProperty(r,n,o):r[n]=e[n]}r.default=e,t&&t.set(e,r);return r}(r("liferay!frontend-js-react-web$react")),u=_interopRequireDefault(r("./InviteUsersFormGroup"));function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return _getRequireWildcardCache=function _getRequireWildcardCache(){return e},e}function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function ownKeys(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,a)}return r}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(r),!0).forEach((function(t){_defineProperty(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ownKeys(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function _defineProperty(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var s=function InviteUsersForm({accountEntryId:e,availableAccountRoles:t,inviteAccountUsersURL:r,portletNamespace:s,redirectURL:d}){const[f,y]=(0,c.useState)([{accountRoles:[],emailAddresses:[],id:"inputGroup-0"}]),p="".concat(s,"inviteUserForm");function closeModal(e={}){Liferay.Util.getOpener().Liferay.fire("closeModal",e)}return c.default.createElement(n.default,{className:"lfr-form-content",id:p},f.map(((r,a)=>c.default.createElement(u.default,{accountRoles:r.accountRoles,availableAccountRoles:t,emailAddresses:r.emailAddresses,id:r.id,index:a,key:r.id,onAccountRoleItemsChange:e=>function setAccountRoles(e,r){const a=f.find((t=>t.id===e));a&&(a.accountRoles=r.map((e=>{const r=_objectSpread({},e);return t.some((t=>t.label===e.label))||(r.errorMessage=(0,l.sub)(Liferay.Language.get("x-is-not-a-valid-role"),e.label)),r})),y([...f]))}(r.id,e),onEmailAddressItemsChange:t=>async function setEmailAddresses(t,r){const a=f.find((e=>e.id===t));if(a){const t=r.map((t=>new Promise((r=>{const a=_objectSpread({},t);Liferay.Util.fetch("/o/com-liferay-account-admin-web/validate-email-address/",{body:Liferay.Util.objectToFormData({accountEntryId:e,emailAddress:t.label}),method:"POST"}).then((e=>e.json())).then((({errorMessage:e})=>{e&&(a.errorMessage=e),r(a)}))}))));a.emailAddresses=await Promise.all(t),y([...f])}}(r.id,t),portletNamespace:s}))),c.default.createElement(i.default.SheetFooter,null,c.default.createElement(a.default,{displayType:"secondary",onClick:()=>{y([...f,{accountRoles:[],emailAddresses:[],id:"inputGroup-".concat(f.length)}])}},c.default.createElement("span",{className:"inline-item inline-item-before"},c.default.createElement(o.default,{symbol:"plus"})),Liferay.Language.get("add-entry"))),c.default.createElement(i.default.SheetFooter,{className:"dialog-footer"},c.default.createElement(a.default,{displayType:"primary",onClick:async e=>{e.preventDefault();const t=document.querySelector("#".concat(p));if(!(null==t?void 0:t.querySelector(".has-error"))&&t){const e=new FormData(t);e.append("".concat(s,"count"),String(f.length));const a=await Liferay.Util.fetch(r,{body:e,method:"POST"}),{success:n}=await a.json();n?closeModal({id:"".concat(s,"inviteUsersDialog"),redirect:d}):Liferay.Util.openToast({message:Liferay.Language.get("your-request-failed-to-complete"),title:Liferay.Language.get("error"),type:"danger"})}}},Liferay.Language.get("invite")),c.default.createElement(a.default,{displayType:"secondary",onClick:closeModal},Liferay.Language.get("cancel"))))};t.default=s}}));
//# sourceMappingURL=InviteUsersForm.js.map