'use client';

import { useState, useCallback } from 'react';
import { useRouter } from 'next/navigation';
import { AdminDashboardTemplate } from '@/templates/AdminDashboardTemplate';
import { AdminDashboardViewData } from '@/lib/view-data/AdminDashboardViewData';
import { ClientWrapperProps } from '@/lib/contracts/components/ComponentContracts';

export function AdminDashboardWrapper({ viewData }: ClientWrapperProps<AdminDashboardViewData>) {
  const router = useRouter();

  // UI state (not business logic)
  const [loading, setLoading] = useState(false);

  const handleRefresh = useCallback(() => {
    setLoading(true);
    router.refresh();
    // Reset loading after a short delay to show the spinner
    setTimeout(() => setLoading(false), 1000);
  }, [router]);

  return (
    <AdminDashboardTemplate
      viewData={viewData}
      onRefresh={handleRefresh}
      isLoading={loading}
    />
  );
}
