import React, {Component} from 'react';
import {
  View,
  Text,
  TouchableOpacity,
  StyleSheet,
  Image,
  FlatList,
  ScrollView,
} from 'react-native';
import FastImage from 'react-native-fast-image';
import Icon from 'react-native-vector-icons/FontAwesome5';
import BackHeader from '../../components/backHeader';
import {colors} from '../../assets/styles/colors-theme';
import {Fonts} from '../../assets/styles/fonts-theme';
import history from '../../common/history';
import LoadingView from '../../common/loading';
import NaviBar from '../../components/navi-bar';
import {scale, verticalScale, moderateScale} from 'react-native-size-matters';
import Migrations from '../../services/realm/Mirgrations';
import {inject, observer} from 'mobx-react';
import {queryUser} from '../../services/realm/realmManger';
import Swiper from 'react-native-swiper';
import Global from '../../services/Global';
import {width, height} from '../../common/screen';
import HTML from 'react-native-render-html';
import AddFunction from '../../common/addFunction';
import {
  UserSchemea,
  ApartmentSchemea,
  DocSchemea,
  NotificationSchemea,
} from '../../services/realm/schemeas';
import * as rssParser from 'react-native-rss-parser';

import Realm from 'realm';
import {observable} from 'mobx';
import {func} from 'prop-types';
let realm = new Realm({
  schema: [UserSchemea, ApartmentSchemea, DocSchemea, NotificationSchemea],
});
@inject('appStore')
@observer
export default class NewsDetails extends Component<Props> {
  @observable
  newsData = '';

  constructor(props) {
    super(props);
    this.store = props.appStore;
    this.newsData = this.props.navigation.state.params.details.description;
  }
  componentWillMount() {}

  render() {
    console.log(this.props.navigation.state.params.type);
    return (
      <View style={styles.container}>
        <BackHeader instance={this} back={true} />
        <LoadingView visible={this.store.loading} />
        <ScrollView style={{flex: 1}}>
          {this.props.navigation.state.params.type == 'rentchat' ? (
            <Image
              style={{width: width, height: 300}}
              source={{
                uri: this.props.navigation.state.params.details.image,
              }}
            />
          ) : (
            <View />
          )}

          <HTML
            html={this.newsData}
            imagesMaxWidth={width - 40}
            containerStyle={{marginTop: 20, marginLeft: 20, marginRight: 20}}
            baseFontStyle={{color: colors.textColor}}
          />
        </ScrollView>
        <View style={{width: width, height: 30, justifyContent: 'center'}}>
          <Text
            style={{
              fontFamily: Fonts.ubuntu,
              color: colors.textColor,
              marginLeft: 20,
            }}>
            {'Copyright: 香港政府新聞網 - 版權所有'}
          </Text>
        </View>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: 'white',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  button: {
    borderWidth: 1,
    borderColor: '#000000',
    margin: 5,
    padding: 5,
    width: '70%',
    backgroundColor: '#DDDDDD',
    borderRadius: 5,
  },
  textField: {
    borderWidth: 1,
    borderColor: '#AAAAAA',
    margin: 5,
    padding: 5,
    width: '70%',
  },
  spacer: {
    height: 10,
  },
  title: {
    fontWeight: 'bold',
    fontSize: 20,
    textAlign: 'center',
  },
});
