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

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

				const wxMaMessagePushConfigValue =
					data?.settingValue as BusinessAPI.WxMaMessagePushConfigValue;
				return {
					...wxMaMessagePushConfigValue,
				} as BusinessAPI.WxMaConfigValue;
			}}
			onFinish={async (values) => {
				await business.setting.updateSetting({
					settingKey: 'WX_MA_MESSAGE_PUSH_CONFIG',
					settingValue: {
						...values,
						settingKey: 'WX_MA_MESSAGE_PUSH_CONFIG',
					},
				});

				message.success('更新消息推送设置成功');
			}}
			submitter={{
				render: (_, dom) => {
					return (
						<Row>
							<Col span={14} offset={4}>
								<Space>{dom}</Space>
							</Col>
						</Row>
					);
				},
			}}
		>
			<ProFormText
				name="token"
				label="Token(令牌)"
				placeholder={'请输入Token(令牌)'}
				required={true}
				rules={[
					{
						required: true,
						message: 'Token(令牌)为必填项',
					},
				]}
			/>
			<ProFormText
				name="encodingAESKey"
				label="EncodingAESKey"
				placeholder={'请输入EncodingAESKey'}
				required={true}
				rules={[
					{
						required: true,
						message: 'EncodingAESKey为必填项',
					},
				]}
			/>
			<ProFormSelect
				name="msgEncryptMode"
				label="消息加密方式"
				placeholder={'请选择消息加密方式'}
				required={true}
				rules={[
					{
						required: true,
						message: '消息加密方式为必填项',
					},
				]}
				options={[
					{
						label: '明文模式',
						value: '1',
					},
					{
						label: '兼容模式',
						value: '2',
					},
					{
						label: '安全模式',
						value: '3',
					},
				]}
			/>
			<ProFormSelect
				name="dataFormat"
				label="数据格式"
				placeholder={'请选择数据格式'}
				required={true}
				rules={[
					{
						required: true,
						message: '数据格式为必填项',
					},
				]}
				options={[
					{
						label: 'XML',
						value: 'XML',
					},
				]}
			/>
			<ProFormText
				name="ipWhiteList"
				disabled={true}
				label="IP白名单"
				placeholder={'暂无IP白名单'}
			/>
			<ProFormText
				name="url"
				disabled={true}
				label="URL(服务器地址)"
				placeholder={'暂无URL地址'}
			/>
		</ProForm>
	);
}
