Liferay.Loader.define("journal-article-dynamic-data-mapping-form-field-type@2.0.24/JournalArticleSelector",["module","exports","require","@frontend-taglib-clay$clayui/button","@frontend-taglib-clay$clayui/form","dynamic-data-mapping-form-field-type/FieldBase/ReactFieldBase.es","frontend-js-web","liferay!frontend-js-react-web$react"],(function(e,t,a){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var r=function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}(a("@frontend-taglib-clay$clayui/button")),n=_interopRequireWildcard(a("@frontend-taglib-clay$clayui/form")),l=a("dynamic-data-mapping-form-field-type/FieldBase/ReactFieldBase.es"),i=a("frontend-js-web"),u=_interopRequireWildcard(a("liferay!frontend-js-react-web$react"));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 _extends(){return(_extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var r in a)Object.prototype.hasOwnProperty.call(a,r)&&(e[r]=a[r])}return e}).apply(this,arguments)}function _objectWithoutProperties(e,t){if(null==e)return{};var a,r,n=function _objectWithoutPropertiesLoose(e,t){if(null==e)return{};var a,r,n={},l=Object.keys(e);for(r=0;r<l.length;r++)a=l[r],t.indexOf(a)>=0||(n[a]=e[a]);return n}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(r=0;r<l.length;r++)a=l[r],t.indexOf(a)>=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(n[a]=e[a])}return n}function parseInputValue(e){return e?"object"==typeof e?e:JSON.parse(e):{}}const JournalArticleSelector=({disabled:e,editingLanguageId:t,inputValue:a,itemSelectorURL:l,message:o,name:d,onChange:c,portletNamespace:p})=>{const[f,s]=(0,u.useState)((()=>parseInputValue(a)));(0,u.useEffect)((()=>{s(parseInputValue(a))}),[a]);const handleFieldChanged=e=>{e&&e.value&&(s(JSON.parse(e.value)),c(e.value))},handleItemSelectorTriggerClick=e=>{e.preventDefault(),(0,i.openSelectionModal)({onSelect:handleFieldChanged,selectEventName:"".concat(p,"selectJournalArticle"),title:Liferay.Language.get("journal-article"),url:l})};return u.default.createElement(n.default.Group,{style:{marginBottom:"0.5rem"}},u.default.createElement(n.ClayInput.Group,null,u.default.createElement(n.ClayInput.GroupItem,{className:"d-none d-sm-block",prepend:!0},u.default.createElement("input",{name:d,type:"hidden",value:JSON.stringify(f)}),u.default.createElement(n.ClayInput,{className:"bg-light",dir:Liferay.Language.direction[t],disabled:e,lang:t,onClick:handleItemSelectorTriggerClick,readOnly:!0,type:"text",value:f.title||""})),u.default.createElement(n.ClayInput.GroupItem,{append:!0,shrink:!0},u.default.createElement(r.default,{disabled:e,displayType:"secondary",onClick:handleItemSelectorTriggerClick,type:"button"},Liferay.Language.get("select"))),f.classPK&&u.default.createElement(n.ClayInput.GroupItem,{shrink:!0},u.default.createElement(r.default,{disabled:e,displayType:"secondary",onClick:()=>{s({}),c("")},type:"button"},Liferay.Language.get("clear")))),o&&u.default.createElement("div",{className:"form-feedback-item"},o))},Main=e=>{let{editingLanguageId:t,itemSelectorURL:a,message:r,name:n,onChange:i,portletNamespace:o,predefinedValue:d,readOnly:c,value:p}=e,f=_objectWithoutProperties(e,["editingLanguageId","itemSelectorURL","message","name","onChange","portletNamespace","predefinedValue","readOnly","value"]);return u.default.createElement(l.FieldBase,_extends({},f,{name:n,readOnly:c}),u.default.createElement(JournalArticleSelector,{disabled:c,editingLanguageId:t,inputValue:p&&""!==p?p:d,itemSelectorURL:a,message:r,name:n,onChange:e=>i({},e),portletNamespace:o}))};Main.displayName="JournalArticleSelector";var o=Main;t.default=o}}));
//# sourceMappingURL=JournalArticleSelector.js.map