'use client';

import { useSession } from 'next-auth/react';
import { signIn } from 'next-auth/react';

import { OptimizationEngine } from '@/components/ai/OptimizationEngine';
import { DataPipelineTile } from '@/components/dashboard/DataPipelineTile';
import { IntegrationStatusTile } from '@/components/dashboard/IntegrationStatusTile';
import { QuickActionsPanel } from '@/components/dashboard/QuickActionsPanel';
import { ResourceUtilizationTile } from '@/components/dashboard/ResourceUtilizationTile';
import { SystemHealthTile } from '@/components/dashboard/SystemHealthTile';

export default function TechnicalDashboardPage() {
  const { status } = useSession();

  if (status === 'loading') {
    return (
      <div className="flex min-h-screen items-center justify-center bg-gray-900">
        <div className="text-center">
          <div className="mb-4 h-8 w-8 animate-spin rounded-full border-4 border-gray-300 border-t-blue-600 mx-auto"></div>
          <p className="text-gray-400">Loading...</p>
        </div>
      </div>
    );
  }

  if (status === 'unauthenticated') {
    return (
      <div className="flex min-h-screen items-center justify-center bg-gray-900">
        <div className="text-center max-w-md mx-auto p-8">
          <h1 className="text-2xl font-bold text-white mb-4">Welcome to Nexus Console</h1>
          <p className="text-gray-400 mb-6">Please sign in to continue</p>
          <button
            onClick={() => signIn()}
            className="px-6 py-3 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors"
          >
            Sign In
          </button>
        </div>
      </div>
    );
  }

  return (
    <div className="container mx-auto px-4 py-8">
      <div className="mb-6">
        <h1 className="text-3xl font-bold text-white">Technical Admin Dashboard</h1>
        <p className="text-gray-400 mt-2">Operational view of infrastructure, integrations, and system health</p>
      </div>
      
      <div className="grid grid-cols-1 lg:grid-cols-3 gap-6 mb-6">
        <div className="lg:col-span-2">
          <SystemHealthTile />
        </div>
        <div>
          <IntegrationStatusTile />
        </div>
      </div>

      <div className="grid grid-cols-1 lg:grid-cols-2 gap-6 mb-6">
        <DataPipelineTile />
        <ResourceUtilizationTile />
      </div>

      <div className="mb-6">
        <OptimizationEngine />
      </div>

      <QuickActionsPanel 
        actions={[
          { label: 'Add Integration', href: '/integrations/new', icon: 'Plus' },
          { label: 'Create Connection', href: '/connections/new', icon: 'Link' },
          { label: 'View Logs', href: '/monitoring/logs', icon: 'FileText' },
          { label: 'System Settings', href: '/settings/system', icon: 'Settings' },
        ]}
      />
    </div>
  );
}

