import { Component } from '@tarojs/taro';
import { ComponentClass } from 'react';
import { WebView } from '@tarojs/components';
import { connect } from '@tarojs/redux';
import { ANN_LINK_URL } from '../../constants';
import { shareHandle } from '@/common/shareMethod';

type PageOwnProps = {
  token: string;
};
type PageState = {
  linkUrl: string;
};

interface Content {
  props: PageOwnProps;
  state: PageState;
}

@connect(({ userinfo }) => ({
  token: userinfo.token,
}))
class Content extends Component {
  constructor(props) {
    super(props);
    this.state = {
      linkUrl: '',
    };
    this.getLinkUrl();
  }
  onShareAppMessage = shareHandle;

  getLinkUrl() {
    const { token } = this.props;
    const { id } = this.$router.params;
    this.setState({
      linkUrl: `${ANN_LINK_URL}?id=${id}&token=${token}`,
    });
  }

  render() {
    const { linkUrl } = this.state;
    return linkUrl && <WebView src={linkUrl} />;
  }
}

export default Content as ComponentClass<PageOwnProps, PageState>;
