import { StyleSheet, TouchableOpacity, View, ViewStyle } from "react-native";
import { GenericActionPayload } from "../../App/common/actions/GenericAction";
import { CtaData } from "../../App/common/interface";
import { TitleWithAssetsWidgetData } from "../../App/common/interface/widgets/widgetData/TitleWithAssetsWidgetData";
import { StyledImage } from "../StyledImage";
import { StyledLottie } from "./styled-lottie/StyledLottie";
import { StyledText } from "./styled-text/StyledText";
import Colors from "../../assets/colors/colors";

const TitleWithAssetsWidget = ({
  widgetData,
  widgetStyle,
  handleActions,
  widgetIndex,
  handleClick,
}: {
  widgetData: TitleWithAssetsWidgetData;
  widgetStyle: ViewStyle;
  handleActions: (screenActionPayload?: GenericActionPayload) => void;
  widgetIndex?: number;
  handleClick?: (ctaData: CtaData) => void;
}) => {
  return (
    <TouchableOpacity
      onPress={() => {
        handleClick && widgetData?.cta && handleClick(widgetData?.cta);
      }}
      activeOpacity={1}
    >
      <View
        style={
          widgetData?.titleStyle ? widgetData?.titleStyle : styles.container
        }
      >
        {widgetData?.leftIcon && (
          <View>
            <StyledImage imageFieldData={widgetData?.leftIcon} />
          </View>
        )}
        {widgetData?.leftLottie && (
          <View>
            <StyledLottie lottieFieldData={widgetData?.leftLottie} />
          </View>
        )}
        {widgetData?.title && (
          <View>
            <StyledText textFieldData={widgetData?.title} />
          </View>
        )}
        {widgetData?.rightIcon && (
          <View>
            <StyledImage imageFieldData={widgetData?.rightIcon} />
          </View>
        )}
        {widgetData?.rightLottie && (
          <View>
            <StyledLottie lottieFieldData={widgetData?.rightLottie} />
          </View>
        )}
      </View>
    </TouchableOpacity>
  );
};

const styles = StyleSheet.create({
  container: {
    flexDirection: "row",
    justifyContent: "space-between",
    alignItems: "center",
    borderWidth: 1,
    borderColor: Colors.hawkesBlue,
    borderRadius: 32,
    paddingHorizontal: 16,
    paddingVertical: 9,
    backgroundColor: Colors.powderBlue,
  },
});

export default TitleWithAssetsWidget;
