import React,{Component} from 'react'
import  {FormattedMessage} from 'react-intl'
import PropTypes from 'prop-types';


export class Label extends Component{
    static contextTypes = {
        trn: PropTypes.string
    }

    shouldComponentUpdate(nextProps,nextState)
    {
        if(isEquals(nextProps,this.props) && isEquals(nextState,this.state))
            return false
        return true;
    }
    render()
    {
        let {code,value,text,itext,i18nId,desp,...rest} = this.props
        let txt = value || itext ||text
        
        if(!i18nId && itext)
            i18nId = itext
        if(i18nId)
        return <span className="comp_label">
            <FormattedMessage  id={i18nId}  defaultMessage={desp||i18nId} />
        </span>
        


        if(code && txt)
        {
            let em = code.find(item=>item.value==this.props.value)
            if(em)
                txt = em.label
        }
        
        return (
            <span className="comp_label" {...rest} >
                {txt}
            </span>
        )
    }
}


export class Section extends Component{
    render()
    {
        const {value,...rest} = this.props
        return <p {...rest}>
            {value}
        </p>
    }
}