import { isDemo, navigation } from "@saasquatch/component-boilerplate";
import { withHooks } from "@saasquatch/stencil-hooks";
import { Component, h, Prop, State } from "@stencil/core";
import deepmerge from "deepmerge";
import { createStyleSheet } from "../../styling/JSS";
import { PortalLoginView, } from "../sqm-portal-login/sqm-portal-login-view";
import { usePortalLogin } from "../sqm-portal-login/usePortalLogin";
/**
 * @uiName Microsite Login
 */
export class PortalGoogleLogin {
  constructor() {
    this.ignored = true;
    /**
     * Redirect participants to this page after they successfully login.
     *
     * @uiName Login redirect
     * @uiWidget pageSelect
     */
    this.nextPage = "/";
    /**
     * @uiName Email field label
     */
    this.emailLabel = "Email";
    /**
     * @uiName Password field label
     */
    this.passwordLabel = "Password";
    /**
     * @uiName Submit button text
     */
    this.submitLabel = "Sign In";
    /**
     * Redirect participants to this page to reset their password
     * @uiName Forgot password redirect
     * @uiWidget pageSelect
     */
    this.forgotPasswordPath = "/forgotPassword";
    /**
     * @uiName Forgot password text
     */
    this.forgotPasswordLabel = "Forgot Password?";
    /**
     * @uiName Register button text
     */
    this.registerLabel = "Register";
    /**
     * Redirect participants to this page to start registration.
     * @uiName Register button redirect
     * @uiWidget pageSelect
     */
    this.registerPath = "/register";
    /**
     * @uiName Heading label
     * @uiWidget textArea
     */
    this.pageLabel = "Sign in to your account";
    /**
     * @uiName Network error message
     * Displayed when the login fails due to a network error. The participant can try refreshing the page.
     */
    this.networkErrorMessage = "An error occurred while logging you in. Please refresh the page and try again.";
    /**
     * @uiName Google account error message
     * Displayed when user tries to sign in with Google account but has not registered.
     */
    this.googleUserNotRegisteredError = "Your Google account has not registered on our platform. Please complete the registration process with your Google account.";
    /**
     * @uiName Register CTA
     */
    this.registerCTA = "Don't have an account?";
    withHooks(this);
  }
  disconnectedCallback() { }
  render() {
    const { states, callbacks } = isDemo()
      ? useLoginDemo(this)
      : usePortalLogin(this);
    const styles = {
      RegisterButton: {
        "&::part(label)": {
          padding: "0",
        },
      },
    };
    const sheet = createStyleSheet(styles);
    const styleString = sheet.toString();
    const content = {
      forgotPasswordButton: (h("slot", { name: "forgotPassword" },
        h("a", { part: "forgot-password-link", onClick: () => navigation.push(states.forgotPasswordPath) }, this.forgotPasswordLabel))),
      googleButton: (h("sqm-google-sign-in", { onInitComplete: callbacks.googleSubmit })),
      secondaryButton: (h("slot", { name: "secondaryButton" },
        h("style", null, styleString),
        h("span", null,
          this.registerCTA,
          " ",
          h("sl-button", { size: "large", type: "text", disabled: states.loading, onClick: () => navigation.push(states.registerPath), className: sheet.classes.RegisterButton }, this.registerLabel)))),
      emailLabel: this.emailLabel,
      passwordLabel: this.passwordLabel,
      submitLabel: this.submitLabel,
      pageLabel: this.pageLabel,
    };
    return (h(PortalLoginView, { states: states, callbacks: callbacks, content: content }));
  }
  static get is() { return "sqm-portal-google-login"; }
  static get encapsulation() { return "shadow"; }
  static get properties() { return {
    "nextPage": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": "Login redirect",
            "name": "uiName"
          }, {
            "text": "pageSelect",
            "name": "uiWidget"
          }],
        "text": "Redirect participants to this page after they successfully login."
      },
      "attribute": "next-page",
      "reflect": false,
      "defaultValue": "\"/\""
    },
    "emailLabel": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": "Email field label",
            "name": "uiName"
          }],
        "text": ""
      },
      "attribute": "email-label",
      "reflect": false,
      "defaultValue": "\"Email\""
    },
    "passwordLabel": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": "Password field label",
            "name": "uiName"
          }],
        "text": ""
      },
      "attribute": "password-label",
      "reflect": false,
      "defaultValue": "\"Password\""
    },
    "submitLabel": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": "Submit button text",
            "name": "uiName"
          }],
        "text": ""
      },
      "attribute": "submit-label",
      "reflect": false,
      "defaultValue": "\"Sign In\""
    },
    "forgotPasswordPath": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": "Forgot password redirect",
            "name": "uiName"
          }, {
            "text": "pageSelect",
            "name": "uiWidget"
          }],
        "text": "Redirect participants to this page to reset their password"
      },
      "attribute": "forgot-password-path",
      "reflect": false,
      "defaultValue": "\"/forgotPassword\""
    },
    "forgotPasswordLabel": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": "Forgot password text",
            "name": "uiName"
          }],
        "text": ""
      },
      "attribute": "forgot-password-label",
      "reflect": false,
      "defaultValue": "\"Forgot Password?\""
    },
    "registerLabel": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": "Register button text",
            "name": "uiName"
          }],
        "text": ""
      },
      "attribute": "register-label",
      "reflect": false,
      "defaultValue": "\"Register\""
    },
    "registerPath": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": "Register button redirect",
            "name": "uiName"
          }, {
            "text": "pageSelect",
            "name": "uiWidget"
          }],
        "text": "Redirect participants to this page to start registration."
      },
      "attribute": "register-path",
      "reflect": false,
      "defaultValue": "\"/register\""
    },
    "pageLabel": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": "Heading label",
            "name": "uiName"
          }, {
            "text": "textArea",
            "name": "uiWidget"
          }],
        "text": ""
      },
      "attribute": "page-label",
      "reflect": false,
      "defaultValue": "\"Sign in to your account\""
    },
    "networkErrorMessage": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": "Network error message\nDisplayed when the login fails due to a network error. The participant can try refreshing the page.",
            "name": "uiName"
          }],
        "text": ""
      },
      "attribute": "network-error-message",
      "reflect": false,
      "defaultValue": "\"An error occurred while logging you in. Please refresh the page and try again.\""
    },
    "googleUserNotRegisteredError": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": "Google account error message\nDisplayed when user tries to sign in with Google account but has not registered.",
            "name": "uiName"
          }],
        "text": ""
      },
      "attribute": "google-user-not-registered-error",
      "reflect": false,
      "defaultValue": "\"Your Google account has not registered on our platform. Please complete the registration process with your Google account.\""
    },
    "registerCTA": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": "Register CTA",
            "name": "uiName"
          }],
        "text": ""
      },
      "attribute": "register-c-t-a",
      "reflect": false,
      "defaultValue": "\"Don't have an account?\""
    },
    "demoData": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "DemoData<PortalLoginViewProps>",
        "resolved": "{ states?: { error: string; loading: boolean; forgotPasswordPath: string; registerPath: string; }; content?: { googleButton?: VNode; forgotPasswordButton?: any; secondaryButton?: any; emailLabel?: string; passwordLabel?: string; submitLabel?: string; pageLabel?: string; }; }",
        "references": {
          "DemoData": {
            "location": "import",
            "path": "../../global/demo"
          },
          "PortalLoginViewProps": {
            "location": "import",
            "path": "../sqm-portal-login/sqm-portal-login-view"
          }
        }
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [{
            "text": undefined,
            "name": "undocumented"
          }, {
            "text": "object",
            "name": "uiType"
          }],
        "text": ""
      }
    }
  }; }
  static get states() { return {
    "ignored": {}
  }; }
}
function useLoginDemo(props) {
  var _a, _b;
  return deepmerge({
    states: {
      error: ((_b = (_a = props.demoData) === null || _a === void 0 ? void 0 : _a.states) === null || _b === void 0 ? void 0 : _b.error) || "",
      loading: false,
      forgotPasswordPath: "/forgotPassword",
      registerPath: "/register",
      showLoginForm: "manual",
    },
    callbacks: {
      googleSubmit: async () => {
        console.log("google submit");
      },
      submit: async (_event) => {
        console.log("submit");
      },
    },
    content: {
      googleButton: null,
    },
  }, props.demoData || {}, { arrayMerge: (_, a) => a });
}
