'use client';
import { useState } from 'react';
import { useGraphQlBuildTypesList } from '@/pages/build-types/queries';
import { BuildTypesForm } from './form';
import { BuildTypesDataTableAdd } from './table/data-table';

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

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

export { PageAddBuildTypes };
