import React from "react"; import { Box, VStack, Text, Button, Image } from "@chakra-ui/react"; import { useChatContext } from "@/providers/chat/chat-context"; import { WidgetHeader } from "../../components/WidgetHeader"; import InputField from "~/components/widget/components/input-field/InputField"; import { useInput } from "./useInput"; import AiSearchIcon from "~/assets/icons/ai-search.svg"; import MoriBranding from "~/components/widget/components/MoriBranding"; import { HorizontalChannelsList } from "~/components/support-channel-menu"; import { createNameSentence } from "~/utils/helpers"; interface SuggestionScreenProps { onStartChat: (message: string, imageUrl?: string, apiMessage?: string) => void; isMobile?: boolean; isExpanded?: boolean; onToggleExpand?: () => void; onClose: () => void; } const SuggestionScreen: React.FC = ({ onStartChat, isMobile, isExpanded = false, onToggleExpand, onClose }) => { const { inputValue, handleInputChange } = useInput(); const { botData, dynamicWelcomeMessage } = useChatContext(); const isWhiteLabeled = botData?.white_label?.is_white_labeled ?? false; const isWidgetTestMode = botData?.widget_test === true; // Build suggestions array: dynamic suggestion first (if available), then backend suggestions const allSuggestions = React.useMemo(() => { const suggestions: Array<{ text: string; isDynamic: boolean }> = []; // Add dynamic suggestion first if in widget_test mode if (isWidgetTestMode && dynamicWelcomeMessage) { suggestions.push({ text: dynamicWelcomeMessage, isDynamic: true }); } // Add backend suggestions if (botData?.suggestedReply) { botData.suggestedReply.forEach((s) => { suggestions.push({ text: s, isDynamic: false }); }); } return suggestions; }, [isWidgetTestMode, dynamicWelcomeMessage, botData?.suggestedReply]); const handleSuggestionClick = (suggestion: string, imageUrl?: string, isDynamicSuggestion?: boolean) => { handleSubmit({ message: suggestion, imageUrl, isDynamicSuggestion }); }; const handleSubmit = ({ message, imageUrl, isDynamicSuggestion }: { message: string; imageUrl?: string; isDynamicSuggestion?: boolean; }) => { if (message.trim() || imageUrl) { // For dynamic suggestions, we pass a special apiMessage that tells the bot // this is its own suggestion that the user clicked on if (isDynamicSuggestion) { const apiMessage = `[SYSTEM: User clicked on your suggested prompt. Respond to this topic directly.]\n\n${message.trim()}`; onStartChat(message.trim(), imageUrl, apiMessage); } else { onStartChat(message.trim(), imageUrl); } } }; return ( <> {createNameSentence(botData?.agent_name)} هر سوالی برای خرید داری، بپرس{" "} {allSuggestions.map((suggestion, index) => ( ))} {/* Support Channels List */} {!isWhiteLabeled && ( )} ); }; export default SuggestionScreen;