import { useAjax } from "@/Hook/useAjax"
import { Card, Space, Table, Tag } from "antd"
import React, { useEffect, useState } from "react"
import { sendLogTableConfig } from "./momentTableConfig"
import { getSendLogApi } from "@/pages/weComTask/API/businessPlan/create"


interface Props {
    corpMomentId?: number
}
/**
 * 发送记录
 * @returns 
 */
const MomentSendLog: React.FC<Props> = ({ corpMomentId }) => {

    /***************************/
    const [queryForm, setQueryForm] = useState<{ pageSize: number, pageNum: number }>({ pageNum: 1, pageSize: 20 })
    const getSendLog = useAjax((params: any) => getSendLogApi(params))//添加朋友圈
    /***************************/

    useEffect(() => {
        if (corpMomentId) {
            getSendLog.run({ ...queryForm, corpMomentId })
        }
    }, [queryForm, corpMomentId])

    return <div>
        <Space>
            <span>发送记录</span>
            <a onClick={() => getSendLog.refresh()}>刷新</a>
        </Space>
        <Table
            style={{ marginBottom: 1 }}
            dataSource={getSendLog?.data?.data?.records}
            loading={getSendLog?.loading}
            columns={sendLogTableConfig()}
            scroll={{ x: 400, y: 500 }}
            rowKey={(s) => {
                return s.id
            }}
            size='small'
            pagination={{
                total: getSendLog?.data?.data?.total,
                showTotal: (total) => <Tag color="cyan">总共{total}数据</Tag>,
                showSizeChanger: true,
                showLessItems: true,
                defaultCurrent: 1,
                defaultPageSize: 20,//默认初始的每页条数
                current: getSendLog?.data?.data?.current || 1,
                pageSize: getSendLog?.data?.data?.size || 20,
                onChange: (page, pageSize) => {
                    setQueryForm({ ...queryForm, pageNum: page, pageSize })
                }
            }}
        />
    </div>
}

export default React.memo(MomentSendLog)