import { business } from '@/services';
import { formLayout } from '@/utils/formLayout';
import { ProForm, ProFormText } from '@ant-design/pro-components';
import { Col, message, Row, Space } from 'antd';

export default function WxCpNotifyConfig() {
	return (
		<ProForm
			{...formLayout()}
			request={async () => {
				const { data } = await business.setting.showSetting({
					settingShowQry: {
						settingKey: 'WX_CP_NOTIFY_CONFIG',
					},
				});

				const wxCpNotifyConfigValue =
					data?.settingValue as BusinessAPI.WxCpNotifyConfigValue;
				return {
					...wxCpNotifyConfigValue,
				} as BusinessAPI.WxCpNotifyConfigValue;
			}}
			onFinish={async (values) => {
				await business.setting.updateSetting({
					settingKey: 'WX_CP_NOTIFY_CONFIG',
					settingValue: {
						...values,
						settingKey: 'WX_CP_NOTIFY_CONFIG',
					},
				});

				message.success('更新企业微信通知设置成功');
			}}
			submitter={{
				render: (_, dom) => {
					return (
						<Row>
							<Col span={14} offset={4}>
								<Space>{dom}</Space>
							</Col>
						</Row>
					);
				},
			}}
		>
			<ProFormText
				name="communityApplyNotifyKey"
				label="小区申请通知"
				placeholder={'请输入小区申请通知key'}
			/>
		</ProForm>
	);
}
