Liferay.Loader.define("segments-web@3.0.77/js/components/title_editor/LocalizedInput.es",["module","exports","require","liferay!frontend-js-react-web$classnames","liferay!frontend-js-react-web$prop-types","liferay!frontend-js-react-web$react","./LocalizedDropdown.es"],(function(e,t,a){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n=_interopRequireDefault(a("liferay!frontend-js-react-web$classnames")),r=(_interopRequireDefault(a("liferay!frontend-js-react-web$prop-types")),_interopRequireDefault(a("liferay!frontend-js-react-web$react"))),l=_interopRequireDefault(a("./LocalizedDropdown.es"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default: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}class LocalizedInput extends r.default.Component{constructor(e){super(e),_defineProperty(this,"_handleLanguageChange",(e=>{this.setState((t=>({currentLang:e,currentValue:t.values[e]||""})))})),_defineProperty(this,"_onChange",((e,t)=>{this.props.onChange(e,this.state.values,t)})),_defineProperty(this,"_handleInputChange",(e=>{e.persist();let t=!1;const a=e.target.value;this.setState((e=>{const n=_objectSpread(_objectSpread({},e.values),{},{[e.currentLang]:a});return t=!this._validateValues(n),{availableLanguages:e.availableLanguages.map((t=>{let n=t;return t.key===e.currentLang&&(n=_objectSpread(_objectSpread({},t),{},{hasValue:""!==a})),n})),currentValue:a,hasError:t,values:n}}),(()=>this._onChange(e,t)))}));const{availableLanguages:t,initialLanguageId:a,initialValues:n}=e;this.state={availableLanguages:Object.keys(t).map((e=>{const a=t[e];return{hasValue:!!n[e],key:e,value:a}})),currentLang:a,currentValue:n[a]||"",values:n}}_validateValues(e){const{defaultLang:t}=this.props;return!!(e[t]&&e[t].replace(/\s/g,""))}render(){const{defaultLang:e,initialLanguageId:t,initialOpen:a,placeholder:i,readOnly:o}=this.props,{availableLanguages:u,currentValue:s,hasError:c}=this.state,p=(0,n.default)("input-group-item ml-2",{"has-error":c});return r.default.createElement("div",{className:"input-group input-localized input-localized-input"},r.default.createElement(l.default,{availableLanguages:u,defaultLang:e,initialLang:t,initialOpen:a,onLanguageChange:this._handleLanguageChange}),r.default.createElement("div",{className:p},r.default.createElement("input",{"aria-label":i,className:"field form-control form-control-inline language-value rounded","data-testid":"localized-main-input",onChange:this._handleInputChange,placeholder:i,readOnly:o,type:"text",value:s})))}}t.default=LocalizedInput,_defineProperty(LocalizedInput,"defaultProps",{initialOpen:!1,initialValues:{},onChange:()=>{},placeholder:"",readOnly:!1})}}));
//# sourceMappingURL=LocalizedInput.es.js.map