import React from "react";
import { View, Text, TextStyle, StyleSheet } from "react-native";
import { toNumberWithDefault } from "@applicaster/zapp-react-native-utils/numberUtils";
import { isNilOrEmpty } from "@applicaster/zapp-react-native-utils/reactUtils/helpers";

type Props = {
  config: {
    titleColor: string;
    summaryColor: string;
    backgroundColor: string;
    backgroundImage: string;
    isRTL: boolean;
    summaryFontFamily: string;
    summaryFontSize: number;
  };
  summary: string | number;
};

const styles = StyleSheet.create({
  container: {
    width: 600,
    marginBottom: 30,
  },
});

const textStyles = ({
  summaryColor,
  isRTL,
  summaryFontFamily,
  summaryFontSize,
}) => ({
  textAlign: (isRTL ? "right" : "left") as TextStyle["textAlign"],
  fontSize: toNumberWithDefault(20, summaryFontSize),
  color: summaryColor,
  fontWeight: "600" as TextStyle["fontWeight"],
  opacity: 0.8,
  fontFamily: summaryFontFamily || null,
});

export function Summary({ summary, config }: Props) {
  if (isNilOrEmpty(summary)) {
    return null;
  }

  return (
    <View style={styles.container}>
      <Text style={textStyles(config)} numberOfLines={3}>
        {summary}
      </Text>
    </View>
  );
}
