import React from 'react';
import { View, StyleSheet, ViewStyle } from 'react-native';
import { IconButton } from 'react-native-paper';
import { Presence } from '../../store/contacts/types';

interface IProps {
  presence: Presence;
  size?: number;
  customView?: React.ReactNode;
  style?: ViewStyle;
}

export const PresenceView: React.FunctionComponent<IProps> = ({
  presence,
  size = 16,
  customView,
  style,
}) => {
  const getPresenceIcon = () => {
    switch (presence) {
      case Presence.online:
      case Presence.mobile_online:
        return (
          <View
            style={[
              styles.presenceCircle,
              { backgroundColor: '#38A169', width: size, height: size, borderRadius: size / 2 },
              style,
            ]}
          />
        );
      case Presence.away:
      case Presence.manual_away:
        return (
          <View
            style={[
              styles.presenceCircle,
              { backgroundColor: '#FACC03', width: size, height: size, borderRadius: size / 2 },
              style,
            ]}
          />
        );
      case Presence.busy:
      case Presence.busy_audio:
      case Presence.busy_video:
        return (
          <View
            style={[
              styles.presenceCircle,
              { backgroundColor: '#E53E3E', width: size, height: size, borderRadius: size / 2 },
              style,
            ]}
          />
        );
      case Presence.DoNotDisturb:
        return (
          <View
            style={[
              styles.presenceCircle,
              { width: size, height: size, borderRadius: size / 2, backgroundColor: '#E53E3E' },
              style,
            ]}
          >
            <IconButton
              icon="minus"
              iconColor="white"
              size={size / 2}
              style={styles.dndIcon}
            />
          </View>
        );
      default:
        return (
          <View
            style={[
              styles.presenceCircle,
              { backgroundColor: '#A0AEC0', width: size, height: size, borderRadius: size / 2 },
              style,
            ]}
          />
        );
    }
  };

  return <View>{customView ? customView : getPresenceIcon()}</View>;
};

const styles = StyleSheet.create({
  presenceCircle: {
    alignItems: 'center',
    justifyContent: 'center',
  },
  dndIcon: {
    margin: 0,
    padding: 0,
  },
});