'use client';

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

interface AdminDashboardWrapperProps {
  initialViewData: AdminDashboardViewData;
}

export function AdminDashboardWrapper({ initialViewData }: AdminDashboardWrapperProps) {
  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
      adminDashboardViewData={initialViewData}
      onRefresh={handleRefresh}
      isLoading={loading}
    />
  );
}