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

export type IUserSelectProps = {
	onFinish?: (dealerVOList: BusinessAPI.DealerVO[]) => void;
	params?: BusinessAPI.DealerPageQry;
} & ProFormSelectProps;

export default function DealerSelect(props: IUserSelectProps) {
	const intl = useIntl();

	return (
		<ProFormDependency name={['dealerVO', 'canChangeDealer']}>
			{({ dealerVO, canChangeDealer }, form) => {
				console.log('dealerVO', dealerVO);
				return (
					<DealerSearch
						{...(canChangeDealer !== undefined && {
							readonly: !canChangeDealer,
						})}
						className={'dealer-select'}
						form={form}
						{...(dealerVO && { selectedList: [dealerVO] })}
						label={intl.formatMessage({
							id: 'form.dealerId.label',
						})}
						name={'dealerId'}
						required={true}
						placeholder={intl.formatMessage({
							id: 'form.dealerId.placeholder',
						})}
						rules={[
							{
								required: true,
								message: intl.formatMessage({
									id: 'form.dealerId.required',
								}),
							},
						]}
						{...props}
					/>
				);
			}}
		</ProFormDependency>
	);
}
