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';
import useNotices from '../Home/hooks/useNotices';

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, customerId } = this.$router.params;
    console.log(id);

    this.setState({
      linkUrl: `${ANN_LINK_URL}?id=${id}&token=${token}&customerId=${customerId}`,
    });
  }

  render() {
    const { linkUrl } = this.state;
    console.log(linkUrl);

    return linkUrl && <WebView src={linkUrl} />;
  }
}

export default Content as ComponentClass<PageOwnProps, PageState>;
