import { isDemo } from "@saasquatch/component-boilerplate";
import { withHooks } from "@saasquatch/stencil-hooks";
import { Component, h, Prop, State } from "@stencil/core";
import deepmerge from "deepmerge";
import { PortalEmailVerificationView, } from "./sqm-portal-email-verification-view";
import { usePortalEmailVerification } from "./usePortalEmailVerification";
/**
 * @uiName Microsite Email Verification
 */
export class PortalEmailVerification {
  constructor() {
    this.ignored = true;
    /**
     * Redirect participants to this page from their verification email.
     *
     * @uiName Email redirect
     * @uiWidget pageSelect
     */
    this.redirectPath = "/verifyEmail";
    /**
     * @uiName Email verification header text
     */
    this.emailVerificationHeader = "Verify your email";
    /**
     * @uiName Re-send email button text
     */
    this.resendEmailButtonText = "Re-send Email";
    /**
     * @uiName Email verification body text
     * @uiWidget textArea
     */
    this.verifyMessage = "A verification email was sent to {email}. Please verify your email to continue to the portal. Resending an email will invalidate the previous email.";
    /**
     * @uiName Email verification status text
     * @uiWidget textArea
     */
    this.verificationStatusMessage = "Checking verification status in {countdown}";
    /**
     * @uiName Email verification checking text
     * @uiWidget textArea
     */
    this.verificationLoadingMessage = "Checking verification status";
    /**
     * @uiName Email verification resent text
     * @uiWidget textArea
     */
    this.verificationResentMessage = "Your verification email has been resent successfully";
    /**
     * Displayed when your verification email fails to send due to a network error. The participant can try refreshing the page.
     * @uiName Network error message
     */
    this.networkErrorMessage = "An error occurred while verifying your password. Please refresh the page.";
    withHooks(this);
  }
  disconnectedCallback() { }
  render() {
    const { states, callbacks, content } = isDemo()
      ? usePortalEmailVerificationDemo(this)
      : usePortalEmailVerification(this);
    return (h(PortalEmailVerificationView, { states: states, callbacks: callbacks, content: content }));
  }
  static get is() { return "sqm-portal-email-verification"; }
  static get encapsulation() { return "shadow"; }
  static get properties() { return {
    "redirectPath": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": "Email redirect",
            "name": "uiName"
          }, {
            "text": "pageSelect",
            "name": "uiWidget"
          }],
        "text": "Redirect participants to this page from their verification email."
      },
      "attribute": "redirect-path",
      "reflect": false,
      "defaultValue": "\"/verifyEmail\""
    },
    "emailVerificationHeader": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": "Email verification header text",
            "name": "uiName"
          }],
        "text": ""
      },
      "attribute": "email-verification-header",
      "reflect": false,
      "defaultValue": "\"Verify your email\""
    },
    "resendEmailButtonText": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": "Re-send email button text",
            "name": "uiName"
          }],
        "text": ""
      },
      "attribute": "resend-email-button-text",
      "reflect": false,
      "defaultValue": "\"Re-send Email\""
    },
    "verifyMessage": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": "Email verification body text",
            "name": "uiName"
          }, {
            "text": "textArea",
            "name": "uiWidget"
          }],
        "text": ""
      },
      "attribute": "verify-message",
      "reflect": false,
      "defaultValue": "\"A verification email was sent to {email}. Please verify your email to continue to the portal. Resending an email will invalidate the previous email.\""
    },
    "verificationStatusMessage": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": "Email verification status text",
            "name": "uiName"
          }, {
            "text": "textArea",
            "name": "uiWidget"
          }],
        "text": ""
      },
      "attribute": "verification-status-message",
      "reflect": false,
      "defaultValue": "\"Checking verification status in {countdown}\""
    },
    "verificationLoadingMessage": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": "Email verification checking text",
            "name": "uiName"
          }, {
            "text": "textArea",
            "name": "uiWidget"
          }],
        "text": ""
      },
      "attribute": "verification-loading-message",
      "reflect": false,
      "defaultValue": "\"Checking verification status\""
    },
    "verificationResentMessage": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": "Email verification resent text",
            "name": "uiName"
          }, {
            "text": "textArea",
            "name": "uiWidget"
          }],
        "text": ""
      },
      "attribute": "verification-resent-message",
      "reflect": false,
      "defaultValue": "\"Your verification email has been resent successfully\""
    },
    "networkErrorMessage": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": "Network error message",
            "name": "uiName"
          }],
        "text": "Displayed when your verification email fails to send due to a network error. The participant can try refreshing the page."
      },
      "attribute": "network-error-message",
      "reflect": false,
      "defaultValue": "\"An error occurred while verifying your password. Please refresh the page.\""
    },
    "demoData": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "DemoData<PortalEmailVerificationViewProps>",
        "resolved": "{ states?: { error: string; loading: boolean; success: boolean; isVerified?: boolean; loadingVerification?: boolean; countdown?: number; }; content?: { email: string; verifyMessage: string; emailVerificationHeader: string; resendEmailButtonText: string; verificationStatusMessage?: string; verificationLoadingMessage?: string; verificationResentMessage?: string; }; }",
        "references": {
          "DemoData": {
            "location": "import",
            "path": "../../global/demo"
          },
          "PortalEmailVerificationViewProps": {
            "location": "import",
            "path": "./sqm-portal-email-verification-view"
          }
        }
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [{
            "text": undefined,
            "name": "undocumented"
          }, {
            "text": "object",
            "name": "uiType"
          }],
        "text": ""
      }
    }
  }; }
  static get states() { return {
    "ignored": {}
  }; }
}
function usePortalEmailVerificationDemo(props) {
  return deepmerge({
    states: { error: "", loading: false, success: false, countdown: 10 },
    callbacks: {
      submit: async (_event) => { },
    },
    content: {
      email: "test@example.com",
      verifyMessage: props.verifyMessage,
      emailVerificationHeader: props.emailVerificationHeader,
      resendEmailButtonText: props.resendEmailButtonText,
      verificationLoadingMessage: props.verificationLoadingMessage,
      verificationStatusMessage: props.verificationStatusMessage,
      verificationResentMessage: props.verificationResentMessage,
      networkErrorMessage: props.networkErrorMessage,
    },
  }, props.demoData || {}, { arrayMerge: (_, a) => a });
}
