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

export interface IPlatformListProps {
	ghost?: boolean;
	search?: boolean;
	mode?: ModeType;
	trigger?: () => React.ReactNode;
	onValueChange?: () => void;
}

export default function PlatformList(props: IPlatformListProps) {
	const {
		mode = 'page',
		ghost = false,
		search = true,
		onValueChange,
		trigger,
	} = props;
	const intl = useIntl();
	const intlPrefix = 'platform';

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

	const columns: ProColumns<BusinessAPI.PlatformVO, BizValueType>[] = [
		{
			title: intl.formatMessage({
				id: intlPrefix + '.column.name',
			}),
			dataIndex: 'platformName',
		},
	];

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

	return (
		<BizContainer<
			typeof business.platform,
			BusinessAPI.PlatformVO,
			BusinessAPI.PlatformPageQry,
			BusinessAPI.PlatformCreateCmd,
			BusinessAPI.PlatformUpdateCmd
		>
			rowKey={'platformId'}
			permission={'operation-platform'}
			func={business.platform}
			method={'platform'}
			methodUpper={'Platform'}
			intlPrefix={intlPrefix}
			modeType={mode}
			onValueChange={onValueChange}
			container={{
				ghost,
			}}
			page={{
				fieldProps: {
					ghost,
					//@ts-ignore
					search,
				},
				columns,
			}}
			create={{
				formType: 'drawer',
				formContext,
				trigger,
			}}
			update={{
				formType: 'drawer',
				formContext,
				trigger,
			}}
			destroy={{}}
			detail={{
				formType: 'drawer',
				columns: detailColumns,
				trigger,
			}}
		/>
	);
}
