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

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

	get dialogProps() {
		const props = {
			hasScroll: true,
			icon: 'icon-coms-hrm',
			iconBgcolor: '#217346',
		}
		if (this.root.moreDialogProps) {
		    return Object.assign({}, props, this.root.moreDialogProps);
		} else {
		    return props;
		}
	}

	@observable visible = false;
	@observable title = '';
	@observable style = {};
	@observable mark = '';
	@observable moduleName = 'hrm';

	@action init = (config) => {
		Object.keys(config).forEach(key => {
			this[key] = config[key];
		})
		return this
	}

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

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

		this._closeDialog && this._closeDialog();
	}

	@action setTitle = (title) => {
		this.title = title;
	}

	@computed get buttons() {
		const mark = (this.mark !== undefined) ? this.mark : '';
		const btn = this.root[`${mark}DialogButtons`];
		return btn || []
	}

	@computed get moreBtn() {
		const mark = (this.mark !== undefined) ? this.mark : '',
			btn = this.root[`${mark}MoreBtn`];

		return btn ? btn : {
			datas: []
		};
	}

}