import React, {Component} from 'react';
import {
  View,
  Text,
  TouchableOpacity,
  StyleSheet,
  Image,
  FlatList,
  Alert,
  ScrollView
} from 'react-native';
import ViewShot from 'react-native-view-shot';
import FastImage from 'react-native-fast-image';
import Icon from 'react-native-vector-icons/FontAwesome5';
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 CameraRoll from '@react-native-community/cameraroll';
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 AddFunction from '../../common/addFunction';
import NewsList from './newsList';
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 TestingImage extends Component<Props> {
  @observable
  news = [];

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

  componentDidMount(){
      console.log(this.props.navigation.state.params.imageUri)
  }
  componentWillMount() {
    
  }
  // static navigationOptions = inject("appStore")(observer(({appStore, otherProp}) => {
  //   return {
  //     tabBarLabel:   otherProp.appStore.text.new
  //   }}));

  // static navigationOptions = {
  //   tabBarLabel: 'Home!',
  // };

  // static navigationOptions = () => {
  //   return {
  //     tabBarLabel:  'fff'
  //   }}
  static navigationOptions = ({navigation}) => {
    const {params = {}} = navigation.state;
    return {
      tabBarLabel: params.handleThis,
    };
  };

  async loadNews() {
    try {
      this.store.loading = true;
      await fetch(
        'https://www.news.gov.hk/tc/categories/finance/html/articlelist.rss.xml',
      )
        .then(response => response.text())
        .then(responseData => rssParser.parse(responseData))
        .then(rss => {
          console.log(rss);
          console.log(rss.items.length);
          this.newsHandler(rss.items);
          this.store.loading = false;
        });
    } catch (e) {
      this.store.loading = false;
      console.log(e);
    }
  }

  async newsHandler(data) {
    this.news = [];
    var newsArray = [];
    await data.map((news, index) => {
      var items = {};
      items.id = index;
      items.image = news.description.slice(
        10,
        news.description.indexOf('"/><p><p>'),
      );
      items.title = news.title;
      items.description = news.description;
      newsArray.push(items);
    });
    this.news = newsArray;
    console.log(this.news);
  }

  cloneDeep(item) {
    console.log(item.copyright);
    var data = {};
    data.id = item.id;
    data.image = item.image;
    data.description = item.description;
    data.title = item.title;
    data.copyright = item.copyright;
    return data;
  }

  onCapture = uri => {
    console.log('do something with ', uri);
  };

  render() {
    return (
      <View style={styles.container}>
        <ScrollView>
            <Image source={{uri: this.props.navigation.state.params.imageUri}} resizeMode = {'contain'} style = {{width:width,height:height}}/>
        </ScrollView>
      </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',
  },
});
