import React, {
	Component
} from 'react';
import {
	WeaOrgTree
} from 'ecCom';
import {
	i18n
} from '../public/i18n';

export default class OrganizationTree extends Component {
	constructor(props) {
		super(props);
		this.state = {
			checkStrictlyTitle: (this.props.showCheckStrictly ? this.getTitle(this.props.checkStrictly) : ''),
			checkStrictly: this.props.checkStrictly  || false
		}
	}

	getTitle = (val) => {
		if(this.props.checkStrictlyTitles != null){
			if(val) 
				return this.props.checkStrictlyTitles[1];
			return this.props.checkStrictlyTitles[0];
		}else{
			
		}
	}

	onCheckStrictlyChange = (val) => {
		this.setState({checkStrictlyTitle: this.getTitle(val), checkStrictly: val});
		this.props.onCheckStrictlyChangeCallback && this.props.onCheckStrictlyChangeCallback(val);
	}

	render() {
		let checkableTypes = null;
		if(this.props.getCheckableTypes)
			checkableTypes = this.props.getCheckableTypes();
		return (
			<WeaOrgTree ecId={`${this && this.props && this.props.ecId || ''}_WeaOrgTree@gijp4e`} {...this.props} checkableTypes={checkableTypes}
			inputLeftDom={`<div style="overflow: hidden;text-overflow:ellipsis;white-space: nowrap;"><b>${i18n.label.organization()}</b></div>`} 
			checkStrictlyTitle={this.state.checkStrictlyTitle} 
			onCheckStrictlyChange={this.onCheckStrictlyChange} 
			checkStrictly={this.state.checkStrictly}
			ref='tree'/>
		)
	}
}