import React, { useMemo } from 'react';
import { Lightbulb } from 'lucide-react-native';

import type { SuperagentToolRendererProps } from '../../types';
import { ToolWidgetRow } from '../primitives/ToolWidgetRow';
import { getActivatePlatformSkillTitle, getFailureReason } from '../skillsAndConnectionsUtils';
import { getSettledWidgetStatus, getStringArg, parseToolArgs } from '../toolWidgetUtils';

// activate_platform_skill — superagent-only; mirrors the web SkillToolUI's
// skill-name chip + status (the builder's activate_* variants). Settled
// status keeps stale rows on old turns from spinning forever; stopped renders
// as an error row so it never reads as completed.
export function ActivatePlatformSkillWidget({ isLastAssistantMessage, toolCall }: SuperagentToolRendererProps) {
  const args = useMemo(() => parseToolArgs(toolCall), [toolCall]);
  const status = getSettledWidgetStatus(toolCall, isLastAssistantMessage);
  const skillName = getStringArg(args, ['skill_name']);
  const title = getActivatePlatformSkillTitle(status);

  return (
    <ToolWidgetRow
      chipText={skillName || null}
      failureText={getFailureReason(status, toolCall)}
      icon={Lightbulb}
      status={status === 'stopped' ? 'error' : status}
      title={title}
    />
  );
}
