import {REFRESH_STATE} from "react-native-refresh-flatlist";

const TurnPage = (data, payload, dataList,) => {
    if (payload.page > 1) {
        dataList = dataList.concat(data.rows)
    } else {
        dataList = data.rows
    }

    let RState = 0
    if (data.total > 0) {
        RState = REFRESH_STATE.Idle
        const totalPage = parseInt(data.total/payload.rows) + 1
        if (payload.page === totalPage) {
            RState = REFRESH_STATE.NoMoreData
        }
    } else {
        RState = REFRESH_STATE.Idle
    }

    return {data: dataList, state: RState}
}


export default TurnPage;
