'use client';
import { useState } from 'react';
import { BuildAddressForm } from '@/pages/build-address/add/form';
import { PeopleDataTableUpdate } from './table/data-table';
import { useGraphQlBuildAddressesList } from '@/pages/build-address/queries';

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

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

export { PageAddBuildAddress };
