import { Component, Event, h, Prop, State } from "@stencil/core";
import * as authly from "authly";
import { Key } from "@payfunc/model";
import { Handler } from "../Handler";
export class CustomerLogin {
  constructor() {
    this.apiKeys = [];
    this.open = true;
    this.expired = false;
  }
  componentWillLoad() {
    Handler.client.me.customerKeys.forEach(async (key) => {
      const apikey = await Key.getVerifier()
        .add(authly.Property.Remover.create(["exp"]))
        .verify(key, "customer");
      if (apikey)
        this.apiKeys = [...this.apiKeys, apikey];
    });
  }
  async login(index) {
    this.selected.emit([Handler.client.me.customerKeys[index], this.apiKeys[index]]);
    this.open = false;
  }
  render() {
    return [
      this.apiKeys.length > 0 ? (h("smoothly-dialog", { open: this.open, header: "Intergiro Customer" }, this.apiKeys.map((key, index) => (h("smoothly-display", { onClick: () => this.login(index) }, key.name + " " + key.customer))))) : (""),
    ];
  }
  static get is() { return "customer-login"; }
  static get encapsulation() { return "scoped"; }
  static get originalStyleUrls() { return {
    "$": ["style.css"]
  }; }
  static get styleUrls() { return {
    "$": ["style.css"]
  }; }
  static get properties() { return {
    "open": {
      "type": "boolean",
      "mutable": true,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "open",
      "reflect": false,
      "defaultValue": "true"
    }
  }; }
  static get states() { return {
    "apiKeys": {},
    "expired": {}
  }; }
  static get events() { return [{
      "method": "selected",
      "name": "selected",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "any",
        "resolved": "any",
        "references": {}
      }
    }]; }
}
