import {
	observer
} from 'mobx-react';
import {
	WeaDialog,
	WeaFormItem,
	WeaInput
} from 'ecCom';
import Customization from './Customization';
import {
    Spin,
    Button,Modal
} from 'antd'
import {
    i18n
} from '../../public/i18n';
const confirm = Modal.confirm;

@observer
export default class SearchCustomDialog extends React.Component {
	constructor(props) {
		super(props);
	}


	saveCustomTemplate() {
        const {
            store
        } = this.props, {
            customTemplateName
        } = store;

        confirm({
            title: "存为模板",
            content: 
                <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@62kt85`}
                    label="列定制模板名称"
                    labelCol={{ span: 10 }}
                    wrapperCol={{ span: 14 }}>
                    <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@j9bmvw`} viewAttr="3" value={customTemplateName} {...window.inputType} onChange={v => store.customTemplateName = v} />
                </WeaFormItem>,
            okText: i18n.button.save(),
            cancelText: i18n.button.cancel(),
            onOk() {
                store.saveCustomTemplate();
            },
            onCancel() {
                return false;
            },
        });
    }

	render() {
		const {
			store,
		} = this.props, {
			SEARCHDIALOG,
			searchDialog,
			search,
			searchTemplateName
		} = store;
		const buttons = [
            <Button type='primary' onClick={()=> search ? store.saveHrmSearchUserDefine() : store.saveCustomDefine()}>保存</Button>,
            <Button type='primary' onClick={()=> this.saveCustomTemplate()}>存为模板</Button>,
            <Button type='primary' onClick={()=> store.getEditTable()}>模板管理</Button>
        ]


		return (
			<WeaDialog
				{...SEARCHDIALOG}
				{...searchDialog}
				buttons={search ? buttons.slice(0, 1) : buttons}
				initLoadCss
				title={search ? '常用条件定制':'列定制'}
			>
                <Customization store={store}/>
			</WeaDialog>
		);
	}
}