import React from 'react';
import PropTypes from 'prop-types';
import { getLanguage } from '../../utils';
import './label-item.css';
import { $characterSub, $buttonColor } from '../styles/theme'

const LabelItem = (props) => {
  const styles = {
    root: {
      display: 'flex',
      alignItems: props.alignItems || 'flex-start',
    },
    title: {
      flexBasis: getLanguage() === 'zh-CN' ? 96 : 120,
      marginRight: '24px',
      color: $characterSub,
      paddingTop: 7,
      flexShrink: 0,
    },
    required: {
      color: $buttonColor,
      width: 8,
      height: 3,
      paddingLeft: 5,
    },
    content: {
      flex: '0 1 auto',
    }
  }
  const { title, required, children, style, titleStyle, contentStyle, titleElement } = props;
  return (
    <div style={Object.assign({}, styles.root, style)} className="pay_label-item">
      <span style={Object.assign({}, styles.title, titleStyle)}>
        {title}
        {required ? <span style={styles.required}>*</span> : ''}
        {titleElement}
      </span>
      <div style={Object.assign({}, styles.content, contentStyle)}>{children}</div>
    </div>
  );
};

LabelItem.propTypes = {
  title: PropTypes.string,
  required: PropTypes.bool,
  children: PropTypes.node,
  style: PropTypes.object,
  titleStyle: PropTypes.object,
  contentStyle: PropTypes.object,
};
LabelItem.defaultProps = {
  title: '',
  required: false,
  children: null,
  style: {},
  titleStyle: {},
  contentStyle: {},
};


export default LabelItem;
