import { setWebviewBack } from '../../../../plugins/navbar';
import { PluginBase } from '../../PluginBase';
import { setNavbar, DisplayType } from '../../../../plugins/navbar';
import { Dialog } from '../../../components/modal/Dialog';
import { iconDarkBack } from '../../../components/icons';

export class SetNavbarNoGoback extends PluginBase {
  public getPluginShortDesc(): JSX.Element {
    return (
      <div>Webview头部标题栏禁用默认的goback能力。</div>
    );
  }
  public getPluginFullDesc(): JSX.Element {
    return (
      <div>
        <div>禁用标题栏默认的返回能力</div>
      </div>
    );
  }
  public componentDidMount() {
    setNavbar({
      left: {
        forbidBack: 'true',
        left: {
          tagName: 'back_tag_click',
        },
      },
      center: { left: { tagName: 'tag_click_center', type: DisplayType.Text, value: '自定义标题' } },
    }, (err, result) => {
      if (err) {
        alert(JSON.stringify(err));
      } else {
        if (result && result.tagName === 'back_tag_click') {
          Dialog.confirm({
            children: <div>点击确认返回</div>,
            onRight: () => {
              Dialog.close();
              setWebviewBack();
            },
          }, false);
        } else {
          alert(JSON.stringify(result));
        }
      }
    });
  }
  private webviewBack = () => {
    setWebviewBack();
  }
  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="body">
          <div className="play-body-item">
            <button onClick={this.webviewBack}>返回上一级</button>
            <button onClick={this.viewCode('navbar-no-goback')}>查看代码</button>
          </div>
        </div>
      </div>
    );
  }
}
