function onNextFrame(cb) {
    if (window.requestAnimationFrame) {
        return window.requestAnimationFrame(cb);
    }
    return window.setTimeout(cb, 1);
}
function clearNextFrameAction(nextFrameId) {
    if (window.cancelAnimationFrame) {
        window.cancelAnimationFrame(nextFrameId);
    } else {
        window.clearTimeout(nextFrameId);
    }
}
function omit(obj, paths){
    var newObj = {};
    for(var i in obj){
        newObj[i] = obj[i];
    }
    for(var i = 0; i < paths.length; i++){
        delete newObj[paths[i]];
    }

    return newObj;
        
}

class TextArea extends React.Component {
    constructor(p, c) {
        super(p, c);
        this.state = {
            textareaStyles: {}
        };
    }
    resizeTextarea() {
        var autosize = this.props.autosize;

        if (!autosize || !this.textAreaRef) {
            return;
        }
        var minRows = autosize ? autosize.minRows : null;
        var maxRows = autosize ? autosize.maxRows : null;
        var textareaStyles = calculateNodeHeight(this.textAreaRef, false, minRows, maxRows);
        this.setState({ textareaStyles: textareaStyles });
    }

    handleTextareaChange(e) {
        if (!("value" in this.props)) {
            this.resizeTextarea();
        }
        var onChange = this.props.onChange;

        if (onChange) {
            onChange(e);
        }
    }
    handleKeyDown(e) {
        var this$props = this.props,
            onPressEnter = this$props.onPressEnter,
            onKeyDown = this$props.onKeyDown;

        if (e.keyCode === 13 && onPressEnter) {
            onPressEnter(e);
        }

        if (onKeyDown) {
            onKeyDown(e);
        }
    }
    saveTextAreaRef(textArea) {
        this.textAreaRef = textArea;
    }
    componentDidMount() {
        this.resizeTextarea();
    }
    componentWillReceiveProps(nextProps) {
        // Re-render with the new content then recalculate the height as required.
        if (this.props.value !== nextProps.value) {
            if (this.nextFrameActionId) {
                clearNextFrameAction(this.nextFrameActionId);
            }
            this.nextFrameActionId = onNextFrame(this.resizeTextarea);
        }
    }
    focus() {
        this.textAreaRef.focus();
    }
    blur() {
        this.textAreaRef.blur();
    }
    getTextAreaClassName() {
        return "";
    }
    render() {
        var props = this.props;
        var otherProps = omit(props, ["prefixCls", "onPressEnter", "autosize"]);
        var style = Object.assign({}, props.style, this.state.textareaStyles);
        // Fix https://github.com/ant-design/ant-design/issues/6776
        // Make sure it could be reset when using form.getFieldDecorator
        if ("value" in otherProps) {
            otherProps.value = otherProps.value || "";
        }
        var lastProps = Object.assign({}, otherProps, {
            className: this.getTextAreaClassName(),
            style: style,
            onKeyDown: this.handleKeyDown,
            onChange: this.handleTextareaChange,
            ref: this.saveTextAreaRef
        });
        console.log(lastProps);
        return React.createElement("textarea", lastProps);
    }
}
