"use client";
import { jsx, jsxs } from 'react/jsx-runtime';
import { memo } from 'react';
import { GripVertical } from 'lucide-react';
import { Button } from '../../../../../../../ui/src/components/button.mjs';
import { Badge } from '../../../../../../../ui/src/components/badge.mjs';
import { KanbanItem, KanbanItemHandle } from '../../../../../../../ui/src/components/kanban.mjs';
import { format } from 'date-fns';
import { getPriorityConfig } from '../../../utils.mjs';
import { useResolveUser } from '../../hooks/kanban-hooks.mjs';
import { UserAvatar } from './user-avatar.mjs';

function TaskCardComponent({ task, onClick }) {
  const priorityConfig = getPriorityConfig(task.priority);
  const { data: assignee } = useResolveUser(task.assigneeId);
  return /* @__PURE__ */ jsx(KanbanItem, { value: task.id, asChild: true, children: /* @__PURE__ */ jsx(
    "div",
    {
      className: "rounded-md border bg-card p-3 shadow-xs cursor-pointer hover:shadow-md transition-shadow",
      onClick,
      children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
        /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
          /* @__PURE__ */ jsx(KanbanItemHandle, { asChild: true, children: /* @__PURE__ */ jsx(
            Button,
            {
              variant: "ghost",
              size: "icon",
              className: "h-6 w-6",
              onClick: (e) => e.stopPropagation(),
              children: /* @__PURE__ */ jsx(GripVertical, { className: "h-3 w-3" })
            }
          ) }),
          /* @__PURE__ */ jsx(
            "span",
            {
              className: "line-clamp-1 font-medium text-base flex-1 text-left cursor-pointer hover:text-primary",
              title: task.title,
              children: task.title
            }
          ),
          /* @__PURE__ */ jsx(
            Badge,
            {
              variant: priorityConfig.variant,
              className: `pointer-events-none h-5 rounded-sm px-1.5 text-[11px] capitalize ${priorityConfig.className}`,
              children: priorityConfig.label
            }
          )
        ] }),
        /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between text-muted-foreground text-xs", children: [
          task.assigneeId ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
            /* @__PURE__ */ jsx(UserAvatar, { user: assignee ?? null, size: "sm" }),
            /* @__PURE__ */ jsx("span", { className: "line-clamp-1", children: assignee?.name || "Assigned" })
          ] }) : /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
            /* @__PURE__ */ jsx(UserAvatar, { user: null, size: "sm" }),
            /* @__PURE__ */ jsx("span", { className: "line-clamp-1", children: "Unassigned" })
          ] }),
          /* @__PURE__ */ jsx("time", { className: "tabular-nums", children: format(new Date(task.createdAt), "MMM d") })
        ] })
      ] })
    }
  ) });
}
const TaskCard = memo(TaskCardComponent);

export { TaskCard };
