import { Button, message, Spin } from 'antd';
import React, { useMemo } from 'react';
import { Column, ColumnConfig } from '@ant-design/charts';
import { SyncOutlined } from '@ant-design/icons';
import { DateFilter } from '../DateFilter';
import {
StatsItemType,
useWorkspaceWebsitePageview,
useWorkspaceWebsiteStats,
WebsiteInfo,
} from '../../api/model/website';
import {
DateUnit,
formatDate,
formatDateWithUnit,
getDateArray,
} from '../../utils/date';
import { useEvent } from '../../hooks/useEvent';
import { MetricCard } from '../MetricCard';
import { formatNumber, formatShortTime } from '../../utils/common';
import { useTheme } from '../../hooks/useTheme';
import { WebsiteOnlineCount } from '../WebsiteOnlineCount';
import { useGlobalRangeDate } from '../../hooks/useGlobalRangeDate';
import { MonitorHealthBar } from '../monitor/MonitorHealthBar';
import { useNavigate } from 'react-router';
export const WebsiteOverview: React.FC<{
website: WebsiteInfo;
showDateFilter?: boolean;
actions?: React.ReactNode;
}> = React.memo((props) => {
const { website, showDateFilter = false, actions } = props;
const { startDate, endDate, unit, refresh } = useGlobalRangeDate();
const navigate = useNavigate();
const {
pageviews,
sessions,
isLoading: isLoadingPageview,
refetch: refetchPageview,
} = useWorkspaceWebsitePageview(
website.workspaceId,
website.id,
startDate.unix() * 1000,
endDate.unix() * 1000,
unit
);
const {
stats,
isLoading: isLoadingStats,
refetch: refetchStats,
} = useWorkspaceWebsiteStats(
website.workspaceId,
website.id,
startDate.unix() * 1000,
endDate.unix() * 1000,
unit
);
const handleRefresh = useEvent(async () => {
refresh();
await Promise.all([refetchPageview(), refetchStats()]);
message.success('Refreshed');
});
const chartData = useMemo(() => {
const pageviewsArr = getDateArray(pageviews, startDate, endDate, unit);
const sessionsArr = getDateArray(sessions, startDate, endDate, unit);
return [
...pageviewsArr.map((item) => ({ ...item, type: 'pageview' })),
...sessionsArr.map((item) => ({ ...item, type: 'session' })),
];
}, [pageviews, sessions, unit]);
const loading = isLoadingPageview || isLoadingStats;
return (