o2o-negosium-original/frontend/src/features/chat/lib/userButtonConfig.ts

26 lines
1.1 KiB
TypeScript

import type { ChatMessage, UserButtonConfig } from '@/features/chat/types'
export const GO_TO_LIST_TEXT = '상품 목록으로 가기'
// 마지막 봇 메시지의 next_input_mode 로 하단 입력 UI 구성을 결정한다.
export function deriveUserButtonConfig(
messages: ChatMessage[],
isLoading: boolean,
priceErrorMessage: string,
): UserButtonConfig {
if (isLoading) return { type: 'loading' }
if (!messages || messages.length === 0) return { type: '', text: '' }
const last = messages[messages.length - 1]
const mode = last.next_input_mode
const options = last.next_input_type
if (last.chat_end) return { type: 'one-black', text: GO_TO_LIST_TEXT }
if (mode === 'confirm') return { type: 'one-black', text: options?.[0] || '' }
if (mode === 'yes_no') return { type: 'black-white', textList: options || [] }
if (mode === 'percent') return { type: 'percent' }
if (mode === 'price') return { type: 'price', priceErrorMessage: priceErrorMessage || undefined }
if (mode === 'delivery_type') return { type: 'three-black', textList: options || [] }
return { type: '', text: '' }
}