/* eslint-disable react-native/no-inline-styles */
import React, { Component } from 'react';
import { View, Text, DeviceEventEmitter, Button } from 'react-native';
// import EventEmitter from 'react-native-eventemitter';
import { DenetWebview } from '@/components/webview';
import { guid } from '@/utils/';
import messageCenter from '@/utils/messageCenter';

interface Props {
	route: any;
}
class Redpack extends Component<Props> {
	webref = {} as any;
	favoriteTweet = () => {
		const idArray = this.props.route.params.tweet_Id.split('');
		console.log(idArray);
		const len = idArray.length;
		const idArray1 = idArray.splice(0, Math.floor(len / 2));
		DeviceEventEmitter.emit('FavoriteTweet', {
			id1: idArray1.join(''),
			id2: idArray.join(''),
		});
	};

	onMessageHandle = (messageData: any) => {
		let { info, data } =
			(messageData.nativeEvent.data &&
				JSON.parse(messageData.nativeEvent.data)) ||
			{};
		console.log('onMessageHandle', info, data);
		info.target = this.webref;
		messageCenter.send({ info, data });
	};

	componentDidMount() {
		// this.TwitterLikeAPI();
	}
	render() {
		const { tweet_Id, post_Id, invite_code, ct0, page_type } =
			this.props.route.params;
		const iframe_id = `denet-${guid()}`;
		return (
			<View style={{ flex: 1 }}>
				{/* <Text>tweet_Id: {this.props.route.params.tweet_Id}</Text>
				<Text>post_Id: {this.props.route.params.post_Id}</Text>
				<Text>invite_code: {this.props.route.params.invite_code}</Text>
				<Text>ct0: {this.props.route.params.ct0}</Text>
				<Button
					onPress={this.favoriteTweet}
					title="FavoriteTweet"
					color="#841584"
					accessibilityLabel="FavoriteTweet when click"
				/> */}
				<DenetWebview
					onLoadEndHandle={() => {}}
					refHandle={r => (this.webref = r)}
					onMessageHandle={this.onMessageHandle}
					handleWebViewNavigationStateChange={() => {}}
					uri={`http://localhost:3001/red-pack?postId=${post_Id}&tweetId=${tweet_Id}&tweet_author=&window_origin=https://twitter.com&page_type=${page_type}&iframeId=${iframe_id}&appVersionCode=22`}
				/>
			</View>
		);
	}
}
export default Redpack;
