/*
 * Copyright OpenSearch Contributors
 * SPDX-License-Identifier: Apache-2.0
 */

import React, { useCallback } from 'react';
import { AGENT_NODE_KINDS } from '../../shared/constants/agent.constants';
import { getProviderIcon } from '../../shared/constants/provider_icons.constants';
import { useCelestialNodeActionsContext } from '../../shared/contexts/node_actions_context';
import { NodeShell } from './node_shell';
import { TypeBadge } from './type_badge';
import { MetricBar, MetricBarGroup } from './metric_bar';
import { StatusIndicator } from './status_indicator';
import './agent_card_node.scss';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
/**
 * Agent/LLM/Tool card node.
 * Renders a type badge, title, duration bar, latency, and status icon.
 */
export const AgentCardNode = _ref => {
  var _AGENT_NODE_KINDS$dat, _data$latency;
  let data = _ref.data;
  const kindConfig = (_AGENT_NODE_KINDS$dat = AGENT_NODE_KINDS[data.nodeKind]) !== null && _AGENT_NODE_KINDS$dat !== void 0 ? _AGENT_NODE_KINDS$dat : AGENT_NODE_KINDS.agent;
  const _useCelestialNodeActi = useCelestialNodeActionsContext(),
    onDashboardClick = _useCelestialNodeActi.onDashboardClick,
    selectedNodeId = _useCelestialNodeActi.selectedNodeId;
  const isSelected = data.id === selectedNodeId;
  const handleClick = useCallback(event => {
    onDashboardClick === null || onDashboardClick === void 0 || onDashboardClick(event, data);
  }, [onDashboardClick, data]);
  const providerIconSrc = getProviderIcon(data.provider);

  // When metrics array is provided, skip the standalone duration bar to avoid duplication
  const showStandaloneDuration = data.duration !== undefined && (!data.metrics || data.metrics.length === 0);
  return /*#__PURE__*/_jsx(NodeShell, {
    borderColor: kindConfig.color,
    glowColor: kindConfig.color,
    isSelected: isSelected,
    isFaded: !!data.isFaded,
    onClick: handleClick,
    className: "osd:bg-container-default osd:w-68 osd:min-h-20 osd:p-3",
    "data-test-subj": "agentCardNode-".concat(data.id),
    children: /*#__PURE__*/_jsxs("div", {
      className: "osd:flex osd:flex-col osd:gap-2",
      children: [/*#__PURE__*/_jsxs("div", {
        className: "osd:flex osd:items-center osd:justify-between",
        children: [/*#__PURE__*/_jsx(TypeBadge, {
          label: kindConfig.label,
          color: kindConfig.color,
          textColor: kindConfig.textColor
        }), data.status && /*#__PURE__*/_jsx(StatusIndicator, {
          status: data.status,
          label: data.statusLabel,
          icon: data.statusIcon
        })]
      }), /*#__PURE__*/_jsx("div", {
        className: "osd:font-bold osd:text-sm osd:text-body-default osd:truncate",
        children: data.title
      }), data.model && /*#__PURE__*/_jsxs("div", {
        className: "osd:flex osd:items-center osd:gap-1 osd:text-xs osd:text-body-secondary osd:truncate",
        children: [providerIconSrc && /*#__PURE__*/_jsx("img", {
          src: providerIconSrc,
          alt: "",
          className: "osd:w-4 osd:h-4 osd:flex-shrink-0 celAgentCard__provider-icon"
        }), data.model]
      }), showStandaloneDuration && /*#__PURE__*/_jsx(MetricBar, {
        value: data.duration,
        max: data.duration * 2,
        color: kindConfig.color,
        label: (_data$latency = data.latency) !== null && _data$latency !== void 0 ? _data$latency : "".concat(data.duration, "ms")
      }), data.metrics && data.metrics.length > 0 && /*#__PURE__*/_jsx(MetricBarGroup, {
        metrics: data.metrics
      })]
    })
  });
};