import './demo12.css';
import Button from '../../button';
import Field from '..';
import React from 'react';
import ReactDOM from 'react-dom';
class Custom extends React.Component {
    constructor(props) {
        super(props);
        this.onAdd = () => {
            const value = this.state.value.concat([]);
            value.push('new');
            this.setState({
                value,
            });
            this.props.onChange(value);
        };
        this.state = {
            value: typeof props.value === 'undefined' ? [] : props.value,
        };
    }
    // update value
    componentWillReceiveProps(nextProps) {
        if ('value' in nextProps) {
            this.setState({
                value: typeof nextProps.value === 'undefined' ? [] : nextProps.value,
            });
        }
    }
    render() {
        return (React.createElement("div", { className: "custom" },
            this.state.value.map((v, i) => {
                return React.createElement(Button, { key: i }, v);
            }),
            React.createElement(Button, { type: "primary", onClick: this.onAdd.bind(this) },
                "Add \uFF0B",
                ' ')));
    }
}
/* eslint-disable react/no-multi-comp */
class App extends React.Component {
    constructor(props) {
        super(props);
        this.field = new Field(this, {
            // @ts-ignore
            deepReset: true,
        });
    }
    onGetValue() {
        console.log(this.field.getValue('custom'));
    }
    render() {
        const { init, setValue, reset } = this.field;
        return (React.createElement("div", { className: "demo" },
            React.createElement(Custom, Object.assign({}, init('custom', { initValue: ['test'] }))),
            React.createElement("br", null),
            React.createElement("br", null),
            React.createElement(Button, { type: "primary", onClick: this.onGetValue.bind(this) }, "getValue"),
            React.createElement(Button, { type: "primary", onClick: () => setValue('custom', ['test', 'setValue']) }, "setValue"),
            React.createElement(Button, { onClick: () => reset() }, "reset")));
    }
}
ReactDOM.render(React.createElement(App, null), document.getElementById('field-demo-12'));
