import React from 'react'; import { View, StyleSheet, ViewStyle, TextStyle } from 'react-native'; import { useStyles } from '../../hooks'; import { ComponentStyleProp, LLComponentStyleFn } from '../../types'; import { IWidgetOptionItem } from '@livelike/javascript'; import { LLText } from '../LLText'; export type LLCheerMeterWidgetResultStyles = { resultContainer: ViewStyle; optionContainer: ViewStyle; leftOptionContainer: ViewStyle; rightOptionContainer: ViewStyle; optionText: TextStyle; }; export type LLCheerMeterWidgetResultProps = ComponentStyleProp & { widgetId: string; widgetOptions: IWidgetOptionItem[]; }; export function LLCheerMeterWidgetResult({ widgetOptions, styles: stylesProp, }: LLCheerMeterWidgetResultProps) { const styles = useStyles({ componentStylesFn: getCheerMeterWidgetResultStyles, stylesProp, }); if (!widgetOptions?.length) { return undefined; } const totalCount = widgetOptions.reduce( (total, option) => total + option.vote_count, 0 ); return ( {widgetOptions.map((option, index) => ( {option.description} ))} ); } const getCheerMeterWidgetResultStyles: LLComponentStyleFn< LLCheerMeterWidgetResultStyles > = ({ theme }) => StyleSheet.create({ resultContainer: { display: 'flex', flexDirection: 'row', marginTop: 4, }, optionContainer: { display: 'flex', flexDirection: 'column', justifyContent: 'center', alignItems: 'center', height: 30, paddingHorizontal: 6, }, leftOptionContainer: { borderTopLeftRadius: 4, borderBottomLeftRadius: 4, backgroundColor: theme.correct, }, rightOptionContainer: { borderTopRightRadius: 4, borderBottomRightRadius: 4, backgroundColor: theme.incorrect, }, optionText: { color: theme.correctIncorrectText, }, });