import { CheckCircleIcon } from "lucide-react";
import { useTranslation } from "react-i18next";
import { TABS_TASK_NAMESPACE } from "@/i18n/resources";
import type { ExecutionControlFinishTask } from "@/api/generated/schemas";
import { FinishTaskSchema } from "@/api/tool-schema";
import { Markdown } from "@/components/custom/Markdown";
import type { ToolMessageProps } from ".";
import {
  BuiltInToolContainer,
  BuiltInToolContent,
  BuiltInToolHeader,
} from "./components/BuiltInTool";
import { useToolArgument } from "../../../hooks/use-tool-argument";

export function FinishTask({ message }: ToolMessageProps) {
  const { t } = useTranslation(TABS_TASK_NAMESPACE);
  const toolArguments = useToolArgument<ExecutionControlFinishTask>(
    message,
    FinishTaskSchema,
  );

  return (
    <BuiltInToolContainer id={message.call_id} defaultOpen>
      <BuiltInToolHeader
        title={t("tool.finish_task.title")}
        icon={CheckCircleIcon}
        iconClassName="text-green-600"
      />
      <BuiltInToolContent>
        {toolArguments?.summary && (
          <Markdown className="px-4 pb-4">{toolArguments.summary}</Markdown>
        )}
      </BuiltInToolContent>
    </BuiltInToolContainer>
  );
}
