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

export class GetWebviewCacheDemo extends PluginBase {
  public getPluginShortDesc(): JSX.Element {
    return (
      <div>获取客户端缓存信息</div>
    );
  }

  public getPluginFullDesc(): JSX.Element {
    return (
      <div>
        <div>获取客户端缓存信息</div>
      </div>
    );
  }
  private viewCode = (mdPath) => () => {
    this.showMarkdownPopup(require(`./${mdPath}.md`));
  }

  private getWebviewCache = () => {
    getWebviewCache({
      projectTag: 'test_project',
      keys: ['key1', 'key2', 'key3', 'undefined'],
    }).then(result => {
      alert(JSON.stringify(result));
    }).catch(e => {
      alert('err' + JSON.stringify(e));
    });
  }
  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="body">
          <div className="play-body-item">
            <button className="exec" onClick={this.getWebviewCache}>获取客户端缓存信息</button>
            <button className="view" onClick={this.viewCode('get-webview-cache')}>查看代码</button>
          </div>
        </div>
      </div>
    );
  }
}
