Liferay.Loader.define("@liferay/notification-web@1.0.27/js/components/Attachments",["module","exports","require","@frontend-taglib-clay$clayui/panel","@liferay/object-js-components-web","liferay!frontend-js-react-web$react","../util/constants","./Attachments.scss"],(function(e,t,a){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.Attachments=function Attachments({setValues:e,values:t}){var a;const[c,o]=(0,l.useState)(),[u,d]=(0,l.useState)([]),[f,s]=(0,l.useState)(),[p,b]=(0,l.useState)(""),y=(0,l.useMemo)((()=>{if(c)return(0,r.filterArrayByQuery)(c,"label",p)}),[c,p]),j=async function fetchObjectFields(e){const a=await r.API.getObjectFields(e),n=null==a?void 0:a.filter((e=>"Attachment"===e.businessType));d((e=>{const a=[],n=new Set(null==t?void 0:t.attachmentObjectFieldIds);return e.forEach((({id:e,label:t})=>{a.push({checked:n.has(e),label:t[i.defaultLanguageId],value:null==e?void 0:e.toString()})})),a})(n))};return(0,l.useEffect)((()=>{(async()=>{const e=await r.API.getAllObjectDefinitions(),a=null==e?void 0:e.find((e=>e.id===t.objectDefinitionId));o(null==e?void 0:e.filter((({system:e})=>!e))),s(a)})()}),[t.objectDefinitionId]),(0,l.useEffect)((()=>{const a=null==c?void 0:c.find((e=>e.id===t.objectDefinitionId));a||e(_objectSpread(_objectSpread({},t),{},{attachmentObjectFieldIds:[],objectDefinitionId:null})),s(a),t.objectDefinitionId&&j(t.objectDefinitionId)}),[t.objectDefinitionId]),(0,l.useEffect)((()=>{e(_objectSpread(_objectSpread({},t),{},{attachmentObjectFieldIds:u.filter((e=>e.checked)).map((e=>e.value))}))}),[u]),l.default.createElement(n.default,{collapsable:!0,defaultExpanded:!0,displayTitle:Liferay.Language.get("attachments"),displayType:"secondary",showCollapseIcon:!0},l.default.createElement(n.default.Body,null,l.default.createElement("div",{className:"lfr__notification-template-attachments"},l.default.createElement("div",{className:"lfr__notification-template-attachments-fields"},l.default.createElement(r.AutoComplete,{emptyStateMessage:Liferay.Language.get("no-data-sources-were-found"),hasEmptyItem:!0,items:null!=y?y:[],label:Liferay.Language.get("data-source"),onChangeQuery:b,onSelectEmptyStateItem:a=>{d([]),s(null),e(_objectSpread(_objectSpread({},t),{},{objectDefinitionId:Number(a.id)}))},onSelectItem:a=>{a.id?(j(a.id),s(a)):(d([]),s(null)),e(_objectSpread(_objectSpread({},t),{},{objectDefinitionId:a.id}))},placeholder:Liferay.Language.get("select-a-data-source"),query:p,value:null!==(a=null==f?void 0:f.label[i.defaultLanguageId])&&void 0!==a?a:null==f?void 0:f.name},(({label:e,name:t})=>{var a;return l.default.createElement("div",{className:"d-flex justify-content-between"},l.default.createElement("div",null,null!==(a=e[i.defaultLanguageId])&&void 0!==a?a:t))}))),l.default.createElement("div",{className:"lfr__notification-template-attachments-fields"},l.default.createElement(r.MultipleSelect,{disabled:!f,label:Liferay.Language.get("field"),options:u,placeholder:Liferay.Language.get("select-a-field"),setOptions:d})))))};var n=function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}(a("@frontend-taglib-clay$clayui/panel")),r=a("@liferay/object-js-components-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 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]}a.default=e,t&&t.set(e,a);return a}(a("liferay!frontend-js-react-web$react")),i=a("../util/constants");function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return _getRequireWildcardCache=function _getRequireWildcardCache(){return e},e}function ownKeys(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 _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}a("./Attachments.scss")}}));
//# sourceMappingURL=Attachments.js.map