'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});

var _extends2 = require('babel-runtime/helpers/extends');

var _extends3 = _interopRequireDefault(_extends2);

exports.useLocaleReceiver = useLocaleReceiver;

var _react = require('react');

var React = _interopRequireWildcard(_react);

var _en_US = require('../../locale/en_US');

var _en_US2 = _interopRequireDefault(_en_US);

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var LocaleContext = React.createContext(undefined);
function useLocaleReceiver(componentName, defaultLocale) {
    var antLocale = React.useContext(LocaleContext);
    var componentLocale = React.useMemo(function () {
        var locale = defaultLocale || _en_US2['default'][componentName || 'global'];
        var localeFromContext = componentName && antLocale ? antLocale[componentName] : {};
        return (0, _extends3['default'])((0, _extends3['default'])({}, typeof locale === 'function' ? locale() : locale), localeFromContext || {});
    }, [componentName, defaultLocale, antLocale]);
    return [componentLocale];
}