import React from 'react';
import {
    SafeAreaView,
    Text,
    View,
    TouchableOpacity,
    StyleSheet,
    Image,
    ImageBackground,
    ScrollView
} from 'react-native';
var _ = require('lodash');
import { width, height } from '../../services/screen';
import { colors } from '../../assets/styles/colors-theme';
import Loading from '../../components/Loading';
import Toast, { DURATION } from 'react-native-easy-toast';
import { inject, observer } from "mobx-react"
import { Col, Grid, Row } from "react-native-easy-grid";
import TitleBar from '../../components/titleBar'
import { observable, makeObservable } from 'mobx'
import { WebView } from 'react-native-webview';
import Carousel, { Pagination } from 'react-native-snap-carousel';
import ListTitle from '../../components/listTitle';
import I18n from '../../services/i18n'
import { s, vs, ms, mvs } from 'react-native-size-matters';
import { images } from '../../assets/images/imageIndex';
import RenderProducts from '../../components/renderProducts';
import HTMLView from 'react-native-htmlview';
import moment from 'moment';
import ProgressiveFastImage from "@freakycoder/react-native-progressive-fast-image";
const NewsList = inject("appStore")(observer(class NewsList extends React.Component {

   

    constructor(props) {
        super(props);
        this.store = props.appStore;
        makeObservable(this, {


        })
    }


    async componentWillMount() {

    }
    renderNews(item) {
        console.log(item)
        return (
            <TouchableOpacity style={{ height: s(250), width:width-40, borderRadius: 15,marginTop:20 }}
                onPress={() => { this.props.navigation.navigate('NewsDetails', { data: item }) }}>
                <View style={{ width: '100%', height: '65%' }}>
                    <ProgressiveFastImage source={{ uri: item.imageURL }} style={{ width: '100%', height: '100%', borderTopLeftRadius: 15, borderTopRightRadius: 15 }} />
                </View>
                <View style={{ position: 'absolute', width: '100%', height: '40%', backgroundColor: colors.listItemsbgc, bottom: 0, borderRadius: 15 }}>
                    <View style={{ marginVertical: 5, marginHorizontal: 10 }}>
                        <Text style={{ fontSize: 11, color: colors.fontColor }}>
                            {item.date}
                        </Text>
                        <Text numberOfLines={2} style={{ fontSize: 13, color: colors.fontColor, marginTop: 3, fontWeight: '800' }}>
                            {item.title}
                        </Text>
                        <Text numberOfLines={3} style={{ fontSize: 11, color: colors.fontColor, marginTop: 5, }}>
                            {item.content.replace(/(<([^>]+)>)/ig, "")}
                        </Text>
                    </View>
                    <Image source={images.titleLogo} style={{ position: 'absolute', top: -30, right: 0 }} />
                </View>
            </TouchableOpacity>
        )
    }
    renderNewsList() {
        return (
            <View style={{ width: width ,alignItems:'center'}}>
              
                    {this.store.news.map((item, index) => {
                        return (
                            this.renderNews(item)
                        )
                    })}
            
            </View>
        )
    }



    render() {
        return (

            <ImageBackground resizeMode='cover' style={{ flex: 1, backgroundColor: colors.bgc }} source={require('../../assets/images/background.png')} >
                <Loading loading={this.store.loading} />
                <TitleBar navigation={this.props.navigation} back={true} user={true} />
                <View style={{ width: width, alignItems: 'center', marginTop: 30, }}>
                    <Text style={{ fontWeight: '800', color: colors.fontColor, fontSize: 15 }}>
                        {I18n.t('news')}
                    </Text>
                </View>

                <ScrollView>
                 {this.renderNewsList()}
                </ScrollView>
                <Toast
                    ref="toast"
                    style={{ backgroundColor: colors.mainColor }}
                    position="center"
                    positionValue={100}
                    fadeInDuration={750}
                    fadeOutDuration={2000}
                    opacity={0.8}
                    textStyle={{ color: 'white' }}
                />
            </ImageBackground>

        );
    }
}))
const styles = StyleSheet.create({
    titleText: {
        color: colors.fontColor,
        fontSize: 13,
        fontWeight: '800'
    },
    content: {
        margin: 20,
        br: { marginTop: -30, fontSize: 18, },
    },
});

export default NewsList
