import { Button, Card, Flex } from 'antd'
import AppList, { AppListProps } from '@/components/AppList'
import ViewDataButtonModal from '@/components/data/ViewMyDataButtonModal'
import ButtonModal from '../components/ButtonModal'
import { getLargeScreenList } from '../api'
import { useDeleteLargeScreen } from '../query'

export default function DataWrap() {
  const { mutate } = useDeleteLargeScreen()
  const handleRemove = (record: any) => {
    mutate({ id: record.id })
  }

  const listOptions: AppListProps = {
    queryKey: ['largeScreenList'],
    fetchApi: async (params) => {
      const { data } = await getLargeScreenList(params)
      return { ...data }
    },
    columns: [
      {
        title: '序号',
        key: 'index',
        render(_value, _record, index) {
          return index + 1
        },
        width: 62,
        align: 'center',
      },
      { title: '名称', dataIndex: 'name', align: 'center' },
      { title: '创建人', dataIndex: 'created_operator_name', align: 'center' },
      { title: '创建时间', dataIndex: 'created_time', align: 'center' },
      { title: '更新时间', dataIndex: 'updated_time', align: 'center' },
      {
        title: '操作',
        key: 'x',
        width: 220,
        align: 'center',
        render(_value, record) {
          return (
            <>
              <Button color="primary" variant="text">
                查看
              </Button>
              <Button color="primary" variant="text">
                编辑
              </Button>
              <Button color="danger" variant="text" onClick={() => handleRemove(record)}>
                删除
              </Button>
            </>
          )
        },
      },
    ],
  }
  return (
    <Flex gap={20} style={{ height: '100%' }}>
      <Card className="app-card" style={{ flex: 1, overflowX: 'hidden' }}>
        <Flex justify="space-between" style={{ marginBottom: '20px' }}>
          <Flex wrap gap={10}>
            <ButtonModal></ButtonModal>
          </Flex>
          <ViewDataButtonModal></ViewDataButtonModal>
        </Flex>
        <AppList {...listOptions} />
      </Card>
    </Flex>
  )
}
