'use client';

import { useState } from 'react';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { Button } from '@/components/ui/button';
import { Database, Table2, Users, Ticket, CheckSquare, FolderKanban, Wrench, Tag, ArrowLeft, Home, Clock, MessageSquare } from 'lucide-react';
import Link from 'next/link';

const entities = [
  { name: 'Companies', icon: Users, path: '/admin/data-browser/companies', description: 'View all companies' },
  { name: 'Tickets', icon: Ticket, path: '/admin/data-browser/tickets', description: 'Browse support tickets' },
  { name: 'Tasks', icon: CheckSquare, path: '/admin/data-browser/tasks', description: 'View all tasks' },
  { name: 'Projects', icon: FolderKanban, path: '/admin/data-browser/projects', description: 'Browse projects' },
  { name: 'Time Entries', icon: Clock, path: '/admin/data-browser/time-entries', description: 'View time tracking data' },
  { name: 'Resources', icon: Users, path: '/admin/data-browser/resources', description: 'View resources/users' },
  { name: 'Configuration Items', icon: Wrench, path: '/admin/data-browser/configuration-items', description: 'Browse config items' },
  { name: 'Contacts', icon: Users, path: '/admin/data-browser/contacts', description: 'View contacts' },
  { name: 'Contracts', icon: Table2, path: '/admin/data-browser/contracts', description: 'Browse contracts' },
  { name: 'Ticket Notes', icon: MessageSquare, path: '/admin/data-browser/ticket-notes', description: 'Browse notes on tickets' },
  { name: 'Issue Types', icon: Tag, path: '/admin/data-browser/issue-types', description: 'Browse issue types' },
  { name: 'Sub-Issue Types', icon: Tag, path: '/admin/data-browser/sub-issue-types', description: 'Browse sub-issue types' },
];

export default function DataBrowserPage() {
  return (
    <div className="container mx-auto p-6 space-y-6">
      <div className="flex items-center gap-4">
        <Link href="/">
          <Button variant="outline" size="sm" className="gap-2">
            <ArrowLeft className="w-4 h-4" />
            <Home className="w-4 h-4" />
            <span className="hidden sm:inline">Back to Dashboard</span>
          </Button>
        </Link>
        <Database className="w-8 h-8" />
        <div>
          <h1 className="text-3xl font-bold">Database Browser</h1>
          <p className="text-muted-foreground">Inspect synced data from PostgreSQL</p>
        </div>
      </div>

      <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4">
        {entities.map((entity) => {
          const Icon = entity.icon;
          return (
            <Link key={entity.name} href={entity.path}>
              <Card className="hover:bg-accent transition-colors cursor-pointer h-full">
                <CardHeader>
                  <div className="flex items-center gap-2">
                    <Icon className="w-5 h-5" />
                    <CardTitle className="text-lg">{entity.name}</CardTitle>
                  </div>
                  <CardDescription>{entity.description}</CardDescription>
                </CardHeader>
              </Card>
            </Link>
          );
        })}
      </div>
    </div>
  );
}
