import React from 'react';
import { getDatasetParameterByName } from '../../helpers';
import ParameterTableWidget from './ParameterTableWidget';

class InstrumentSlitWidget extends React.Component {
  getParameter(parameterName) {
    return getDatasetParameterByName(this.props.dataset, parameterName);
  }

  getJSONKeyValuePair(name, value) {
    return { name, value };
  }

  getSlitValues(prefix) {
    return [
      this.getJSONKeyValuePair(
        'Blade Front',
        getDatasetParameterByName(this.props.dataset, `${prefix}_blade_front`)
      ),
      this.getJSONKeyValuePair(
        'Blade Back',
        getDatasetParameterByName(this.props.dataset, `${prefix}_blade_back`)
      ),
      this.getJSONKeyValuePair(
        'Blade Up',
        getDatasetParameterByName(this.props.dataset, `${prefix}_blade_up`)
      ),
      this.getJSONKeyValuePair(
        'Blade Down',
        getDatasetParameterByName(this.props.dataset, `${prefix}_blade_down`)
      ),
      this.getJSONKeyValuePair(
        'Horizontal Gap',
        getDatasetParameterByName(
          this.props.dataset,
          `${prefix}_horizontal_gap`
        )
      ),
      this.getJSONKeyValuePair(
        'Horizontal Offset',
        getDatasetParameterByName(
          this.props.dataset,
          `${prefix}_horizontal_offset`
        )
      ),
      this.getJSONKeyValuePair(
        'Vertical Gap',
        getDatasetParameterByName(this.props.dataset, `${prefix}_vertical_gap`)
      ),
      this.getJSONKeyValuePair(
        'Vertical Offset',
        getDatasetParameterByName(
          this.props.dataset,
          `${prefix}_vertical_offset`
        )
      ),
    ];
  }

  render() {
    return (
      <div className="container-fluid">
        <br />
        <span style={{ fontSize: 16, fontWeight: 'bold' }}>Slits</span>
        <div className="row">
          <div className="col-sm-2">
            <ParameterTableWidget
              header="Primary slit"
              parameters={this.getSlitValues('InstrumentSlitPrimary')}
            />
          </div>
          <div className="col-sm-2">
            <ParameterTableWidget
              header="Secondary slit"
              parameters={this.getSlitValues('InstrumentSlitSecondary')}
            />
          </div>
          <div className="col-sm-8">
            <ParameterTableWidget
              header="Slits"
              parameters={this.getSlitValues('InstrumentSlits')}
            />
          </div>
        </div>
      </div>
    );
  }
}

export default InstrumentSlitWidget;
