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

export type ICompanyPaymentAccountSelectProps = {
	onFinish?: (accountList: BusinessAPI.CompanyPaymentAccountVO[]) => void;
	params: BusinessAPI.CompanyPaymentAccountPageQry;
} & ProFormSelectProps;

export default function CompanyPaymentAccountSelect(
	props: ICompanyPaymentAccountSelectProps,
) {
	const intl = useIntl();
	console.log('props', props);

	return (
		<ProFormDependency name={['companyPaymentAccountVO', 'canChangeAccount']}>
			{({ companyPaymentAccountVO, canChangeAccount }, form) => {
				return (
					<CompanyPaymentAccountSearch
						{...(canChangeAccount !== undefined && {
							readonly: !canChangeAccount,
						})}
						className={'company-payment-account-select'}
						form={form}
						{...(companyPaymentAccountVO && {
							selectedList: [companyPaymentAccountVO],
						})}
						label={intl.formatMessage({
							id: 'form.companyPaymentAccountId.label',
						})}
						name={'companyPaymentAccountVO'}
						required={true}
						placeholder={intl.formatMessage({
							id: 'form.companyPaymentAccountId.placeholder',
						})}
						rules={[
							{
								required: true,
								message: intl.formatMessage({
									id: 'form.companyPaymentAccountId.required',
								}),
							},
						]}
						{...props}
					/>
				);
			}}
		</ProFormDependency>
	);
}
