import React, { FC, useContext } from 'react';
import { View } from 'react-native';
import { ChildPaginationProps } from './types';
import Dot from './Dot';
import styles from './styles';
import { Spacing } from '../Consts';
import { ApplicationContext, MiniAppContext } from '../Context';

const PaginationDot: FC<ChildPaginationProps> = ({
  dataLength = 2,
  activeIndex = 0,
  style,
}) => {
  const { theme } = useContext(ApplicationContext);
  const context = useContext<any>(MiniAppContext);

  const showBaseLineDebug = context?.features?.showBaseLineDebug ?? false;

  const renderDots = () => {
    const dots: React.ReactElement[] = [];
    for (let i = 0; i < dataLength; i++) {
      dots.push(
        <Dot
          key={`Dot${i}`}
          style={[
            i !== dataLength - 1 ? { marginRight: Spacing.XS } : {},
            { backgroundColor: theme.colors.primary },
          ]}
          active={activeIndex === i}
        />,
      );
    }
    return dots;
  };
  return (
    <View
      style={[style, styles.row, showBaseLineDebug && styles.debugBaseLine]}
    >
      <View style={styles.paginationPinkContainer}>{renderDots()}</View>
    </View>
  );
};

export default PaginationDot;
