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

export interface CountersignType {
  changeTime: number;
  changeType: string;
  countersignType: number;
  changeUser: API.User;
  countersignUser: API.User[];
}

export interface CountersignProps {
  users?: CountersignType[];
}

const Countersign = (props: CountersignProps) => {
  const { users } = props;
  const { formatMessage } = useIntl();

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

  const columns = [
    {
      title: formatMessage({ id: 'component.AuditCountersign.col.changeUser' }),
      dataIndex: 'changeUser',
      render: (__: any, record: CountersignType) => <UserLink user={record.changeUser} />,
    },
    {
      title: formatMessage({ id: 'component.AuditCountersign.col.countersignType' }),
      dataIndex: 'countersignType',
      render: (__: any, record: CountersignType) =>
        formatMessage({
          id: `component.AuditCountersign.countersignType.${record.countersignType}`,
        }),
    },
    {
      title: formatMessage({ id: 'component.AuditCountersign.col.changeTime' }),
      dataIndex: 'changeTime',
      render: (__: any, record: CountersignType) =>
        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 Countersign;
