import Dashboard from "@/components/dashboard/dashboard";
import Content from "@/components/dashboard/content";
import { fetchServer } from '@/lib/server-service';
import { performance } from 'perf_hooks';
import { Info } from 'lucide-react';
import packageJson from '../../package.json';

// ✅ Corrected Vendor Type
interface Vendor {
  _id: string;
  username: string;
  storeId: string;
  pgpKey: string;
  __v: number;
}

interface User {
  vendor: Vendor;
}

interface OrderStats {
  totalOrders: number;
  pendingOrders: number;
  completedOrders: number;
  cancelledOrders: number;
}

export default async function DashboardPage() {
  const startTime = performance.now();

  const [userResponse, orderStats] = await Promise.all([
    fetchServer<User>("/auth/me"),
    fetchServer<OrderStats>("/orders/stats"),
  ]);

  const endTime = performance.now();
  const generationTime = (endTime - startTime).toFixed(2);
  const panelVersion = packageJson.version;

  const vendor = userResponse.vendor; 

  return (
    <Dashboard>
      <Content username={vendor.username} orderStats={orderStats} />
      <div className="fixed bottom-2 right-2 text-xs text-muted-foreground bg-background/80 backdrop-blur-sm px-2 py-1 rounded border border-border/50 z-50 flex items-center gap-1.5">
        <Info size={12} className="text-muted-foreground/80" /> 
        <span>v{panelVersion}</span>
        <span className="text-muted-foreground/50">|</span>
        <span>Generated in {generationTime}ms</span>
      </div>
    </Dashboard>
  );
}