import { Component, h, Prop, State, Event } from '@stencil/core';
import { joinCommunity } from '../../utils/utils';
import { defaultValidator, getValidator } from '../../validators/validator.factory.js';
export class RolesScreenNewUser {
  constructor() {
    this.isInvalid = false;
    this._commitmentValidator = defaultValidator;
  }
  componentWillLoad() {
    this._commitmentValidator = getValidator(this.validator['commitment']);
  }
  componentWillUpdate() {
    this._commitmentValidator = getValidator(this.validator['commitment']);
  }
  updateValue(event) {
    this.skill = parseInt(event.target.value);
    if (!getValidator({ name: 'commitment', options: { min: 1 } }).validate(this.skill)) {
      this.isInvalid = true;
    }
    else {
      this.isInvalid = false;
    }
    return this.isInvalid;
  }
  handleRoleClick(role) {
    this.roleSelected = role;
    this.buttonClass = '';
  }
  async handleUserQRClick() {
    this.isLoadingEvent.emit(true);
    const tokenId = await joinCommunity(this.web3Provider, this.community.address, window.sessionStorage.getItem('username'), this.roleSelected, this.skill);
    this.isLoadingEvent.emit(false);
    window.sessionStorage.setItem('tokenId', tokenId);
    this.showNewScreen.emit('role');
  }
  render() {
    return (h("div", { class: "roles-screen-new-user" },
      h("div", { class: "user-role-header" },
        h("h2", null,
          "Your Role in ",
          h("span", { style: { textDecoration: 'underline', fontWeight: 'bold' } }, this.community.name)),
        h("h3", null, "Pick what you're the best at & be rewarded for your commitment!")),
      (this.roleSelected) ?
        h("div", { class: "commitment-level-parent-div" },
          h("div", { class: "commitment-level-div" },
            h("div", { class: "commitment-level-text" },
              h("h3", null, this.roleSelected)),
            h("div", { class: "xp-component" },
              h("h4", null,
                "Your ",
                h("u", null, "Commitment Level")),
              h("p", null, "Tell your Community how much time you commit to this Role!"),
              (this.isInvalid) ? h("span", { class: "validation-error" }, " Your commitment level must be atleast 1") : null,
              h("div", { class: "bar-chart-first-container" },
                h("input", { class: "bar-chart-container", type: "range", id: "myRange", min: "1", max: "10", value: this.skill, onChange: (e) => this.updateValue(e), ref: ele => this.slider = ele }),
                h("div", { class: "bar-chart-metrics" },
                  h("p", null, "1"),
                  h("p", null, "10")))))) :
        h("div", { class: "role-fields" },
          h("div", { class: "role-button", onClick: () => this.handleRoleClick(this.community.roles[0]) },
            h("h4", null, this.community.roles[0])),
          h("div", { class: "role-button", onClick: () => this.handleRoleClick(this.community.roles[1]) },
            h("h4", null, this.community.roles[1])),
          h("div", { class: "role-button", onClick: () => this.handleRoleClick(this.community.roles[2]) },
            h("h4", null, this.community.roles[2]))),
      h("button", { onClick: () => this.handleUserQRClick(), class: this.buttonClass, disabled: !this.roleSelected || this.isInvalid || this.isLoading }, "That's it - join this community!")));
  }
  static get is() { return "roles-screen-new-user"; }
  static get encapsulation() { return "shadow"; }
  static get originalStyleUrls() { return {
    "$": ["skillwallet-auth.css"]
  }; }
  static get styleUrls() { return {
    "$": ["skillwallet-auth.css"]
  }; }
  static get properties() { return {
    "roleSelected": {
      "type": "string",
      "mutable": true,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "role-selected",
      "reflect": false
    },
    "isLoading": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "is-loading",
      "reflect": false
    },
    "buttonClass": {
      "type": "string",
      "mutable": true,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "button-class",
      "reflect": false
    },
    "community": {
      "type": "any",
      "mutable": false,
      "complexType": {
        "original": "any",
        "resolved": "any",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "community",
      "reflect": false
    },
    "isPartner": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Boolean",
        "resolved": "Boolean",
        "references": {
          "Boolean": {
            "location": "global"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "web3Provider": {
      "type": "any",
      "mutable": true,
      "complexType": {
        "original": "any",
        "resolved": "any",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "web-3-provider",
      "reflect": false
    },
    "skill": {
      "type": "number",
      "mutable": true,
      "complexType": {
        "original": "number",
        "resolved": "number",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "skill",
      "reflect": false
    },
    "validator": {
      "type": "any",
      "mutable": false,
      "complexType": {
        "original": "string | any",
        "resolved": "any",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "validator",
      "reflect": false
    }
  }; }
  static get states() { return {
    "isInvalid": {}
  }; }
  static get events() { return [{
      "method": "showNewScreen",
      "name": "showNewScreen",
      "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"
          }
        }
      }
    }]; }
}
