import React, { useCallback, useEffect, useState } from 'react'
import styles from './index.module.scss'
import { Button, Modal } from 'antd'
import MyTable from '@/components/MyTable'
import { API_getFileLog } from '@/store/action/Cledger/C4file'

type listType = {
  createTime: string
  creatorId: number
  creatorName: string
  fileId: number
  id: number
  updateTime: string
}

type Props = {
  id: number
  closeFu: () => void
}

function DownLog({ closeFu, id }: Props) {
  const [list, setList] = useState<listType[]>([])

  const getList = useCallback(async () => {
    const res = await API_getFileLog(id)
    if (res.code === 0) {
      setList(res.data || [])
    }
  }, [id])

  useEffect(() => {
    getList()
  }, [getList])

  return (
    <Modal wrapClassName={styles.DownLog} title='下载记录' open={true} footer={[]}>
      <MyTable
        yHeight={500}
        classKey='DownLog'
        list={list}
        columnsTemp={[
          ['txt', '下载人员', 'creatorName'],
          ['txt', '下载时间', 'createTime']
        ]}
        pagingInfo={false}
      />

      <div className='DownLogBtn'>
        <Button onClick={closeFu}>关闭</Button>
      </div>
    </Modal>
  )
}

const MemoDownLog = React.memo(DownLog)

export default MemoDownLog
