import { Component, h, Event, Prop } from '@stencil/core';
import { changeNetwork, fetchSkillWallet } from '../../utils/utils';
import { ethers } from 'ethers';
import Portis from '@portis/web3';
export class UsersModal {
  constructor() {
    this.handleMetamaskClick = async () => {
      this.isLoadingEvent.emit(true);
      const { ethereum } = window;
      try {
        await changeNetwork();
        await ethereum.request({ method: 'eth_requestAccounts' });
        console.log(ethereum);
        // const web3Provider = new ethers.providers.Web3Provider(window.ethereum);
        const portis = new Portis('b86287a9-e792-4722-9487-477419f4470f', {
          nodeUrl: 'https://matic-mumbai.chainstacklabs.com/',
          chainId: '80001',
        });
        const web3Provider = new ethers.providers.Web3Provider(portis.provider);
        const addresses = await web3Provider.listAccounts();
        await fetchSkillWallet(web3Provider, addresses[0]);
        this.closeModalOnLogin.emit();
      }
      catch (error) {
        this.isLoadingEvent.emit(false);
        alert(error);
      }
    };
  }
  handleNewScreen(text) {
    this.showNewScreen.emit(text);
  }
  render() {
    return (h("div", { class: "modal-window-child" },
      h("div", { class: "wallet-header" },
        h("auth-image", { class: "white-wallet", image: 'https://skillwallet-demo-images.s3.us-east-2.amazonaws.com/wallet-white.svg' }),
        h("h2", null, this.isPartner ? 'I am a...' : 'Login with')),
      h("div", { class: "wallet-modal-button users-modal" },
        h("button", { onClick: () => this.showLoginMenu.emit() },
          h("auth-image", null),
          h("h4", null, this.isPartner ? 'Existing Partner' : 'SkillWallet')),
        h("button", { onClick: () => this.handleNewScreen(null), disabled: this.partnerKey === undefined ? true : false },
          h("auth-image", { image: 'https://skillwallet-demo-images.s3.us-east-2.amazonaws.com/plus-button-white.svg' }),
          h("h4", null, this.isPartner ? 'New Partner' : 'New User')))));
  }
  static get is() { return "users-modal"; }
  static get properties() { return {
    "isPartner": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Boolean",
        "resolved": "Boolean",
        "references": {
          "Boolean": {
            "location": "global"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "partnerKey": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "partner-key",
      "reflect": false
    },
    "isLoading": {
      "type": "boolean",
      "mutable": true,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "is-loading",
      "reflect": false
    }
  }; }
  static get events() { return [{
      "method": "showNewScreen",
      "name": "showNewScreen",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "any",
        "resolved": "any",
        "references": {}
      }
    }, {
      "method": "showLoginMenu",
      "name": "showLoginMenu",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "any",
        "resolved": "any",
        "references": {}
      }
    }, {
      "method": "closeModalOnLogin",
      "name": "closeModalOnLogin",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "any",
        "resolved": "any",
        "references": {}
      }
    }, {
      "method": "isLoadingEvent",
      "name": "isLoadingEvent",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "Boolean",
        "resolved": "Boolean",
        "references": {
          "Boolean": {
            "location": "global"
          }
        }
      }
    }]; }
}
