// app/(admin)/owner-companies/_components/owner-company-user-list.tsx
"use client";

import { Button } from "@/components/ui/button";
import {
  Table,
  TableBody,
  TableCell,
  TableHead,
  TableHeader,
  TableRow,
} from "@/components/ui/table";
import { Badge } from "@/components/ui/badge";
import { UserPlus } from "lucide-react";
import Link from "next/link";

interface User {
  id: number;
  name: string;
  email: string;
  phone: string | null;
  isActive: boolean;
  createdAt: Date;
  employeeNumber: string | null;
}

interface OwnerCompanyUserListProps {
  users: User[];
  companyId: number;
}

export function OwnerCompanyUserList({
  users,
  companyId,
}: OwnerCompanyUserListProps) {
  if (users.length === 0) {
    return (
      <div className="text-center py-12 border rounded-lg">
        <UserPlus className="mx-auto h-12 w-12 text-muted-foreground" />
        <h3 className="mt-4 text-lg font-semibold">등록된 사용자가 없습니다</h3>
        <p className="mt-2 text-sm text-muted-foreground">
          첫 번째 사용자를 추가해보세요.
        </p>
        <Button asChild className="mt-4">
          <Link href={`/evcp/data-room/owner-companies/${companyId}/users/new`}>
            사용자 추가
          </Link>
        </Button>
      </div>
    );
  }

  return (
    <Table>
      <TableHeader>
        <TableRow>
          <TableHead>이름</TableHead>
          <TableHead>이메일</TableHead>
          <TableHead>전화번호</TableHead>
          <TableHead>사번</TableHead>
          <TableHead>상태</TableHead>
          <TableHead>등록일</TableHead>
        </TableRow>
      </TableHeader>
      <TableBody>
        {users.map((user) => (
          <TableRow key={user.id}>
            <TableCell className="font-medium">{user.name}</TableCell>
            <TableCell>{user.email}</TableCell>
            <TableCell>{user.phone || "-"}</TableCell>
            <TableCell>{user.employeeNumber || "-"}</TableCell>
            <TableCell>
              {user.isActive ? (
                <Badge variant="default" className="bg-green-500">
                  활성
                </Badge>
              ) : (
                <Badge variant="destructive">비활성</Badge>
              )}
            </TableCell>
            <TableCell>
              {new Date(user.createdAt).toLocaleDateString("ko-KR", {
                year: "numeric",
                month: "2-digit",
                day: "2-digit",
              })}
            </TableCell>
          </TableRow>
        ))}
      </TableBody>
    </Table>
  );
}