import { Button, Card, Flex } from 'antd'
import { ReactNode } from 'react'
import AppList, { AppListProps } from '@/components/AppList'
import { getChartList } from '@/api/base'

export default function DataWrap({ title, buttons }: { title: string; buttons: ReactNode; children?: ReactNode }) {
  const listOptions: AppListProps = {
    fetchApi: async (params) => {
      const { data } = await getChartList(params)
      return { ...data }
    },
    columns: [
      {
        title: '序号',
        key: 'index',
        render(_value, _record, index) {
          return index + 1
        },
        width: 62,
        align: 'center',
      },
      { title: '组件类型', dataIndex: 'type', align: 'center' },
      { title: '组件名称', dataIndex: 'name', align: 'center' },
      { title: '创建人', dataIndex: 'create_user', align: 'center' },
      { title: '创建时间', dataIndex: 'create_time', align: 'center' },
      { title: '更新时间', dataIndex: 'update_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">
                删除
              </Button>
            </>
          )
        },
      },
    ],
  }
  return (
    <Flex gap={20} style={{ height: '100%' }}>
      <Card className="app-card" title={title} style={{ flex: 1, overflowX: 'hidden' }}>
        <Flex justify="space-between" style={{ marginBottom: '20px' }}>
          <Flex wrap gap={10}>
            {buttons}
          </Flex>
          <Button>查看我的数据集</Button>
        </Flex>
        <AppList {...listOptions} />
      </Card>
    </Flex>
  )
}
