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

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

				const wxMaConfigValue =
					data?.settingValue as BusinessAPI.WxMaConfigValue;
				return {
					...wxMaConfigValue,
					wxMaLogoList: [wxMaConfigValue?.wxMaLogo],
				} as BusinessAPI.WxMaConfigValue;
			}}
			onFinish={async (values) => {
				await business.setting.updateSetting({
					settingKey: 'ALI_PAY_CONFIG',
					settingValue: {
						...values,
						settingKey: 'ALI_PAY_CONFIG',
					},
				});

				message.success('更新支付宝配置成功');
			}}
			submitter={{
				render: (_, dom) => {
					return (
						<Row>
							<Col span={14} offset={4}>
								<Space>{dom}</Space>
							</Col>
						</Row>
					);
				},
			}}
		>
			<ProFormText hidden={true} name={'settingId'} />
			<ProFormText
				name="appId"
				label="支付宝APPID"
				placeholder={'请输入支付宝APPID'}
				required={true}
				rules={[
					{
						required: true,
						message: '支付宝APPID为必填项',
					},
				]}
			/>
			<ProFormTextArea
				name="appId"
				label="应用私钥"
				placeholder={'请输入应用私钥'}
				required={true}
				rules={[
					{
						required: true,
						message: '应用私钥为必填项',
					},
				]}
			/>
			<ProFormTextArea
				name="appId"
				label="应用公钥"
				placeholder={'请输入应用公钥'}
				required={true}
				rules={[
					{
						required: true,
						message: '应用公钥为必填项',
					},
				]}
			/>
			<ProFormTextArea
				name="appId"
				label="支付宝公钥证书"
				placeholder={'请输入支付宝公钥证书'}
				required={true}
				rules={[
					{
						required: true,
						message: '支付宝公钥为必填项',
					},
				]}
			/>
			<ProFormTextArea
				name="appId"
				label="支付宝根证书"
				placeholder={'请输入支付宝根证书'}
				required={true}
				rules={[
					{
						required: true,
						message: '支付宝根证书为必填项',
					},
				]}
			/>
		</ProForm>
	);
}
