/**
 * @license
 * The MIT License (MIT)
 * Copyright 2015 Government of Canada
 *
 * @author
 * Ian Boyes
 *
 * @exports IsolateAdd
 */
import React from "react";
import { connect } from "react-redux";
import { Modal } from "react-bootstrap";
import { editIsolate, hideOTUModal } from "../../actions";
import IsolateForm from "./IsolateForm";

const getInitialState = props => ({
    sourceType: props.sourceType || (props.restrictSourceTypes ? "unknown" : ""),
    sourceName: props.sourceName || ""
});

class EditIsolate extends React.Component {
    constructor(props) {
        super(props);
        this.state = getInitialState(this.props);
    }

    handleChange = update => {
        this.setState(update);
    };

    handleSubmit = e => {
        e.preventDefault();

        this.props.onSave(this.props.otuId, this.props.isolateId, this.state.sourceType, this.state.sourceName);
    };

    render() {
        return (
            <Modal bsStyle="warning" show={this.props.show} onEntered={this.modalEntered} onHide={this.props.onHide}>
                <Modal.Header onHide={this.props.onHide} closeButton>
                    Edit Isolate
                </Modal.Header>
                <IsolateForm
                    sourceType={this.state.sourceType}
                    sourceName={this.state.sourceName}
                    allowedSourceTypes={this.props.allowedSourceTypes}
                    restrictSourceTypes={this.props.restrictSourceTypes}
                    onChange={this.handleChange}
                    onSubmit={this.handleSubmit}
                />
            </Modal>
        );
    }
}

const mapStateToProps = state => ({
    show: state.otus.editIsolate,
    allowedSourceTypes: state.references.detail.source_types,
    restrictSourceTypes: state.references.detail.restrict_source_types
});

const mapDispatchToProps = dispatch => ({
    onHide: () => {
        dispatch(hideOTUModal());
    },

    onSave: (otuId, isolateId, sourceType, sourceName) => {
        dispatch(editIsolate(otuId, isolateId, sourceType, sourceName));
    }
});

export default connect(mapStateToProps, mapDispatchToProps)(EditIsolate);

@@ -206,24 +206,30 @@
 port %7B Modal
+Dialog
  %7D from %22rea
@@ -229,23 +229,21 @@
 om %22
-react-bootstrap
+../../../base
 %22;%0Ai
@@ -952,26 +952,145 @@
 odal
- bsStyle=%22warning%22
+Dialog%0A                headerText=%22Edit Isolate%22%0A                label=%22EditIsolate%22%0A                moadlStyle=%22warning%22%0A               
  sho
@@ -1108,16 +1108,32 @@
 ps.show%7D
+%0A               
  onEnter
@@ -1158,36 +1158,8 @@
 red%7D
- onHide=%7Bthis.props.onHide%7D%3E
 %0A   
@@ -1175,22 +1175,8 @@
     
-%3CModal.Header 
 onHi
@@ -1201,85 +1201,21 @@
 ide%7D
- closeButton%3E%0A                    Edit Isolate%0A                %3C/Modal.Header
+%0A            
 %3E%0A  
@@ -1612,16 +1612,16 @@
      /%3E%0A
-
         
@@ -1631,16 +1631,22 @@
  %3C/Modal
+Dialog
 %3E%0A      

Replace bootstrap modal in EditIsolate Component