/**
 * Dashboard Page Component
 * @description Main dashboard page with metrics and agent cards
 */

import { useState } from 'react';
import { MetricCard } from '@/components/dashboard/metric-card';
import { AgentCard } from '@/components/dashboard/agent-card';
import { Button } from '@/components/ui/button';
import { Search, Plus } from 'lucide-react';

/**
 * Dashboard component
 * @description Main dashboard page with all sections
 * @returns Dashboard element
 */
export function Dashboard() {
    const [activeTab, setActiveTab] = useState<'all' | 'my'>('all');

    const agents = [
        {
            title: 'Customer Support Agent',
            tags: ['GPT-4', 'Chat Interface'],
            description: 'Automates customer service inquiries with intelligent escalation and context preservation.',
        },
        {
            title: 'Document Analyst',
            tags: ['Claude-3', 'PDF Processing', 'Knowledge Graph'],
            description: 'Analyzes documents to extract insights and generate comprehensive reports automatically.',
        },
        {
            title: 'Sales Qualifier',
            tags: ['Lead Scoring', 'CRM Integration', 'Email Autom...'],
            description: 'Qualifies prospects, schedules meetings, and manages follow-up communications with tracking.',
        },
        {
            title: 'Customer Support Agent',
            tags: ['GPT-4', 'Chat Interface'],
            description: 'Automates customer service inquiries with intelligent escalation and context preservation.',
        },
        {
            title: 'Document Analyst',
            tags: ['Claude-3', 'PDF Processing', 'Knowledge Graph'],
            description: 'Analyzes documents to extract insights and generate comprehensive reports automatically.',
        },
        {
            title: 'Sales Qualifier',
            tags: ['Lead Scoring', 'CRM Integration', 'Email Autom...'],
            description: 'Qualifies prospects, schedules meetings, and manages follow-up communications with tracking.',
        },
    ];

    return (
        <div className="px-8 pt-8">
                    {/* Content Header: Welcome + Search/Create */}
                    <div className="flex flex-col md:flex-row md:items-center justify-between gap-4 mb-8">
                        <div>
                            <h1 className="text-[22px] font-semibold text-gray-900 mb-2">
                                Welcome, Vijay! 👋
                            </h1>
                            <p className="text-gray-500 max-w-2xl text-[16px]">
                                Monitor and manage your intelligent agents, knowledge bases, and automated workflows from a centralized dashboard
                            </p>
                        </div>

                        <div className="flex items-center gap-3">
                            <div className="relative group">
                                <Search className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400 group-focus-within:text-blue-500 transition-colors" />
                                <input
                                    type="text"
                                    placeholder="Search"
                                    className="pl-10 pr-4 py-2.5 bg-white border border-gray-200 rounded-xl text-sm focus:outline-none focus:ring-2 focus:ring-blue-500/20 focus:border-blue-500 w-64 shadow-sm transition-all"
                                />
                            </div>
                            <Button className="bg-[#0033FF] hover:bg-[#0042CC] text-white px-6 py-2.5 rounded-xl font-semibold flex items-center gap-2 shadow-lg shadow-blue-500/20 active:scale-95 transition-all h-auto">
                                <Plus className="w-5 h-5" />
                                Create Agent
                            </Button>
                        </div>
                    </div>

                    {/* Metrics Grid */}
                    <div className="bg-[#F3F8FF]/80 backdrop-blur-sm rounded-[32px] p-6 mb-8 border border-white/40 shadow-sm">
                        <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
                            <MetricCard
                                title="ACTIVE AGENTS"
                                subtitle="Agents"
                                value="03"
                                gradient="blue-teal"
                            />
                            <MetricCard
                                title="KNOWLEDGE BASES"
                                subtitle="Knowledge Bases"
                                value="02"
                                gradient="pink-purple"
                            />
                            <MetricCard
                                title="ACTIVE WORKFLOWS"
                                subtitle="Workflows"
                                value="01"
                                gradient="orange-yellow"
                            />
                            <MetricCard
                                title="CONNECTED TOOLS"
                                subtitle="Tools"
                                value="01"
                                gradient="blue-purple"
                            />
                        </div>
                    </div>

                    {/* Agents Section */}
                    <div className="bg-white rounded-2xl shadow-sm border border-gray-200 p-6">
                        {/* Tabs */}
                        <div className="flex gap-4 mb-6">
                            <button
                                onClick={() => setActiveTab('all')}
                                className={`px-6 py-2 rounded-lg text font-medium transition-colors ${activeTab === 'all'
                                    ? 'bg-black text-white'
                                    : 'bg-white text-gray-600 border border-gray-300 hover:bg-gray-50'
                                    }`}
                            >
                                All Agents
                            </button>
                            <button
                                onClick={() => setActiveTab('my')}
                                className={`px-6 py-2 rounded-lg font-medium transition-colors ${activeTab === 'my'
                                    ? 'bg-black text-white'
                                    : 'bg-white text-gray-600 border border-gray-300 hover:bg-gray-50'
                                    }`}
                            >
                                My Agents
                            </button>
                        </div>

                        {/* Agent Cards Grid */}
                        <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
                            {agents.map((agent, index) => (
                                <AgentCard
                                    key={index}
                                    title={agent.title}
                                    tags={agent.tags}
                                    description={agent.description}
                                />
                            ))}
                        </div>
                    </div>
        </div>
    );
}
