'use client';

import { useEffect, useState } from 'react';
import ConstructionTestUrlsClient, { UrlCategory } from './ConstructionTestUrlsClient';
import { getConstructionTestUrlsData } from './actions';

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 (
      <div className="flex items-center justify-center min-h-[400px]">
        <div className="text-muted-foreground">로딩 중...</div>
      </div>
    );
  }

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