"use client";
import { betRecordApi, RecordBillsResp } from "@/api/betrecord";
import { Pagination } from "@/types";
import { useSetState } from "ahooks";
import { InfiniteScroll } from "antd-mobile";
import { useRef } from "react";
import Message from "./components/list";

const Bets = () => {
    const params = useRef({ current_page: 0, page_size: 20, use_page: true });
    const [sourceData, setSourceData] = useSetState<{
        list: RecordBillsResp[];
        page: Partial<Pagination>;
    }>({ list: [], page: { is_end: false } });

    const getBetRecordData = async () => {
        return betRecordApi(params.current).then((res) => {
            setSourceData((value) => ({ page: res.page, list: [...value.list, ...res.data] }));
            return res;
        });
    };
    const loadMore = async () => {
        params.current.current_page += 1;
        await getBetRecordData();
        console.log(`🚀🚀🚀🚀🚀-> in page.tsx on 25`, sourceData);
    };
    return (
        <>
            <Message record={sourceData.list} />
            <InfiniteScroll loadMore={loadMore} hasMore={!sourceData.page.is_end!} />
        </>
    );
};

export default Bets;
