import { Table } from 'antd';
import moment from 'moment';
import { useIntl } from 'umi';
import UserLink from '../UserInfo/link';

export interface PassOnType {
  changeTime: number;
  changeType: string;
  changeUser: API.User;
  reassignUser: API.User;
}

export interface PassOnProps {
  users: PassOnType[];
}

const PassOn = (props: PassOnProps) => {
  const { users } = props;
  const { formatMessage } = useIntl();

  if (!Array.isArray(users)) return <></>;

  const columns = [
    {
      title: formatMessage({ id: 'component.AuditPassOn.col.changeUser' }),
      dataIndex: 'changeUser',
      render: (__: any, record: PassOnType) => <UserLink user={record.changeUser} />,
    },
    {
      title: formatMessage({ id: 'component.AuditPassOn.col.reassignUser' }),
      dataIndex: 'reassignUser',
      render: (__: any, record: PassOnType) => <UserLink user={record.reassignUser} />,
    },
    {
      title: formatMessage({ id: 'component.AuditPassOn.col.changeTime' }),
      dataIndex: 'changeTime',
      render: (__: any, record: PassOnType) =>
        record.changeTime ? moment(record.changeTime * 1000).format('YYYY-MM-DD HH:mm:ss') : '',
    },
  ];

  return <Table dataSource={users} columns={columns} pagination={false} style={{ width: 500 }} />;
};

export default PassOn;
