"use client";

/**
 * 로그 노드 - 디버깅 및 모니터링용
 */

import { memo } from "react";
import { Handle, Position, NodeProps } from "reactflow";
import { FileText, AlertCircle, Info, AlertTriangle } from "lucide-react";
import type { LogNodeData } from "@/types/node-editor";

const LOG_LEVEL_CONFIG = {
  debug: { icon: Info, color: "text-primary", bg: "bg-primary/10", border: "border-primary/20" },
  info: { icon: Info, color: "text-emerald-600", bg: "bg-emerald-50", border: "border-emerald-200" },
  warn: { icon: AlertTriangle, color: "text-amber-600", bg: "bg-amber-50", border: "border-amber-200" },
  error: { icon: AlertCircle, color: "text-destructive", bg: "bg-destructive/10", border: "border-destructive/20" },
};

export const LogNode = memo(({ data, selected }: NodeProps<LogNodeData>) => {
  const config = LOG_LEVEL_CONFIG[data.level] || LOG_LEVEL_CONFIG.info;
  const Icon = config.icon;

  return (
    <div
      className={`min-w-[200px] rounded-lg border-2 bg-white shadow-sm transition-all ${
        selected ? `${config.border} shadow-md` : "border-border"
      }`}
    >
      {/* 헤더 */}
      <div className={`flex items-center gap-2 rounded-t-lg ${config.bg} px-3 py-2`}>
        <FileText className={`h-4 w-4 ${config.color}`} />
        <div className="flex-1">
          <div className={`text-sm font-semibold ${config.color}`}>로그</div>
          <div className="text-xs text-muted-foreground">{data.level.toUpperCase()}</div>
        </div>
        <Icon className={`h-4 w-4 ${config.color}`} />
      </div>

      {/* 본문 */}
      <div className="p-3">
        {data.message ? (
          <div className="text-sm text-foreground">{data.message}</div>
        ) : (
          <div className="text-sm text-muted-foreground/70">로그 메시지 없음</div>
        )}

        {data.includeData && (
          <div className="mt-2 rounded bg-muted px-2 py-1 text-xs text-muted-foreground">✓ 데이터 포함</div>
        )}
      </div>

      {/* 핸들 */}
      <Handle type="target" position={Position.Left} className="!h-3 !w-3 !bg-muted-foreground" />
      <Handle type="source" position={Position.Right} className="!h-3 !w-3 !bg-muted-foreground" />
    </div>
  );
});

LogNode.displayName = "LogNode";
