import Form from '..';
import Input from '../../input';
import React from 'react';
import ReactDOM from 'react-dom';
const FormItem = Form.Item;
const formItemLayout = {
    labelCol: { fixedSpan: 3 },
    wrapperCol: { span: 20 },
};
class Demo extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            code: '',
            second: 60,
        };
        this.handleSubmit = (values, errors) => {
            if (errors) {
                return;
            }
            console.log('Get form value:', values);
        };
        this.sendCode = (values, errors) => {
            if (errors) {
                return;
            }
            this.setState({
                code: Math.floor(Math.random() * (999999 - 99999 + 1) + 99999),
            });
            setInterval(() => {
                let { second } = this.state;
                this.setState({
                    second: --second,
                });
            }, 1000);
        };
    }
    render() {
        const { code } = this.state;
        return (React.createElement(Form, Object.assign({ style: { width: 400 } }, formItemLayout, { labelTextAlign: "left", size: "large", labelAlign: "inset" }),
            React.createElement(FormItem, { label: "name", required: true, asterisk: false },
                React.createElement(Input, { name: "username", trim: true, defaultValue: "frank" })),
            React.createElement(FormItem, { label: "phone", format: "tel", required: true, asterisk: false },
                React.createElement(Input, { name: "phone", trim: true, innerAfter: React.createElement(Form.Submit, { text: true, type: "primary", disabled: !!code, validate: ['phone'], onClick: this.sendCode, style: { marginRight: 10 } }, code ? `retry after ${this.state.second}s` : 'send code') })),
            this.state.code ? (React.createElement(FormItem, { label: "code", required: true, asterisk: false },
                React.createElement(Input, { name: "code", trim: true, defaultValue: this.state.code }))) : null,
            React.createElement(FormItem, { label: " " },
                React.createElement(Form.Submit, { style: { width: '100%' }, type: "primary", validate: true, onClick: this.handleSubmit }, "Submit"))));
    }
}
ReactDOM.render(React.createElement(Demo, null), document.getElementById('form-demo-4'));
