import React from 'react';
import Icon from "@/jsx/Components/Icon.jsx";

export default class Label extends React.Component {

  constructor(props) {
    super(props);
  }

  /**
   * Get the classes for the label
   * @return {string}
   */
  classes() {
    const {className, processing} = this.props;

    let classes = ['ra-label'];
    if (className) {
      classes.push(className);
    }

    if (processing) {
      classes.push('processing');
    }

    return classes.join(' ');
  }

  render() {

    const {processing} = this.props;

    return (
      <label
        htmlFor={this.props.name}
        className={this.classes()}
      >
        {
          processing === true && (
            <span className="ra-processing">
              <Icon>
                loading
              </Icon>
            </span>
          )
        }
        <span className="ra-label-text">
          {this.props.children}
        </span>
      </label>
    );
  }

}
