import React, { Component } from 'react';
import {SQLResultSetRow} from 'components';

export default class SQLResultSet extends Component {
  render() {
    // let {headers, resultantDB} = this.props.resultSet;
    let renderTableHeader;
    if (this.props.resultSet.hasOwnProperty('headers')) {
      renderTableHeader = this.props.resultSet.headers.map(function (headerValue, index) {
        return (
          <th key={index}>
            {headerValue}
          </th>
        );
      });
    }
    let renderTableBody;
    if (this.props.resultSet.hasOwnProperty('dbData')) {
      renderTableBody = this.props.resultSet.dbData.map(function (row, index) {
        return (
          <SQLResultSetRow key={index} row={row}/>
        );
      });
    }
    return (
      <div id="container">
        <div className="LoginTable ">
          <table className="table tableInMobile" id="loginDetailstable">
            <thead>
              <tr className='table-header'>
                  {renderTableHeader}
              </tr>
            </thead>
            <tbody>
               {renderTableBody}
            </tbody>
          </table>
        </div>
      </div>
    );
  }
}
