Liferay.Loader.define("segments-web@3.0.77/js/components/title_editor/LocalizedDropdown.es",["module","exports","require","@frontend-taglib-clay$clayui/icon","liferay!frontend-js-react-web$prop-types","liferay!frontend-js-react-web$react","../../utils/key-constants.es"],(function(e,a,t){window;{Object.defineProperty(a,"__esModule",{value:!0}),a.default=void 0;var n=_interopRequireDefault(t("@frontend-taglib-clay$clayui/icon")),l=(_interopRequireDefault(t("liferay!frontend-js-react-web$prop-types")),_interopRequireDefault(t("liferay!frontend-js-react-web$react"))),r=t("../../utils/key-constants.es");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _defineProperty(e,a,t){return a in e?Object.defineProperty(e,a,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[a]=t,e}class LocalizedDropdown extends l.default.Component{constructor(e){super(e),_defineProperty(this,"_handleButtonClick",(()=>{this.setState((e=>({open:!e.open})))})),_defineProperty(this,"_handleButtonBlur",(()=>{this.state.open&&(this.timer=setTimeout((()=>{this.setState((()=>({open:!1})))}),200))})),_defineProperty(this,"_changeLanguage",(e=>{this.setState({currentLangKey:keyLangToLanguageTag(e),currentLangTag:keyLangToLanguageTag(e,!1),open:!1},(()=>this.props.onLanguageChange(e)))})),_defineProperty(this,"_handleItemFocus",(()=>{clearTimeout(this.timer)})),_defineProperty(this,"_handleLanguageClick",(e=>()=>this._changeLanguage(e))),_defineProperty(this,"_handleLanguageKeyboard",(e=>a=>{a.keyCode===r.ENTER&&this._changeLanguage(e)}));const{initialLang:a,initialOpen:t}=e;this.state={currentLangKey:keyLangToLanguageTag(a),currentLangTag:keyLangToLanguageTag(a,!1),open:t}}render(){const{currentLangKey:e,currentLangTag:a,open:t}=this.state,{availableLanguages:r,defaultLang:o}=this.props;return l.default.createElement("div",{className:"dropdown postion-relative lfr-icon-menu ".concat(t?"open":"")},l.default.createElement("button",{"aria-expanded":"false","aria-haspopup":"true",className:"btn btn-monospaced btn-secondary dropdown-toggle","data-testid":"localized-dropdown-button",onBlur:this._handleButtonBlur,onClick:this._handleButtonClick,role:"button",title:"",type:"button"},l.default.createElement("span",{className:"inline-item"},l.default.createElement(n.default,{key:e,symbol:e})),l.default.createElement("span",{className:"btn-section"},a)),t&&l.default.createElement("ul",{className:"d-block dropdown-menu",role:"menu"},r.map((e=>{const{hasValue:a,key:t}=e;return l.default.createElement("li",{key:t,onBlur:this._handleButtonBlur,onClick:this._handleLanguageClick(t),onFocus:this._handleItemFocus,onKeyDown:this._handleLanguageKeyboard(t),role:"presentation"},l.default.createElement("span",{className:"dropdown-item lfr-icon-item palette-item taglib-icon",role:"menuitem",tabIndex:"0",target:"_self"},l.default.createElement("span",{className:"inline-item inline-item-before"},l.default.createElement(n.default,{symbol:keyLangToLanguageTag(t)})),l.default.createElement("span",{className:"taglib-text-icon"},keyLangToLanguageTag(t,!1),o===t&&l.default.createElement("span",{className:"label label-info ml-1"},Liferay.Language.get("default")),o!==t&&(a?l.default.createElement("span",{className:"label label-success ml-1"},Liferay.Language.get("translated")):l.default.createElement("span",{className:"label label-warning ml-1"},Liferay.Language.get("not-translated"))))))}))))}}function keyLangToLanguageTag(e="",a=!0){let t=e.replace(/_/g,"-");return a&&(t=t.toLowerCase()),t}_defineProperty(LocalizedDropdown,"defaultProps",{availableLanguages:[]});var o=LocalizedDropdown;a.default=o}}));
//# sourceMappingURL=LocalizedDropdown.es.js.map