Liferay.Loader.define("dynamic-data-mapping-form-field-type@6.0.122/ObjectField/ObjectField",["module","exports","require","@frontend-taglib-clay$clayui/data-provider","@liferay/frontend-js-react-web","data-engine-js-components-web","frontend-js-web","liferay!frontend-js-react-web$react","../Select/Select.es"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n=r("@frontend-taglib-clay$clayui/data-provider"),l=r("@liferay/frontend-js-react-web"),a=r("data-engine-js-components-web"),o=r("frontend-js-web"),i=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 l in e)if(Object.prototype.hasOwnProperty.call(e,l)){var a=n?Object.getOwnPropertyDescriptor(e,l):null;a&&(a.get||a.set)?Object.defineProperty(r,l,a):r[l]=e[l]}r.default=e,t&&t.set(e,r);return r}(r("liferay!frontend-js-react-web$react")),c=function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}(r("../Select/Select.es"));function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return _getRequireWildcardCache=function _getRequireWildcardCache(){return e},e}function _extends(){return(_extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function _objectWithoutProperties(e,t){if(null==e)return{};var r,n,l=function _objectWithoutPropertiesLoose(e,t){if(null==e)return{};var r,n,l={},a=Object.keys(e);for(n=0;n<a.length;n++)r=a[n],t.indexOf(r)>=0||(l[r]=e[r]);return l}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n<a.length;n++)r=a[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(l[r]=e[r])}return l}const e={double:["double","bigdecimal"],image:["blob"],integer:["integer","long"]},normalizeDataType=t=>{var r;const n=t.toLowerCase();return null!==(r=e[n])&&void 0!==r?r:n},ObjectField=({label:e,objectFields:t,onChange:r,readOnly:n,spritemap:l,value:o={},visible:u})=>{const{formBuilder:{focusedField:{dataType:d,type:s},pages:f}}=(0,a.useFormState)(),b=(0,i.useMemo)((()=>normalizeDataType(d)),[d]),p=(0,i.useMemo)((()=>{const e=t.filter((({businessType:e,listTypeDefinitionId:t,relationshipType:r,system:n,type:l})=>!(!(t||"radio"!==s&&"select"!==s)&&b.includes(l.toLowerCase()))&&((!t||"checkbox_multiple"!==s&&"color"!==s&&"grid"!==s&&"rich_text"!==s&&"text"!==s||!b.includes(l.toLowerCase()))&&(("rich_text"===s||"text"===s)&&"Clob"===l||!r&&!n&&("Attachment"===e&&"document_library"===s||b.includes(l.toLowerCase()))))));if(e.length){const t=(0,a.getFields)(f).map((e=>{const t=(0,a.getObjectFieldName)(e);return t&&(0,a.getSelectedValue)(t.value)})).filter(Boolean);return e.map((({label:e,name:r})=>{var n;return{disabled:!!t.includes(r),label:null!==(n=e[themeDisplay.getDefaultLanguageId()])&&void 0!==n?n:r,value:r}}))}{const e=Liferay.Language.get("there-are-no-compatible-object-fields-to-map");return[{disabled:!0,label:e,value:e}]}}),[s,b,t,f]);return i.default.createElement(c.default,{label:e,name:"selectedObjectField",onChange:r,options:p,readOnly:n,showEmptyOption:!!p.length,spritemap:l,value:(0,a.getSelectedValue)(o),visible:u})},ObjectDefinitionObjectField=({label:e,objectDefinitionId:t,onChange:r,readOnly:a,spritemap:u,value:d={},visible:s})=>{var f;const{refetch:b,resource:p}=(0,n.useResource)({fetch:o.fetch,fetchPolicy:"cache-first",link:"".concat(window.location.origin,"/o/object-admin/v1.0/object-definitions/").concat(t)}),y=(0,l.usePrevious)(t);(0,i.useEffect)((()=>{t&&t!==y&&b()}),[t,y,b]);const g=(null==p||null===(f=p.objectFields)||void 0===f?void 0:f.map((({label:e,name:t})=>{var r;return{label:null!==(r=e[themeDisplay.getDefaultLanguageId()])&&void 0!==r?r:t,value:t}})))||[];return i.default.createElement(c.default,{label:e,name:"selectedObjectField",onChange:r,options:g,readOnly:a,showEmptyOption:!!g.length,spritemap:u,value:d,visible:s})};var _default=e=>{let{objectDefinitionId:t}=e,r=_objectWithoutProperties(e,["objectDefinitionId"]);const{objectFields:n}=(0,a.useFormState)();return(null==n?void 0:n.length)?i.default.createElement(ObjectField,_extends({objectFields:n},r)):t?i.default.createElement(ObjectDefinitionObjectField,_extends({objectDefinitionId:t},r)):null};t.default=_default}}));
//# sourceMappingURL=ObjectField.js.map