import { BizValueType } from '@/components';
import BizProvider from '@/components/Biz/BizProvider';
import { formatCurrency } from '@/utils/format';
import { useIntl } from '@@/exports';
import { ArrowDownOutlined, ArrowUpOutlined } from '@ant-design/icons';
import {
	ProColumns,
	ProTable,
	ProTableProps,
} from '@ant-design/pro-components';

type IOrderShipSelectListProps = ProTableProps<
	BusinessAPI.OrderShipVO,
	BusinessAPI.OrderShipPageQry,
	BizValueType
>;

export default function OrderShipSelectList(props: IOrderShipSelectListProps) {
	const intl = useIntl();
	const intlPrefix = 'orderShip';

	const { ...tableProps } = props;
	// 订单列表列定义
	const orderColumns: ProColumns<BusinessAPI.OrderShipVO, BizValueType>[] = [
		{
			title: intl.formatMessage({ id: intlPrefix + '.column.order' }),
			dataIndex: 'orderVO',
			key: 'orderId',
			valueType: 'order',
		},
		{
			title: intl.formatMessage({ id: intlPrefix + '.column.dealer' }),
			dataIndex: 'dealerVO',
			key: 'dealerId',
			valueType: 'dealer',
		},
		{
			title: intl.formatMessage({ id: intlPrefix + '.column.company' }),
			dataIndex: 'companyVO',
			key: 'companyId',
			valueType: 'company',
		},
		{
			title: intl.formatMessage({ id: intlPrefix + '.column.orderSn' }),
			dataIndex: 'orderSn',
			key: 'orderSn',
		},
		{
			title: intl.formatMessage({ id: intlPrefix + '.column.shippingAddress' }),
			dataIndex: 'shippingAddress',
			key: 'shippingAddress',
		},
		{
			title: intl.formatMessage({
				id: intlPrefix + '.column.receivingAddress',
			}),
			dataIndex: 'receivingAddress',
			key: 'receivingAddress',
		},
		{
			title: intl.formatMessage({ id: intlPrefix + '.column.shippingDate' }),
			dataIndex: 'shippingDate',
			key: 'shippingDate',
			valueType: 'date',
		},
		{
			title: intl.formatMessage({
				id: intlPrefix + '.column.estimatedArrivalDate',
			}),
			dataIndex: 'estimatedArrivalDate',
			key: 'estimatedArrivalDate',
			valueType: 'date',
		},
		{
			title: intl.formatMessage({ id: intlPrefix + '.column.watermelonGrade' }),
			dataIndex: 'watermelonGrade',
			key: 'watermelonGrade',
			search: false,
		},
		{
			title: intl.formatMessage({
				id: intlPrefix + '.column.receivableAmount',
			}),
			dataIndex: 'receivableAmount',
			key: 'receivableAmount',
			search: false,
			valueType: 'money',
			render: (_, record) => (
				<span className="text-blue-600 font-medium">
					￥{formatCurrency(record.receivableAmount)}
				</span>
			),
		},
		{
			title: intl.formatMessage({ id: intlPrefix + '.column.adjustedAmount' }),
			dataIndex: 'adjustedAmount',
			key: 'adjustedAmount',
			search: false,
			valueType: 'money',
			render: (_, record) => (
				<span
					className={
						record.adjustedAmount >= 0 ? 'text-green-600' : 'text-red-600'
					}
				>
					{record.adjustedAmount >= 0 ? (
						<ArrowUpOutlined />
					) : (
						<ArrowDownOutlined />
					)}
					<span className="ml-1">
						￥{formatCurrency(Math.abs(record.adjustedAmount))}
					</span>
				</span>
			),
		},
		{
			title: intl.formatMessage({ id: intlPrefix + '.column.type' }),
			dataIndex: 'type',
			key: 'type',
			valueType: 'select',
			valueEnum: {
				PURCHASE_SHIP: intl.formatMessage({
					id: intlPrefix + '.column.type.enum.purchaseShip',
				}),
				TRANSFER_SHIP: intl.formatMessage({
					id: intlPrefix + '.column.type.enum.transferShip',
				}),
				CHANGE_SHIP: intl.formatMessage({
					id: intlPrefix + '.column.type.enum.changeShip',
				}),
				RETURN_SHIP: intl.formatMessage({
					id: intlPrefix + '.column.type.enum.returnShip',
				}),
			},
		},
		{
			title: intl.formatMessage({ id: intlPrefix + '.column.state' }),
			dataIndex: 'state',
			key: 'state',
			valueType: 'select',
			search: false,
			valueEnum: {
				DRAFT: intl.formatMessage({
					id: intlPrefix + '.column.state.enum.draft',
				}),
				WAIT_SHIPMENT: intl.formatMessage({
					id: intlPrefix + '.column.state.enum.waitShipment',
				}),
				WAIT_PAYMENT: intl.formatMessage({
					id: intlPrefix + '.column.state.enum.waitPayment',
				}),
				PARTIAL_PAYMENT: intl.formatMessage({
					id: intlPrefix + '.column.state.enum.partialPayment',
				}),
				FULL_PAYMENT: intl.formatMessage({
					id: intlPrefix + '.column.state.enum.fullPayment',
				}),
				REJECT_FINISH: intl.formatMessage({
					id: intlPrefix + '.column.state.enum.rejectFinish',
				}),
				FINISH: intl.formatMessage({
					id: intlPrefix + '.column.state.enum.finish',
				}),
			},
		},
		...(tableProps.columns || []),
	];

	return (
		<BizProvider>
			<ProTable
				ghost={true}
				search={false}
				options={false}
				{...tableProps}
				rowKey="ordershipId"
				columns={orderColumns}
				pagination={false}
				size="small"
				scroll={{
					x: 'max-content',
				}}
			/>
		</BizProvider>
	);
}
