Liferay.Loader.define("segments-web@3.0.68/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,a,t){window;{Object.defineProperty(a,"__esModule",{value:!0}),a.default=void 0;var n=i(t("liferay!frontend-js-react-web$classnames")),r=(i(t("liferay!frontend-js-react-web$prop-types")),i(t("liferay!frontend-js-react-web$react"))),l=i(t("./LocalizedDropdown.es"));function i(e){return e&&e.__esModule?e:{default:e}}function s(e,a){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);a&&(n=n.filter((function(a){return Object.getOwnPropertyDescriptor(e,a).enumerable}))),t.push.apply(t,n)}return t}function u(e){for(var a=1;a<arguments.length;a++){var t=null!=arguments[a]?arguments[a]:{};a%2?s(Object(t),!0).forEach((function(a){o(e,a,t[a])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):s(Object(t)).forEach((function(a){Object.defineProperty(e,a,Object.getOwnPropertyDescriptor(t,a))}))}return e}function o(e,a,t){return a in e?Object.defineProperty(e,a,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[a]=t,e}class e extends r.default.Component{constructor(e){super(e),o(this,"_handleLanguageChange",(e=>{this.setState((a=>({currentLang:e,currentValue:a.values[e]||""})))})),o(this,"_onChange",((e,a)=>{this.props.onChange(e,this.state.values,a)})),o(this,"_handleInputChange",(e=>{e.persist();let a=!1;const t=e.target.value;this.setState((e=>{const n=u(u({},e.values),{},{[e.currentLang]:t});return a=!this._validateValues(n),{availableLanguages:e.availableLanguages.map((a=>{let n=a;return a.key===e.currentLang&&(n=u(u({},a),{},{hasValue:""!==t})),n})),currentValue:t,hasError:a,values:n}}),(()=>this._onChange(e,a)))}));const{availableLanguages:a,initialLanguageId:t,initialValues:n}=e;this.state={availableLanguages:Object.keys(a).map((e=>{const t=a[e];return{hasValue:!!n[e],key:e,value:t}})),currentLang:t,currentValue:n[t]||"",values:n}}_validateValues(e){const{defaultLang:a}=this.props;return!!(e[a]&&e[a].replace(/\s/g,""))}render(){const{defaultLang:e,initialLanguageId:a,initialOpen:t,placeholder:i,readOnly:s}=this.props,{availableLanguages:u,currentValue:o,hasError:c}=this.state,d=(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:a,initialOpen:t,onLanguageChange:this._handleLanguageChange}),r.default.createElement("div",{className:d},r.default.createElement("input",{className:"field form-control form-control-inline language-value rounded","data-testid":"localized-main-input",onChange:this._handleInputChange,placeholder:i,readOnly:s,type:"text",value:o})))}}a.default=e,o(e,"defaultProps",{initialOpen:!1,initialValues:{},onChange:()=>{},placeholder:"",readOnly:!1})}}));
//# sourceMappingURL=LocalizedInput.es.js.map