import { ReconciliationSearch } from '@/components';
import { useIntl } from '@@/exports';
import {
	ProFormDependency,
	ProFormSelectProps,
} from '@ant-design/pro-components';

export type IReconciliationSelectProps = {
	onFinish?: (reconciliationVOList: BusinessAPI.ReconciliationVO[]) => void;
	params: BusinessAPI.ReconciliationPageQry;
} & ProFormSelectProps;

export default function ReconciliationSelect(
	props: IReconciliationSelectProps,
) {
	const intl = useIntl();

	return (
		<ProFormDependency name={['reconciliationVO', 'canChangeReconciliation']}>
			{({ reconciliationVO, canChangeReconciliation }, form) => {
				return (
					<ReconciliationSearch
						{...(canChangeReconciliation !== undefined && {
							readonly: !canChangeReconciliation,
						})}
						className={'reconciliation-select'}
						form={form}
						{...(reconciliationVO && {
							selectedList: [reconciliationVO],
						})}
						label={intl.formatMessage({
							id: 'form.reconciliationId.label',
						})}
						name={'reconciliationId'}
						required={true}
						placeholder={intl.formatMessage({
							id: 'form.reconciliationId.placeholder',
						})}
						rules={[
							{
								required: true,
								message: intl.formatMessage({
									id: 'form.reconciliationId.required',
								}),
							},
						]}
						{...props}
					/>
				);
			}}
		</ProFormDependency>
	);
}
