Liferay.Loader.define("@liferay/notification-web@1.0.35/js/components/ContentContainer/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,n){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.Attachments=function Attachments({setValues:e,values:t}){var n;const[o,c]=(0,l.useState)(),[u,d]=(0,l.useState)([]),[f,s]=(0,l.useState)(),[p,b]=(0,l.useState)(""),y=(0,l.useMemo)((()=>{if(o)return(0,r.filterArrayByQuery)({array:o,query:p,str:"label"})}),[o,p]),j=async function fetchObjectFields(e){const n=await r.API.getObjectFieldsByExternalReferenceCode(e),a=null==n?void 0:n.filter((e=>"Attachment"===e.businessType));d((e=>{const n=[],a=new Set(null==t?void 0:t.attachmentObjectFieldIds);return e.forEach((({id:e,label:t})=>{n.push({checked:a.has(e),label:t[i.defaultLanguageId],value:null==e?void 0:e.toString()})})),n})(a))};return(0,l.useEffect)((()=>{(async()=>{const e=await r.API.getAllObjectDefinitions(),n=null==e?void 0:e.find((e=>e.id===t.objectDefinitionId));c(null==e?void 0:e.filter((({system:e})=>!e))),s(n)})()}),[t.objectDefinitionId]),(0,l.useEffect)((()=>{const n=null==o?void 0:o.find((e=>e.id===t.objectDefinitionId));n||e(_objectSpread(_objectSpread({},t),{},{attachmentObjectFieldIds:[],objectDefinitionId:null})),s(n),t.objectDefinitionId&&j(t.objectDefinitionExternalReferenceCode)}),[t.objectDefinitionId]),(0,l.useEffect)((()=>{e(_objectSpread(_objectSpread({},t),{},{attachmentObjectFieldIds:u.filter((e=>e.checked)).map((e=>e.value))}))}),[u]),l.default.createElement(a.default,{collapsable:!0,defaultExpanded:!0,displayTitle:Liferay.Language.get("attachments"),displayType:"secondary",showCollapseIcon:!0},l.default.createElement(a.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:n=>{d([]),s(null),e(_objectSpread(_objectSpread({},t),{},{objectDefinitionId:Number(n.id)}))},onSelectItem:n=>{n.id?(j(n.externalReferenceCode),s(n)):(d([]),s(null)),e(_objectSpread(_objectSpread({},t),{},{objectDefinitionId:n.id}))},placeholder:Liferay.Language.get("select-a-data-source"),query:p,value:null!==(n=null==f?void 0:f.label[i.defaultLanguageId])&&void 0!==n?n:null==f?void 0:f.name},(({label:e,name:t})=>{var n;return l.default.createElement("div",{className:"d-flex justify-content-between"},l.default.createElement("div",null,null!==(n=e[i.defaultLanguageId])&&void 0!==n?n: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 a=function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}(n("@frontend-taglib-clay$clayui/panel")),r=n("@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 n={},a=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var r in e)if(Object.prototype.hasOwnProperty.call(e,r)){var l=a?Object.getOwnPropertyDescriptor(e,r):null;l&&(l.get||l.set)?Object.defineProperty(n,r,l):n[r]=e[r]}n.default=e,t&&t.set(e,n);return n}(n("liferay!frontend-js-react-web$react")),i=n("../../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 n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(n),!0).forEach((function(t){_defineProperty(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ownKeys(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function _defineProperty(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}n("./Attachments.scss")}}));
//# sourceMappingURL=Attachments.js.map