// @flow

/* global window, IS_PRODUCTION */

/* eslint consistent-this: ["error", "view"] */

import type {Node} from 'react';
import React, {Component} from 'react';
import {connect} from 'react-redux';
import type {GlobalStateType} from './../../app-reducer';
import type {LocaleType} from './reducer';
import {allLocales} from './const';
import type {LangKeyType} from './translation/type';

type StateType = {};
type PropsType = {|
    +locale: LocaleType,
    +stringKey: LangKeyType
|};

class Locale extends Component<PropsType, StateType> {
    state: StateType;
    props: PropsType;

    getLocalizedString(): string {
        const view = this;
        const {props} = view;
        const {locale, stringKey} = props;

        // eslint-disable-next-line id-match
        if (!IS_PRODUCTION) {
            if (!stringKey) {
                console.error('stringKey is not define', stringKey);
                return 'TEXT';
            }

            if (!allLocales['en-US'].hasOwnProperty(stringKey)) {
                console.error('has no key stringKey', stringKey);
                return stringKey;
            }
        }

        return allLocales[locale.name][stringKey];
    }

    render(): string {
        const view = this;
        const {props} = view;

        return view.getLocalizedString();
    }
}

export default connect(
    (state: GlobalStateType): {|+locale: LocaleType|} => ({
        locale: state.locale
    }),
    {
        // setUser
    }
)(Locale);

@@ -411,16 +411,47 @@
  = %7B
+%7C%0A    stateData: string%0A%7C
 %7D;%0A
+%0A
 type 
+Redux
 Prop
@@ -484,17 +484,47 @@
 caleType
-,
+%0A%7C%7D;%0A%0Atype PassedPropsType = %7B%7C
 %0A    +st
@@ -580,16 +580,38 @@
 mponent%3C
+ReduxPropsType, Passed
 PropsTyp
@@ -634,42 +634,121 @@
     
-state: StateType;%0A    props: Props
+// eslint-disable-next-line id-match%0A    props: $Exact%3C%7B...ReduxPropsType, ...PassedPropsType%7D%3E;%0A    state: State
 Type
@@ -1542,34 +1542,49 @@
 Type
-): %7B%7C+locale: Locale
+, props: PassedPropsType): ReduxProps
 Type
-%7C%7D
  =%3E 

update locale props