import React, { Component } from 'react';
import { View, Text, Dimensions, Platform, Button, ActivityIndicator } from 'react-native';
import { WebView } from 'react-native-webview';
import firebase from 'react-native-firebase';
import CryptoJS from "react-native-crypto-js";
import Moment from 'moment';
import * as GameballSdk from './gameball-sdk';
import AsyncStorage from '@react-native-community/async-storage';


class GameballWidget extends Component {
  constructor(props) {
    super(props);
    this.state = {
      url: null,
      playerId: '',
      apiKey: '',
      lang: '',
      playerId: ''
    };
  }

  render() {
    if (this.props) {
      params = 'playerId=' + this.props.playerId + '&apiKey=' + this.props.apiKey + '&lang=' + this.props.lang;
      console.log(params)
      sourceUri =
        Platform.OS === 'android'
          ? 'file:///android_asset/Web.bundle/site/index.html?playerId=' + this.props.playerId + '&apiKey=' + this.props.apiKey + '&lang=' + this.props.lang
          : 'assets/html/Web.bundle/loader.html';
      var injectedJS = `
          if (!window.location.search) {
            var link = document.getElementById('progress-bar');
            link.href = './site/index.html?${params}';
            link.click();
          }
    `;
    }
    


    console.log(sourceUri)
    return (
      <View style={{ flex: 1 }}>
        {Platform.OS === 'ios' &&
          <WebView
            source={{ uri: sourceUri }}
            javaScriptEnabled={true}
            startInLoadingState
            useWebKit={true}
            injectedJavaScript={injectedJS}
            originWhitelist={['*']}
            allowFileAccess={true}
          />
        }
        {Platform.OS === 'android' &&
          <WebView
            source={{ uri: sourceUri }}
            javaScriptEnabled={true}
            originWhitelist={['*']}
            allowFileAccess={true}
            startInLoadingState
            useWebKit={true}
          />
        }
      </View>
    );
  }

}

export default (GameballWidget);