'use client';
import { useState } from 'react';
import { useGraphQlPeopleList } from '@/pages/people/queries';
import { PeopleDataTableAdd } from '@/pages/people/add/table/data-table';
import { PeopleForm } from '@/pages/people/add/form';

const PageAddPerson = () => {
    const [page, setPage] = useState(1);
    const [limit, setLimit] = useState(10);
    const [sort, setSort] = useState({ createdAt: 'desc' });
    const [filters, setFilters] = useState({});

    const { data, isLoading, error, refetch } = useGraphQlPeopleList({ limit, skip: (page - 1) * limit, sort, filters });

    return (
        <>
            <PeopleDataTableAdd
                data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit}
                onPageChange={setPage} onPageSizeChange={setLimit} refetchTable={refetch}
            />
            <PeopleForm refetchTable={refetch} />
        </>
    )
}

export { PageAddPerson };
