import React from 'react';
import {StyleProp, View, ViewStyle} from 'react-native';
import {Skeleton} from '@components/_HuGo/Skeleton';
import {Divider} from '@components/_HuGo/Divider';
import {ListItemSkeleton} from '@components/_HuGo/List';
import {Typography} from '@components/_core/Typography';
import {useTheme} from '@shared/theme';

import {styles} from './styles';

const DEFAULT_SKELETON_ITEM_LENGTH = 10;

interface Props {
  style?: StyleProp<ViewStyle>;
  withDescription?: boolean;
  withDivider?: boolean;
  itemLength?: number;
}

export function SectionListSkeleton({
  style,
  withDescription = true,
  withDivider = true,
  itemLength = DEFAULT_SKELETON_ITEM_LENGTH,
}: Props) {
  const {theme} = useTheme();
  const array = new Array(itemLength).fill(null);

  return (
    <Skeleton style={style}>
      <View
        style={[styles.sectionTitle, {backgroundColor: theme.neutralBgTrans}]}>
        <Typography weight="semiBold">A</Typography>
      </View>
      {array.map((_, index) => (
        <View key={index} style={styles.item}>
          <ListItemSkeleton withDescription={withDescription} />
          {withDivider && index < itemLength - 1 && <Divider />}
        </View>
      ))}
    </Skeleton>
  );
}
