import Input from '../../input';
import React from 'react';
import ReactDOM from 'react-dom';
import Tab from '..';
class EditableTabPane extends React.Component {
    constructor(props) {
        super(props);
        this.onKeyDown = e => {
            const { keyCode } = e;
            if (keyCode > 36 && keyCode < 41) {
                e.stopPropagation();
            }
        };
        this.onBlur = e => {
            this.setState({
                editable: false,
                tabTitle: e.target.value,
            });
        };
        this.onDblClick = () => {
            this.setState({
                editable: true,
            });
        };
        this.state = {
            tabTitle: props.defaultTitle,
            editable: false,
        };
    }
    componentWillReceiveProps(nextProps) {
        if (nextProps.defaultTitle !== this.state.tabTitle) {
            this.setState({
                tabTitle: nextProps.defaultTitle,
            });
        }
    }
    // Stop bubble up the events of keyUp, keyDown, keyLeft, and keyRight
    render() {
        const { tabTitle, editable } = this.state;
        if (editable) {
            return (React.createElement(Input, { defaultValue: tabTitle, onKeyDown: this.onKeyDown, onBlur: this.onBlur }));
        }
        return React.createElement("span", { onDoubleClick: this.onDblClick }, tabTitle);
    }
}
const tabRender = (key, { title }) => (React.createElement("div", { key: key, className: "editable-tab-wrapper" },
    React.createElement(EditableTabPane, { defaultTitle: title })));
ReactDOM.render(React.createElement(Tab, { defaultActiveKey: "1", tabRender: tabRender },
    React.createElement(Tab.Item, { title: "Double Click To Edit Me", key: "1" }, "Editable tab"),
    React.createElement(Tab.Item, { title: "Double Click To Edit Me", key: "2" }, "Editable tab")), document.getElementById('tab-demo-13'));
