import { useRef } from 'react'
import { Button, Flex, Space, Dropdown } from 'antd'

import ReloadIcon from '../../Icons/ReloadIcon'
import useColumnVisibility from '../hooks/useColumnVisibility'
import ObjectTable from '../common/ObjectTable'
import ColumnViewButton from '../common/ColumnViewButton'

const AuditLogs = () => {
  const tableRef = useRef()

  const [columnVisibility, updateColumnVisibility] =
    useColumnVisibility('auditLogs')

  const actionItems = {
    items: [
      {
        label: 'Reload List',
        key: 'reloadList',
        icon: <ReloadIcon />
      }
    ],
    onClick: ({ key }) => {
      if (key === 'reloadList') {
        tableRef.current?.reload()
      }
    }
  }

  return (
    <>
      <Flex vertical={'true'} gap='large'>
        <Flex justify={'space-between'}>
          <Space size='small'>
            <Dropdown menu={actionItems}>
              <Button>Actions</Button>
            </Dropdown>
            <ColumnViewButton
              type='auditLog'
              loading={false}
              visibleState={columnVisibility}
              updateVisibleState={updateColumnVisibility}
            />
          </Space>
        </Flex>

        <ObjectTable
          ref={tableRef}
          visibleColumns={columnVisibility}
          type='auditLog'
        />
      </Flex>
    </>
  )
}

export default AuditLogs
