'use client';

import { useEffect, useState } from 'react';
import ConstructionTestUrlsClient, { UrlCategory } from './ConstructionTestUrlsClient';
import { getConstructionTestUrlsData } from './actions';
import { GenericPageSkeleton } from '@/components/ui/skeleton';

export default function TestUrlsPage() {
  const [urlData, setUrlData] = useState<UrlCategory[]>([]);
  const [lastUpdated, setLastUpdated] = useState('N/A');
  const [isLoading, setIsLoading] = useState(true);

  useEffect(() => {
    getConstructionTestUrlsData()
      .then(result => {
        setUrlData(result.categories);
        setLastUpdated(result.lastUpdated);
      })
      .finally(() => setIsLoading(false));
  }, []);

  if (isLoading) return <GenericPageSkeleton />;

  return <ConstructionTestUrlsClient initialData={urlData} lastUpdated={lastUpdated} />;
}