import { PluginBase } from '../../PluginBase';
import { openPdfView } from '../../../../plugins';

export class OpenPdfViewerDemo extends PluginBase {
  public getPluginShortDesc(): JSX.Element {
    return (
      <div>打开PDF浏览</div>
    );
  }

  public getPluginFullDesc(): JSX.Element {
    return (
      <div>
        <div>打开PDF浏览</div>
      </div>
    );
  }

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

  public state = {
    filePath: '',
  };

  private openPdfViewer = () => {
    openPdfView({ title: 'PDF Viewer', filePath: this.state.filePath });
  }

  private handleChange = (e) => {
    this.setState({
      filePath: e.target.value,
    });
  }
  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" onChange={this.handleChange} contentEditable={true}>{this.state.filePath}</div>
        <div className="body">
          <div className="play-body-item">
            <button className="exec" onClick={this.openPdfViewer}>打开PDF文件在线预览</button>
            <button className="view" onClick={this.viewCode('open-pdf-viewer')}>查看代码</button>
          </div>
        </div>
      </div>
    );
  }
}
