import { BizContainer, BizValueType, ModeType } from '@/components';
import { business } from '@/services';
import { useIntl } from '@@/exports';
import { ProColumns, ProFormText } from '@ant-design/pro-components';
import { ProDescriptionsItemProps } from '@ant-design/pro-descriptions';
import React from 'react';

interface IBoxSpecListProps {
	ghost?: boolean;
	specId?: BusinessAPI.BoxSpecVO['specId'];
	search?: boolean;
	onValueChange?: () => void;
	mode?: ModeType;
	trigger?: () => React.ReactNode;
}
export default function BoxSpecList(props: IBoxSpecListProps) {
	const {
		ghost = false,
		specId,
		search = true,
		mode = 'drag',
		trigger,
		onValueChange,
	} = props;
	const intl = useIntl();
	const intlPrefix = 'boxSpec';

	const columns: ProColumns<BusinessAPI.BoxSpecVO, BizValueType>[] = [
		{
			title: intl.formatMessage({ id: intlPrefix + '.column.name' }),
			dataIndex: 'name',
			key: 'name',
			renderText: (text: string) => <span className="font-medium">{text}</span>,
		},
	];

	const formContext = [
		<ProFormText
			key={'name'}
			name={'name'}
			label={intl.formatMessage({ id: intlPrefix + '.form.name.label' })}
			required={true}
			placeholder={intl.formatMessage({
				id: intlPrefix + '.form.name.placeholder',
			})}
			rules={[
				{
					required: true,
					message: intl.formatMessage({
						id: intlPrefix + '.form.name.required',
					}),
				},
			]}
		/>,
	];

	const detailColumns: ProDescriptionsItemProps<
		BusinessAPI.BoxSpecVO,
		BizValueType
	>[] = columns as ProDescriptionsItemProps<
		BusinessAPI.BoxSpecVO,
		BizValueType
	>[];

	return (
		<BizContainer<
			typeof business.boxSpec,
			BusinessAPI.BoxSpecVO,
			BusinessAPI.BoxSpecPageQry,
			BusinessAPI.BoxSpecCreateCmd,
			BusinessAPI.BoxSpecUpdateCmd
		>
			rowKey={'specId'}
			permission={'operation-box-spec'}
			func={business.boxSpec}
			method={'boxSpec'}
			methodUpper={'BoxSpec'}
			intlPrefix={intlPrefix}
			modeType={mode}
			onValueChange={onValueChange}
			container={{ ghost }}
			remark={{
				mode: 'editor',
			}}
			status
			drag={{
				fieldProps: {
					bordered: true,
					ghost,
					//@ts-ignore
					search,
				},
				columns,
			}}
			create={{
				formType: 'drawer',
				formContext,
			}}
			update={{
				formType: 'drawer',
				formContext,
			}}
			destroy={{}}
			detail={{
				rowId: specId,
				formType: 'drawer',
				columns: detailColumns,
				trigger,
			}}
		/>
	);
}
