{"version":3,"file":"CopilotChatSuggestionView.cjs","names":["React","cn","renderSlot","CopilotChatSuggestionPill"],"sources":["../../../src/components/chat/CopilotChatSuggestionView.tsx"],"sourcesContent":["import React from \"react\";\nimport { Suggestion } from \"@copilotkitnext/core\";\nimport { renderSlot, WithSlots } from \"@/lib/slots\";\nimport { cn } from \"@/lib/utils\";\nimport CopilotChatSuggestionPill, {\n  CopilotChatSuggestionPillProps,\n} from \"./CopilotChatSuggestionPill\";\n\nconst DefaultContainer = React.forwardRef<\n  HTMLDivElement,\n  React.HTMLAttributes<HTMLDivElement>\n>(function DefaultContainer({ className, ...props }, ref) {\n  return (\n    <div\n      ref={ref}\n      data-copilotkit\n      data-testid=\"copilot-suggestions\"\n      className={cn(\n        \"cpk:flex cpk:flex-wrap cpk:items-center cpk:gap-1.5 cpk:sm:gap-2 cpk:pl-0 cpk:pr-4 cpk:sm:px-0 cpk:pointer-events-none\",\n        className,\n      )}\n      {...props}\n    />\n  );\n});\n\nexport type CopilotChatSuggestionViewProps = WithSlots<\n  {\n    container: typeof DefaultContainer;\n    suggestion: typeof CopilotChatSuggestionPill;\n  },\n  {\n    suggestions: Suggestion[];\n    onSelectSuggestion?: (suggestion: Suggestion, index: number) => void;\n    loadingIndexes?: ReadonlyArray<number>;\n  } & React.HTMLAttributes<HTMLDivElement>\n>;\n\nexport const CopilotChatSuggestionView = React.forwardRef<\n  HTMLDivElement,\n  CopilotChatSuggestionViewProps\n>(function CopilotChatSuggestionView(\n  {\n    suggestions,\n    onSelectSuggestion,\n    loadingIndexes,\n    container,\n    suggestion: suggestionSlot,\n    className,\n    children,\n    ...restProps\n  },\n  ref,\n) {\n  const loadingSet = React.useMemo(() => {\n    if (!loadingIndexes || loadingIndexes.length === 0) {\n      return new Set<number>();\n    }\n    return new Set(loadingIndexes);\n  }, [loadingIndexes]);\n\n  const ContainerElement = renderSlot(container, DefaultContainer, {\n    ref,\n    className,\n    ...restProps,\n  });\n\n  const suggestionElements = suggestions.map((suggestion, index) => {\n    const isLoading = loadingSet.has(index) || suggestion.isLoading === true;\n    const pill = renderSlot<\n      typeof CopilotChatSuggestionPill,\n      CopilotChatSuggestionPillProps\n    >(suggestionSlot, CopilotChatSuggestionPill, {\n      children: suggestion.title,\n      isLoading,\n      type: \"button\",\n      onClick: () => onSelectSuggestion?.(suggestion, index),\n    });\n\n    return React.cloneElement(pill, {\n      key: `${suggestion.title}-${index}`,\n    });\n  });\n\n  const boundContainer = React.cloneElement(\n    ContainerElement,\n    undefined,\n    suggestionElements,\n  );\n\n  if (typeof children === \"function\") {\n    const sampleSuggestion = renderSlot<\n      typeof CopilotChatSuggestionPill,\n      CopilotChatSuggestionPillProps\n    >(suggestionSlot, CopilotChatSuggestionPill, {\n      children: suggestions[0]?.title ?? \"\",\n      isLoading:\n        suggestions.length > 0\n          ? loadingSet.has(0) || suggestions[0]?.isLoading === true\n          : false,\n      type: \"button\",\n    });\n\n    return (\n      <div data-copilotkit style={{ display: \"contents\" }}>\n        {children({\n          container: boundContainer,\n          suggestion: sampleSuggestion,\n          suggestions,\n          onSelectSuggestion,\n          loadingIndexes,\n          className,\n          ...restProps,\n        })}\n      </div>\n    );\n  }\n\n  if (children) {\n    return (\n      <div data-copilotkit style={{ display: \"contents\" }}>\n        {boundContainer}\n        {children}\n      </div>\n    );\n  }\n\n  return boundContainer;\n});\n\nCopilotChatSuggestionView.displayName = \"CopilotChatSuggestionView\";\n\nexport default CopilotChatSuggestionView;\n"],"mappings":";;;;;;;;;AAQA,MAAM,mBAAmBA,cAAM,WAG7B,SAAS,iBAAiB,EAAE,WAAW,GAAG,SAAS,KAAK;AACxD,QACE,2CAAC;EACM;EACL;EACA,eAAY;EACZ,WAAWC,iBACT,0HACA,UACD;EACD,GAAI;GACJ;EAEJ;AAcF,MAAa,4BAA4BD,cAAM,WAG7C,SAAS,0BACT,EACE,aACA,oBACA,gBACA,WACA,YAAY,gBACZ,WACA,UACA,GAAG,aAEL,KACA;CACA,MAAM,aAAaA,cAAM,cAAc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