import React from 'react';
import ModernUI from '@burner-wallet/modern-ui';
import { BurnerUIComponents, Page } from '@burner-wallet/ui-core';
import { WhiteRabbitPage, WhiteRabbitProvider, Loading } from '@whiterabbitjs/burner-plugin';

import Template from './Template';
import Header from './Header';

class WhiteRabbitUI extends ModernUI {

  getPages(): Page[] {
    const pages = super.getPages();

    const homePage = pages[0].component;

    const ProxyHomePage: React.FC<any> = ({ history }) => {
      const { whiterabbitUrl } = window as any;
      if (whiterabbitUrl) {
        history.push(whiterabbitUrl);
      }
      
      return React.createElement(homePage);
    };

    pages[0].component = ProxyHomePage;
    
    return pages;
  }

  burnerComponents(): BurnerUIComponents {
    const burnerComponents = super.burnerComponents();

    return {
      ...burnerComponents,
      Page: WhiteRabbitPage(burnerComponents.Page),
    };
  }

  content() {
    return (
      <WhiteRabbitProvider>
        <Template theme={this.props.theme}>
          {/* <Scanner /> */}
          <Loading />
          <Header title={this.props.title} />
          {this.router()}
        </Template>
      </WhiteRabbitProvider>
    );
  }
}

export default WhiteRabbitUI;
