import React from 'react';
import { StyleSheet, View } from 'react-native';

import { useChannelsContext } from '../../contexts/channelsContext/ChannelsContext';
import { useComponentsContext } from '../../contexts/componentsContext/ComponentsContext';
import { useTheme } from '../../contexts/themeContext/ThemeContext';

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

export const ChannelListLoadingIndicator = () => {
  const {
    theme: {
      channelListLoadingIndicator: { container },
    },
  } = useTheme();
  const { numberOfSkeletons } = useChannelsContext();
  const { Skeleton } = useComponentsContext();

  return (
    <View style={[styles.container, container]} testID='channel-list-loading-indicator'>
      {Array.from(Array(numberOfSkeletons)).map((_, index) => (
        <Skeleton key={`skeleton_${index}`} />
      ))}
    </View>
  );
};
