'use client';
import { useState } from 'react';
import { useGraphQlUsersList } from '@/pages/users/queries';
import { UserDataTableAdd } from '@/pages/users/add/table/data-table';
import { UserForm } from '@/pages/users/add/form';

const PageAddUser = () => {
    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 } = useGraphQlUsersList({ limit, skip: (page - 1) * limit, sort, filters });

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

export { PageAddUser };
