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

export type IReconciliationInvoiceSelectProps = {
	onFinish?: (
		reconciliationInvoiceVOList: BusinessAPI.ReconciliationInvoiceVO[],
	) => void;
	params: BusinessAPI.ReconciliationInvoicePageQry;
} & ProFormSelectProps;

export default function ReconciliationInvoiceSelect(
	props: IReconciliationInvoiceSelectProps,
) {
	const intl = useIntl();

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