/**
 * Created by geweimin on 17/7/19.
 */
import React from 'react';

import TitleBar from '../../modules/info/titleBar';
import { convertTemplate } from '../../utils/StringUtils';

export default class DetailTitle extends React.Component {

  _getDetailTitleDesc = () => {
    return '';
  };

  _getTitleDesc = () => {
    const { dataSource = {} } = this.props;
    const { pageMenu = {} } = dataSource;
    const name = pageMenu.name;
    const headerDesc = pageMenu.headerDesc;
    const headerId = pageMenu.headerId;
    if (!headerDesc || headerDesc === 'null') return name;
    if (!headerId || headerId === 'null') return name + '-' + convertTemplate(headerDesc, this.props.query);
    return convertTemplate(headerDesc, this.props.query) + ' ' + convertTemplate(headerId, this.props.query);
  };

  render() {
    const { domainType } = this.props;
    if (domainType === 'Detail') {
      return (
        <TitleBar getTitleDesc={this._getDetailTitleDesc} />
      );
    }
    const { infoCompletenessBean } = this.props.dataSource;
    return (
      <TitleBar getTitleDesc={this._getTitleDesc} infoCompleteness={infoCompletenessBean && infoCompletenessBean.totalValue}>
        {this.props.globalBtns}
      </TitleBar>
    );
  }

}
