Liferay.Loader.define("commerce-organization-web@5.0.37/js/modals/AddOrganizationsModal",["module","exports","require","@frontend-taglib-clay$clayui/button","@frontend-taglib-clay$clayui/form","@frontend-taglib-clay$clayui/icon","@frontend-taglib-clay$clayui/modal","@frontend-taglib-clay$clayui/multi-select","liferay!frontend-js-react-web$classnames","frontend-js-web","liferay!frontend-js-react-web$react","../ChartContext","../data/organizations"],(function(e,t,a){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function({closeModal:e,observer:t,parentData:a}){const[g,y]=(0,f.useState)(""),[b,m]=(0,f.useState)([]),[O,j]=(0,f.useState)([]),{chartInstanceRef:h}=(0,f.useContext)(d.default);return f.default.createElement(o.default,{center:!0,observer:t,size:"md"},f.default.createElement(o.default.Header,null,Liferay.Language.get("add-organizations")),f.default.createElement(o.default.Body,null,f.default.createElement(r.default.Group,{className:(0,c.default)(!!O.length&&"has-error")},f.default.createElement("label",{htmlFor:"addNewOrganization"},Liferay.Language.get("name")+" ",f.default.createElement(l.default,{className:"ml-1 reference-mark",symbol:"asterisk"})),f.default.createElement(r.ClayInput.Group,null,f.default.createElement(r.ClayInput.GroupItem,null,f.default.createElement(u.default,{id:"addNewOrganization",items:b,onChange:y,onItemsChange:m,placeholder:Liferay.Language.get("organization-name"),value:g}),!!O.length&&f.default.createElement(r.default.FeedbackGroup,null,O.map(((e,t)=>f.default.createElement(r.default.FeedbackItem,{key:t},f.default.createElement(r.default.FeedbackIndicator,{symbol:"info-circle"}),e)))))))),f.default.createElement(o.default.Footer,{last:f.default.createElement(n.default.Group,{spaced:!0},f.default.createElement(n.default,{displayType:"secondary",onClick:e},Liferay.Language.get("cancel")),f.default.createElement(n.default,{displayType:"primary",onClick:function(){const t=g?b.concat({label:g,value:g}):[...b],n=t.map((e=>e.label));t.length?(0,s.createOrganizations)(n,a.id).then((n=>{const r=[],l=new Set,o=[];if(n.forEach(((e,a)=>{"rejected"===e.status?(o.push(t[a]),l.add(e.reason.title)):r.push(e.value)})),m(o),j(Array.from(l)),y(""),r.length){const e=1===r.length?(0,i.sub)(Liferay.Language.get("1-organization-was-added-to-x"),a.name):(0,i.sub)(Liferay.Language.get("x-organizations-were-added-to-x"),r.length,a.name);(0,i.openToast)({message:e,type:"success"}),h.current.addNodes(r,"organization",a),h.current.updateNodeContent(p(p({},a),{},{numberOfOrganizations:a.numberOfOrganizations+r.length}))}o.length||e()})):j([Liferay.Language.get("a-name-is-required")])}},Liferay.Language.get("save")))}))};var n=b(a("@frontend-taglib-clay$clayui/button")),r=y(a("@frontend-taglib-clay$clayui/form")),l=b(a("@frontend-taglib-clay$clayui/icon")),o=b(a("@frontend-taglib-clay$clayui/modal")),u=b(a("@frontend-taglib-clay$clayui/multi-select")),c=b(a("liferay!frontend-js-react-web$classnames")),i=a("frontend-js-web"),f=y(a("liferay!frontend-js-react-web$react")),d=b(a("../ChartContext")),s=a("../data/organizations");function g(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return g=function(){return e},e}function y(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=g();if(t&&t.has(e))return t.get(e);var a={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var r in e)if(Object.prototype.hasOwnProperty.call(e,r)){var l=n?Object.getOwnPropertyDescriptor(e,r):null;l&&(l.get||l.set)?Object.defineProperty(a,r,l):a[r]=e[r]}return a.default=e,t&&t.set(e,a),a}function b(e){return e&&e.__esModule?e:{default:e}}function m(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,n)}return a}function p(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?m(Object(a),!0).forEach((function(t){O(e,t,a[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):m(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))}))}return e}function O(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}}}));
//# sourceMappingURL=AddOrganizationsModal.js.map