import React from 'react';
import LinearGradient from 'react-native-linear-gradient';
import {
  StyleSheet,
  TouchableWithoutFeedback,
  Keyboard,
  ViewProps,
  SafeAreaView,
} from 'react-native';
import {CenteredView} from '../common';
import {BackgroundGradientType} from '../../types';
import {BACKGROUND_GRADIENT_MAP} from '../../constants';

interface BackgroundProps extends ViewProps {
  centered?: boolean;
  gradientType: BackgroundGradientType;
}
const Background: React.FC<BackgroundProps> = (props) => {
  const {centered, gradientType, children} = props;
  return (
    <LinearGradient
      colors={BACKGROUND_GRADIENT_MAP[gradientType]}
      useAngle={true}
      angle={154.72}
      angleCenter={{x: 0.5, y: 0.5}}
      style={styles.container}>
      <TouchableWithoutFeedback accessible={false} onPress={Keyboard.dismiss}>
        {centered ? (
          <CenteredView {...props}>{children}</CenteredView>
        ) : (
          <SafeAreaView {...props}>{children}</SafeAreaView>
        )}
      </TouchableWithoutFeedback>
    </LinearGradient>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
});

export default Background;
