import { Component, Event, h, Host, Prop, State } from '@stencil/core';
import { signIn } from '../../providers/auth/auth.ic';
import { IconDfinity } from '../icons/dfinity';
export class IcSignin {
  constructor() {
    this.signInInProgress = false;
  }
  async signUserIn() {
    this.inProgress.emit(true);
    this.signInInProgress = true;
    const signInSuccess = this.signInSuccess || (() => this.ddgSignInSuccess.emit());
    const signInError = this.signInError || ((err) => this.ddgSignInError.emit(err));
    await signIn({ onSuccess: signInSuccess, onError: signInError });
  }
  render() {
    return (h(Host, null,
      h("div", { class: "actions" },
        this.renderSpinner(),
        this.renderAction()),
      this.renderTerms()));
  }
  renderSpinner() {
    return (h("div", { class: `spinner ${!this.signInInProgress ? 'hidden' : ''}` },
      h("slot", { name: "spinner" })));
  }
  renderAction() {
    var _a;
    if (this.signInInProgress) {
      return undefined;
    }
    return (h("button", { onClick: async () => await this.signUserIn() },
      h(IconDfinity, null), (_a = this.i18n) === null || _a === void 0 ? void 0 :
      _a.sign_in.internet_identity));
  }
  renderTerms() {
    var _a, _b;
    const { terms, privacy } = this.config || {};
    return (h("p", { class: "terms" },
      "By continuing, you are indicating that you accept our",
      ' ',
      h("a", { href: terms, rel: "noopener norefferer", target: "_blank" }, (_a = this.i18n) === null || _a === void 0 ? void 0 : _a.links.terms_of_use),
      ' ',
      "and",
      ' ',
      h("a", { href: privacy, rel: "noopener norefferer", target: "_blank" }, (_b = this.i18n) === null || _b === void 0 ? void 0 : _b.links.privacy_policy),
      "."));
  }
  static get is() { return "deckgo-ic-signin"; }
  static get originalStyleUrls() { return {
    "$": ["ic-signin.scss"]
  }; }
  static get styleUrls() { return {
    "$": ["ic-signin.css"]
  }; }
  static get properties() { return {
    "i18n": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Record<string, Record<string, string>>",
        "resolved": "{ [x: string]: Record<string, string>; }",
        "references": {
          "Record": {
            "location": "global"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "config": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Record<string, string>",
        "resolved": "{ [x: string]: string; }",
        "references": {
          "Record": {
            "location": "global"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "signInSuccess": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "() => void",
        "resolved": "() => void",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "signInError": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "(err?: string) => void",
        "resolved": "(err?: string) => void",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    }
  }; }
  static get states() { return {
    "signInInProgress": {}
  }; }
  static get events() { return [{
      "method": "inProgress",
      "name": "inProgress",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      }
    }, {
      "method": "ddgSignInSuccess",
      "name": "ddgSignInSuccess",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "void",
        "resolved": "void",
        "references": {}
      }
    }, {
      "method": "ddgSignInError",
      "name": "ddgSignInError",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "string | undefined",
        "resolved": "string",
        "references": {}
      }
    }]; }
}
