import React from "react";
import { WeaDialog, WeaError, WeaFormItem, WeaInput } from "ecCom";
import "./index.less";

export default class CopySchemaModal extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      value: this.props.value || ""
    };
  }

  render() {
    return (
      <WeaDialog
        title={`复制${this.props.title}`}
        initLoadCss
        className="copyDialogWrapper"
        buttons={this.props.footer}
        onCancel={() => this.props.onCancel()}
        visible={this.props.visible}>
        <div className='contentWrapper'>
          <WeaFormItem
            label={`${this.props.title}名称`}
            labelCol={{ span: 6 }}
            wrapperCol={{ span: 18 }}
          >
            <WeaError
              tipPosition="bottom"
              ref="weaError"
              style={{ width: "90%" }}
              error={`${this.props.title}名称不能为空`}>
              <WeaInput
                value={this.state.value}
                style={{ width: "100%" }}
                viewAttr={3}
                onChange={(v) => {
                  if (v === "") this.refs.weaError.showError();
                  this.setState({ value: v });
                  this.props.onChange(v);
                }}/>
            </WeaError>
          </WeaFormItem>
        </div>
      </WeaDialog>
    );
  }
}
