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