text: import _ from 'lodash'
  import React, {Component} from 'react'
  import {connect} from 'react-redux'
  import Communications from 'react-native-communications'
  import EmployeeForm from './EmployeeForm'
  import {Button, Card, CardSection, Confirm} from "./common"
  import {employeeDelete, employeeResetForm, employeeSave, employeeUpdate} from '../actions'
  
  class EmployeeEdit extends Component {
      state = {showModal: false};
  
      componentWillMount() {
          _.each(this.props.employee, (value, prop) => {
              this.props.employeeUpdate({prop, value});
          })
      }
  
      componentWillUnmount() {
          this.props.employeeResetForm();
      }
  
      onButtonPress() {
          const {name, phone, shift} = this.props;
  
          this.props.employeeSave({
              name,
              phone,
              shift,
              uid: this.props.employee.uid
          });
      }
  
      onTextPress() {
          const {name, phone, shift} = this.props;
  
          Communications.text(phone, `Yout upcoming shift is on ${shift}, thanks ${name}!`);
      }
  
      onAccept() {
          const {uid} = this.props.employee;
  
          this.setState({showModal: false});
          this.props.employeeDelete({uid});
      }
  
      onDecline() {
          this.setState({showModal: false});
      }
  
      render() {
          return (
              <Card>
                  <EmployeeForm/>
                  <CardSection>
                      <Button onPress={this.onButtonPress.bind(this)}>
                          Save Changes
                      </Button>
                  </CardSection>
                  <CardSection>
                      <Button onPress={this.onTextPress.bind(this)}>
                          Text Schedule
                      </Button>
                  </CardSection>
                  <CardSection>
                      <Button onPress={() => this.setState({showModal: !this.state.showModal})}>
                          Fire Employee
                      </Button>
                  </CardSection>
                  <Confirm
                      visible={this.state.showModal}
                      onAccept={this.onAccept.bind(this)}
                      onDecline={this.onDecline.bind(this)}
                  >
                      Are you sure you want to delete this?
                  </Confirm>
              </Card>
          );
      };
  }
  
  const mapStateToProps = state => {
      const {name, phone, shift} = state.employeeForm;
  
      return {name, phone, shift};
  };
  
  export default connect(mapStateToProps, {
      employeeUpdate,
      employeeSave,
      employeeResetForm,
      employeeDelete
  })(EmployeeEdit)