import {
	observable,
	action,
	computed
} from 'mobx';

export default class DialogStore {
	constructor(rootStore) {
		this.rootStore = rootStore;
	}

	get dialogProps() {
		return {
			hasScroll: true,
			icon: 'icon-coms-hrm',
			iconBgcolor: '#217346',
		}
	}

	//控制弹框显隐
	@observable visible = false;

	@action openDialog = () => {
		this.visible = true;
	}

	@action closeDialog = () => {
		this.visible = false;

		const mark = this.getDialogMark();
		let markPro;
		if (mark) {
			//首字母大写
			markPro = mark.replace(mark[0],mark[0].toUpperCase());
		}else{
			markPro = mark;
		}

		if (this.rootStore[`close${markPro}Dialog`]) {
			this.rootStore[`close${markPro}Dialog`]();
		}
	}

	@computed get buttons() {
		const mark = this.getDialogMark();
		return this.rootStore[`${mark}DialogButtons`];
	}

	@computed get moreBtn() {
		const mark = this.getDialogMark();
		return this.rootStore[`${mark}MoreBtn`];
	}

	//获取弹框的标识,便于从rootStore中获取对应的buttons和moreBtn。
	getDialogMark = () => {
		return (this.dialogMark !== undefined) ? this.dialogMark : '';
	}

	//设置弹框的标题、样式、标识等。
	setDialogConfig=(config)=>{
		Object.keys(config).forEach(key=>{
			this[key] = config[key];
		})
	}


}