import { PluginBase } from '../../PluginBase';
import { readInstalledAppInfo } from '../../../../plugins/util/read-installed-app-info';

export class ReadInstalledAppInfoDemo extends PluginBase {
  public getPluginShortDesc(): JSX.Element {
    return (
      <div>取当前手机已安装的App信息</div>
    );
  }

  public getPluginFullDesc(): JSX.Element {
    return (
      <div>
        <div>取当前手机已安装的App信息</div>
      </div>
    );
  }

  public state = {
    value: JSON.stringify({}),
  };

  private viewCode = (mdPath) => () => {
    this.showMarkdownPopup(require(`./${mdPath}.md`));
  }

  private getInstalledAppInfo = () => {
    readInstalledAppInfo().then(result => {
      this.setState({
        value: JSON.stringify(result),
      });
    });
  }
  public render() {
    return (
      <div className="plugin-page">
        <h2 className="left">{this.props.pluginName}</h2>
        <div className="short-desc">{this.getPluginShortDesc()}</div>
        <div className="full-desc">{this.getPluginFullDesc()}</div>
        <div className="text-area">{this.state.value}</div>
        <div className="body">
          <div className="play-body-item">
            <button className="exec" onClick={this.getInstalledAppInfo}>取当前手机已安装的App信息</button>
            <button className="view" onClick={this.viewCode('read-installed-app-info')}>查看代码</button>
          </div>
        </div>
      </div>
    );
  }
}
