import React, { Component } from 'react'
import ReactTable from 'react-table'
import 'react-table/react-table.css'

/*  Add a field to the state of this component that is a boolean that determines if he is sign in or not. */
class Results extends Component {
  render () {
    /*
    search results are accessed via this.props.location.state.state_results)
    where state_results is an array of json structures.
      e.g. state_results[1].mtname for the mtname of the 2nd json in the array
    */


    let data = null
    if (this.props.data != null) {
      data = this.props.data;
    } else if (this.props.location != null) {
      data = this.props.location.state.state_results
    }
    console.log("In results...")
    console.log(data)
    if (data==null || Object.keys(data).length == 0) {
      return (
        "No data to display"
      )
    }

    let columns = new Array();
    const keys = Object.keys(data[0]);
    for (let i=0; i < keys.length; i++) {
      if (keys[i] == 'Matter Title') {
        columns.push({
          Header: `${keys[i]}`,
          accessor: `${keys[i]}`,
          Cell: data => <a href={"viewItem/" + data.row.Id}> {data.row['Matter Title']}</a>
        })
      } else {
        columns.push({
          Header: `${keys[i]}`,
          accessor: `${keys[i]}`
        })
      }
    }



    return (
      <ReactTable
        columns={columns}
        data={data}
      />
    )
  }

  getTable = (data) => {

  }
}

export default Results
