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