import React, { useEffect, FunctionComponent, useContext } from 'react';
import { View, ViewStyle, ListRenderItemInfo } from 'react-native';
import styles from './PixelForumsGridStyles';
import usePixelForumsGridTranslation from './PixelForumsGridTranslation'
import { PixelStyles } from 'react-native-pixel-styles';
import { PixelwolfFlatlist, PixelwolfText } from 'react-native-pixel-components';
import { PixelForum } from '../../Model/PixelForum';
import { PixelForumButton } from '../PixelForumButton/PixelForumButton';
import { ForumHeaderText } from '../ForumHeaderText/ForumHeaderText';
import { forumStoreContext } from '../../Store/ForumStore';

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

interface IState {
    // State type definition
}

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

    const { I18n } = usePixelForumsGridTranslation()
    const themeStore = useContext(PixelStyles.pixelThemeStoreContext)
    const forumStore = useContext(forumStoreContext)

    const initialState: IState = {
    };

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

    const renderForum = (item: ListRenderItemInfo<PixelForum>) => {
        return <PixelForumButton style={[styles.flex1, (item.index + 1) % 2 === 0 && { marginLeft: 20 }, item.index > 1 && styles.marginTop]} forum={item.item} />
    }
    const renderPlaceholder = () => {
        return <View />
    }

    return (
        <View style={[styles.fullWidthContainer, props.style]}>
            <ForumHeaderText>
                {I18n.translation.Forums}
            </ForumHeaderText>
            <PixelwolfFlatlist scrollEnabled={false} style={[styles.fullWidthContainer, styles.smallMarginTop, {
                overflow: 'visible',
            }]} numColumns={2} data={[]} mapData={forumStore.forums} renderItem={renderForum} renderPlaceholder={renderPlaceholder} />
        </View>
    );
};
