| 1 | import { ChevronDownIcon } from "@heroicons/react/24/outline"; |
| 2 | import { ArrowPathIcon } from "@heroicons/react/24/solid"; |
| 3 | import type { ProfileDescription } from "core/config/ConfigHandler"; |
| 4 | import { useAppSelector } from "../../redux/hooks"; |
| 5 | import { fontSize } from "../../util"; |
| 6 | import { cn } from "../../util/cn"; |
| 7 | import { ListboxButton } from "../ui"; |
| 8 | import { AssistantIcon } from "./AssistantIcon"; |
| 9 | |
| 10 | interface SelectedAssistantButtonProps { |
| 11 | selectedProfile: ProfileDescription | null; |
| 12 | variant?: "lump" | "sidebar"; |
| 13 | } |
| 14 | |
| 15 | export function SelectedAssistantButton({ |
| 16 | selectedProfile, |
| 17 | variant, |
| 18 | }: SelectedAssistantButtonProps) { |
| 19 | const configLoading = useAppSelector((store) => store.config.loading); |
| 20 | |
| 21 | const isSidebar = variant === "sidebar"; |
| 22 | const iconSize = isSidebar ? "h-4 w-4" : "h-3 w-3"; |
| 23 | const buttonPadding = isSidebar ? "px-2 py-1.5" : "px-0 py-0.5"; |
| 24 | const buttonStyle = isSidebar ? {} : { fontSize: fontSize(-3) }; |
| 25 | |
| 26 | return ( |
| 27 | <ListboxButton |
| 28 | data-testid="assistant-select-button" |
| 29 | className={`text-description overflow-hidden border-none bg-transparent hover:brightness-110 ${isSidebar ? "w-full justify-start" : "gap-1.5"} ${buttonPadding}`} |
| 30 | style={buttonStyle} |
| 31 | > |
| 32 | <div |
| 33 | className={`flex flex-row items-center ${isSidebar ? "w-full justify-between" : "gap-1.5"}`} |
| 34 | > |
| 35 | <div className="flex min-w-0 flex-1 flex-row items-center gap-2"> |
| 36 | {selectedProfile === null ? ( |
| 37 | "Create your first agent" |
| 38 | ) : configLoading ? ( |
| 39 | <span className="text-description flex flex-row items-center"> |
| 40 | <ArrowPathIcon |
| 41 | className={cn( |
| 42 | `text-description mr-1.5 ${iconSize}`, |
| 43 | configLoading && "animate-spin-slow", |
| 44 | )} |
| 45 | /> |
| 46 | Loading |
| 47 | </span> |
| 48 | ) : ( |
| 49 | <> |
| 50 | <AssistantIcon assistant={selectedProfile} size={iconSize} /> |
| 51 | <span className={`xs:line-clamp-1 hidden select-none text-xs`}> |
| 52 | {selectedProfile.title} |
| 53 | </span> |
| 54 | </> |
| 55 | )} |
| 56 | </div> |
| 57 | <ChevronDownIcon |
| 58 | className={`text-description ml-0.5 h-3 w-3 flex-shrink-0 select-none ${isSidebar && "hidden md:block"}`} |
| 59 | aria-hidden="true" |
| 60 | /> |
| 61 | </div> |
| 62 | </ListboxButton> |
| 63 | ); |
| 64 | } |