import React, { useEffect, FunctionComponent, useContext } from 'react';
import { View, ViewStyle, ListRenderItemInfo } from 'react-native';
import styles from './PixelLastTopicsListStyles';
import usePixelLastTopicsListTranslation from './PixelLastTopicsListTranslation'
import { PixelStyles } from 'react-native-pixel-styles';
import { PixelTopicButton } from '../PixelTopicButton/PixelTopicButton';
import { PixelTopic } from '../../Model/PixelTopic';
import { ForumHeaderText } from '../ForumHeaderText/ForumHeaderText';
import { PixelwolfFlatlist } from 'react-native-pixel-components';
import { topicStoreContext } from '../../Store/TopicStore';

interface IProps {
    // Props type definition
    style?: ViewStyle | ViewStyle[]
}

interface IState {
    // State type definition
}

export const PixelLastTopicsList: FunctionComponent<IProps> = (props) => {

    const { I18n } = usePixelLastTopicsListTranslation()
    const themeStore = useContext(PixelStyles.pixelThemeStoreContext)
    const topicStore = useContext(topicStoreContext)

    const initialState: IState = {
    };

    // ComponentDidMount
    useEffect(() => {
        return () => {
            //ComponentDidUnmount
        }
    }, [])

    const renderTopic = (item: ListRenderItemInfo<PixelTopic>) => {
        return <PixelTopicButton style={[styles.smallMarginBottom]} topic={item.item} />
    }
    const renderPlaceholder = () => {
        return <View />
    }

    return (
        <View style={[styles.fullWidthContainer, props.style]}>
            <ForumHeaderText >
                {I18n.translation.LastTopics}
            </ForumHeaderText>
            <PixelwolfFlatlist showsVerticalScrollIndicator={false} style={[styles.fullWidthContainer, styles.smallMarginTop, {
                overflow: 'visible',
            }]}
                data={[]} mapData={topicStore.lastTopics} renderItem={renderTopic} renderPlaceholder={renderPlaceholder} />
        </View>
    );
};
