Liferay.Loader.define("account-admin-web@2.0.82/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 n=_interopRequireDefault(r("@frontend-taglib-clay$clayui/button")),a=_interopRequireDefault(r("@frontend-taglib-clay$clayui/form")),o=_interopRequireDefault(r("@frontend-taglib-clay$clayui/icon")),i=_interopRequireDefault(r("@frontend-taglib-clay$clayui/layout")),c=r("frontend-js-web"),l=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={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var a in e)if(Object.prototype.hasOwnProperty.call(e,a)){var o=n?Object.getOwnPropertyDescriptor(e,a):null;o&&(o.get||o.set)?Object.defineProperty(r,a,o):r[a]=e[a]}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 n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}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}const deduplicatePredicate=(e,t,r)=>t===r.findIndex((t=>t.value===e.value));var s=function InviteUsersForm({accountEntryId:e,availableAccountRoles:t,inviteAccountUsersURL:r,portletNamespace:s,redirectURL:d}){const[f,p]=(0,l.useState)([{accountRoles:[],emailAddresses:[],id:"inputGroup-0"}]),y="".concat(s,"inviteUserForm");function getInputGroup(e){const t=f.find((t=>t.id===e));if(t)return t;throw new Error("No input group found for id ".concat(e))}return l.default.createElement(a.default,{className:"lfr-form-content",id:y,onSubmit:async e=>{e.preventDefault();const t=e.currentTarget;if(!t.querySelector(".has-error")){const e=new FormData(t);e.append("".concat(s,"count"),String(f.length));const n=await Liferay.Util.fetch(r,{body:e,method:"POST"}),{success:a}=await n.json();a?function closeModal(e={}){Liferay.Util.getOpener().Liferay.fire("closeModal",e)}({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"})}}},f.map(((r,n)=>l.default.createElement(u.default,{accountRoles:r.accountRoles,availableAccountRoles:t,emailAddresses:r.emailAddresses,id:r.id,index:n,key:r.id,onAccountRoleItemsChange:e=>function setAccountRoles(e,r){getInputGroup(e).accountRoles=r.filter(deduplicatePredicate).map((e=>{let r="";return t.some((t=>t.label===e.label))||(r=(0,c.sub)(Liferay.Language.get("x-is-not-a-valid-role"),e.label)),_objectSpread(_objectSpread({},e),{},{errorMessage:r})})),p([...f])}(r.id,e),onEmailAddressItemsChange:t=>async function setEmailAddresses(t,r){const n=getInputGroup(t),a=r.filter(deduplicatePredicate).map((t=>new Promise((r=>{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})=>r(_objectSpread(_objectSpread({},t),{},{errorMessage:e}))))}))));n.emailAddresses=await Promise.all(a),p([...f])}(r.id,t),portletNamespace:s}))),l.default.createElement(i.default.SheetFooter,null,l.default.createElement(n.default,{displayType:"secondary",onClick:()=>{p([...f,{accountRoles:[],emailAddresses:[],id:"inputGroup-".concat(f.length)}])}},l.default.createElement("span",{className:"inline-item inline-item-before"},l.default.createElement(o.default,{symbol:"plus"})),Liferay.Language.get("add-entry"))))};t.default=s}}));
//# sourceMappingURL=InviteUsersForm.js.map