import { isLight } from "indite-js/lib/hexToRgb"; import { ContainerTheme, GeneralTheme } from "indite-js/schemas"; import { BackgroundType, defaultBackgroundColor, defaultBackgroundType, defaultContainerBackgroundColor, defaultOpacity, } from "indite-js/schemas/features/bot/theme/constants"; import { isEmpty, isNotEmpty } from "indite-js/lib"; type Props = { chatContainer: ContainerTheme | undefined; generalBackground: GeneralTheme["background"]; }; export const isChatContainerLight = ({ chatContainer, generalBackground, }: Props): boolean => { const chatContainerBgColor = chatContainer?.backgroundColor ?? defaultContainerBackgroundColor; const ignoreChatBackground = (chatContainer?.opacity ?? defaultOpacity) <= 0.3 || chatContainerBgColor === "transparent" || isEmpty(chatContainerBgColor); if (ignoreChatBackground) { const bgType = generalBackground?.type ?? defaultBackgroundType; const backgroundColor = bgType === BackgroundType.IMAGE ? "#000000" : bgType === BackgroundType.COLOR && isNotEmpty(generalBackground?.content) ? generalBackground.content : "#ffffff"; return isLight(backgroundColor); } return isLight(chatContainer?.backgroundColor ?? defaultBackgroundColor); };