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 NewsDetails = inject("appStore")(observer(class NewsDetails extends React.Component {

    data = this.props.route.params.data

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


        })
    }


    async componentWillMount() {

    }

    renderNewsImage() {
        return (
            <View style={{ justifyContent: 'center', alignItems: 'center', width: width, marginTop: 20 }}>
                <ProgressiveFastImage source={{ uri: this.data.imageURL }} style={{ width: width - 40, height:s(200), borderRadius: s(30) }} resizeMode = 'contain' />
            </View>

        )
    }
    renderContent() {
        return (
            <View style={{ backgroundColor: '#FFC76F', marginHorizontal: 20, marginVertical: 30, borderRadius: width / 20 }}>
                <View style={{ margin: 20, marginBottom: 50, }}>
                    <Text style={{ color: colors.fontColor }}>
                        {moment(this.data.date).format('YYYY/MM/DD').toString('DD/MM/YYYY')}
                    </Text>
                    <HTMLView
                        style={{ marginTop: 5, fontColor: colors.fontColor }}
                        value={this.data.content}
                        stylesheet={styles.content}
                        textComponentProps={{ style: { color: colors.fontColor } }}
                    />
                </View>

                <Image source={images.titleLogo} style={{ position: 'absolute', bottom: -20, right: 0 }} />
            </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.renderNewsImage()}
                    {this.renderContent()}
                </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 NewsDetails
