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

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


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

        confirm({
            title: getLabel(547548,'存为模板'),
            content: 
                <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@62kt85`}
                    label= {getLabel(547581,'列定制模板名称')}
                    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,
            loginId
		} = store;
		const buttons = [
            <Button type='primary' onClick={()=> search ? store.saveHrmSearchUserDefine() : store.saveCustomDefine()}>{getLabel(547360,'保存')}</Button>,
            <Button type='primary' onClick={()=> this.saveCustomTemplate()}>{getLabel(547548,'存为模板')}</Button>,
            <Button type='primary' onClick={()=> store.getEditTable()}>{getLabel(547582,'模板管理')}</Button>,
            loginId == 1 ?<Button type='primary' onClick={()=> store.setOverAll()}>{getLabel(547853,'将当前模板应用所有人')}</Button> : ''
        ]


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