import { PluginBase } from '../../PluginBase';
import { getDeviceInfo } from '../../../../plugins/util/get-device-info';

export class GetDeviceInfoDemo extends PluginBase {
  public getPluginShortDesc(): JSX.Element {
    return (
      <div>获取NATIVE deviceInfo相关信息</div>
    );
  }

  public getPluginFullDesc(): JSX.Element {
    return (
      <div>
        <div>获取NATIVE Device信息</div>
      </div>
    );
  }

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

  private getDeviceInfo = () => {
    getDeviceInfo().then(result => {
      this.setState({
        payload: JSON.stringify(result),
      });
    });
  }

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

  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.payload}</div>
        <div className="body">
          <div className="play-body-item">
            <button className="exec" onClick={this.getDeviceInfo}>获取设备信息(deviceInfo)</button>
            <button className="view" onClick={this.viewCode('get-device-info')}>查看代码</button>
          </div>
        </div>
      </div>
    );
  }
}
