import React from "react"
import { Button, Modal } from "react-bootstrap"
import PropTypes from "prop-types"
import PositionTable from "components/PositionTable"
import PersonTable from "./PersonTable"
import LocationTable from "./LocationTable"

const DEFAULT_PAGESIZE = 10

const SimilarObjectsModal = ({ objectType, userInput, onCancel }) => {
  const queryParams = Object.assign({
    sortBy: "NAME",
    sortOrder: "ASC",
    pageNum: 0,
    pageSize: DEFAULT_PAGESIZE,
    text: userInput
  })

  return (
    <Modal show={true} onHide={onCancel}>
      <Modal.Header closeButton>
        <Modal.Title>Possible Duplicates</Modal.Title>
      </Modal.Header>
      <Modal.Body>
        {objectType === "Person" && (
          <PersonTable queryParams={queryParams} id="similar-people-table" />
        )}
        {objectType === "Location" && (
          <LocationTable
            queryParams={queryParams}
            id="similar-locations-table"
          />
        )}
        {objectType === "Position" && (
          <PositionTable
            queryParams={queryParams}
            id="similar-positions-table"
          />
        )}
      </Modal.Body>
      <Modal.Footer>
        <Button className="pull-left" onClick={onCancel}>
          Cancel
        </Button>
      </Modal.Footer>
    </Modal>
  )
}

SimilarObjectsModal.propTypes = {
  objectType: PropTypes.string,
  userInput: PropTypes.string,
  onCancel: PropTypes.func
}

export default SimilarObjectsModal

@@ -269,16 +269,122 @@
 E = 10%0A%0A
+const TABLE_COMPONENTS = %7B%0A  Location: LocationTable,%0A  Person: PersonTable,%0A  Position: PositionTable%0A%7D%0A%0A
 const Si
@@ -446,16 +446,16 @@
 %7D) =%3E %7B%0A
-
   const 
@@ -606,14 +606,93 @@
 %0A%0A  
-return
+const TableComponent = TABLE_COMPONENTS%5BobjectType%5D%0A  return !TableComponent ? null :
  (%0A 
@@ -873,462 +873,52 @@
     
-%7BobjectType === %22Person%22 && (%0A          %3CPersonTable queryParams=%7BqueryParams%7D id=%22similar-people-table%22 /%3E%0A        )%7D%0A        %7BobjectType === %22Location%22 && (%0A          %3CLocationTable%0A            queryParams=%7BqueryParams%7D%0A            id=%22similar-locations-table%22%0A          /%3E%0A        )%7D%0A        %7BobjectType === %22Position%22 && (%0A          %3CPositionTable%0A            queryParams=%7BqueryParams%7D%0A            id=%22similar-positions-table%22%0A          /%3E%0A        )%7D
+%3CTableComponent queryParams=%7BqueryParams%7D /%3E
 %0A   

Simplify component