"use strict";

var __extends = undefined && undefined.__extends || function () {
    var extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function (d, b) {
        d.__proto__ = b;
    } || function (d, b) {
        for (var p in b) {
            if (b.hasOwnProperty(p)) d[p] = b[p];
        }
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() {
            this.constructor = d;
        }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
}();
Object.defineProperty(exports, "__esModule", { value: true });
var React = require("react");
var _ = require("lodash");
var react_display_name_1 = require("react-display-name");
/* tslint:disable */
/**
 * Decorator that converts immutable props to plain JS.
 * Optionally, filter which props get converted.
 */
function toJS(propsMap) {
    function decorate(component) {
        var ToJS = /** @class */function (_super) {
            __extends(ToJS, _super);
            function ToJS() {
                return _super !== null && _super.apply(this, arguments) || this;
            }
            ToJS.prototype.toJS = function () {
                return _.reduce(this.props, function (result, value, key) {
                    if (propsMap) {
                        if (propsMap[key]) {
                            result[propsMap[key]] = typeof value.toJS === 'function' ? value.toJS() : value;
                        } else {
                            result[key] = value;
                        }
                    } else {
                        result[key] = value && typeof value.toJS === 'function' ? value.toJS() : value;
                    }
                    return result;
                }, {});
            };
            ToJS.prototype.render = function () {
                return React.createElement(component, this.toJS());
            };
            ToJS.displayName = "ToJS(" + react_display_name_1.default(component) + ")";
            ToJS.WrappedComponent = component;
            return ToJS;
        }(React.Component);
        return ToJS;
    }
    // Support `true`.
    if (propsMap === true) {
        propsMap = null;
    }
    // Support an array of propNames.
    if (_.isArray(propsMap)) {
        propsMap = _.keyBy(propsMap, _.identity);
    }
    // Support using @toJS or @toJS(propsMap)
    if (_.isPlainObject(propsMap) || !propsMap) {
        return decorate;
    } else {
        return decorate.apply(null, arguments);
    }
}
exports.default = toJS;
//# sourceMappingURL=toJS.js.map