import { Pagination, States, StatesIcon, StatesActions, StatesAction, StatesTitle } from '@rocket.chat/fuselage';
import { useDebouncedValue } from '@rocket.chat/fuselage-hooks';
import {
GenericTable,
GenericTableBody,
GenericTableHeaderCell,
GenericTableHeader,
GenericTableLoadingRow,
usePagination,
} from '@rocket.chat/ui-client';
import { useTranslation, useEndpoint } from '@rocket.chat/ui-contexts';
import { useQuery } from '@tanstack/react-query';
import { useMemo, useState } from 'react';
import BusinessHoursRow from './BusinessHoursRow';
import FilterByText from '../../../components/FilterByText';
import GenericNoResults from '../../../components/GenericNoResults';
const BusinessHoursTable = () => {
const t = useTranslation();
const [text, setText] = useState('');
const { current, itemsPerPage, setItemsPerPage: onSetItemsPerPage, setCurrent: onSetCurrent, ...paginationProps } = usePagination();
const query = useDebouncedValue(
useMemo(
() => ({
name: text,
...(itemsPerPage && { count: itemsPerPage }),
...(current && { offset: current }),
}),
[text, itemsPerPage, current],
),
500,
);
const getBusinessHours = useEndpoint('GET', '/v1/livechat/business-hours');
const { data, isLoading, isSuccess, isError, refetch } = useQuery({
queryKey: ['livechat-getBusinessHours', query],
queryFn: async () => getBusinessHours(query),
});
const headers = (
<>
{t('Name')}
{t('Timezone')}
{t('Open_Days')}
{t('Enabled')}
{t('Remove')}
>
);
return (
<>
setText(event.target.value)} />
{isLoading && (
{headers}
)}
{isSuccess && data?.businessHours.length === 0 && }
{isSuccess && data?.businessHours.length > 0 && (
<>
{headers}
{data?.businessHours.map((businessHour) => (
))}
>
)}
{isError && (
{t('Something_went_wrong')}
refetch()}>{t('Reload_page')}
)}
>
);
};
export default BusinessHoursTable;