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 { PortalVerifyEmailView, } from "./sqm-portal-verify-email-view";
import { usePortalVerifyEmail } from "./usePortalVerifyEmail";
import { getProps } from "../../utils/utils";
/**
 * @uiName Microsite Verify Email
 */
export class PortalVerifyEmail {
  constructor() {
    this.ignored = true;
    /**
     * Redirect participants to this page when they successfully verify their email.
     *
     * @uiName Successful verification redirect
     * @uiWidget pageSelect
     */
    this.nextPage = "/";
    /**
     * Redirect participants to this page if verification fails due to an outdated verification attempt.
     *
     * @uiName Failed verification redirect
     * @uiWidget pageSelect
     */
    this.failedPage = "/";
    /**
     * @uiName Verify email text
     * @uiWidget textArea
     */
    this.verifyEmailText = "Verify your email";
    /**
     * @uiName Email verification success text
     * @uiWidget textArea
     */
    this.verifySuccessText = "Your email has been verified and you are being redirected. If you are not redirected, please click Continue.";
    /**
     * @uiName Email verification invalid text
     * @uiWidget textArea
     */
    this.verifyInvalidText = "The email verification code is invalid or has expired, please try again.";
    /**
     * @uiName Continue text
     */
    this.continueText = "Continue";
    /**
     * Displayed when the email verification fails due to a network error. The participant can try refreshing the page.
     * @uiName Network error message
     */
    this.networkErrorMessage = "An error occurred while verifying your email. Please refresh the page and try again.";
    withHooks(this);
  }
  disconnectedCallback() { }
  render() {
    const { states, data, callbacks, content } = isDemo()
      ? usePortalVerifyEmailDemo(getProps(this))
      : usePortalVerifyEmail(getProps(this));
    return (h(PortalVerifyEmailView, { states: states, data: data, callbacks: callbacks, content: content }));
  }
  static get is() { return "sqm-portal-verify-email"; }
  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": "Successful verification redirect",
            "name": "uiName"
          }, {
            "text": "pageSelect",
            "name": "uiWidget"
          }],
        "text": "Redirect participants to this page when they successfully verify their email."
      },
      "attribute": "next-page",
      "reflect": false,
      "defaultValue": "\"/\""
    },
    "failedPage": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": "Failed verification redirect",
            "name": "uiName"
          }, {
            "text": "pageSelect",
            "name": "uiWidget"
          }],
        "text": "Redirect participants to this page if verification fails due to an outdated verification attempt."
      },
      "attribute": "failed-page",
      "reflect": false,
      "defaultValue": "\"/\""
    },
    "verifyEmailText": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": "Verify email text",
            "name": "uiName"
          }, {
            "text": "textArea",
            "name": "uiWidget"
          }],
        "text": ""
      },
      "attribute": "verify-email-text",
      "reflect": false,
      "defaultValue": "\"Verify your email\""
    },
    "verifySuccessText": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": "Email verification success text",
            "name": "uiName"
          }, {
            "text": "textArea",
            "name": "uiWidget"
          }],
        "text": ""
      },
      "attribute": "verify-success-text",
      "reflect": false,
      "defaultValue": "\"Your email has been verified and you are being redirected. If you are not redirected, please click Continue.\""
    },
    "verifyInvalidText": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": "Email verification invalid text",
            "name": "uiName"
          }, {
            "text": "textArea",
            "name": "uiWidget"
          }],
        "text": ""
      },
      "attribute": "verify-invalid-text",
      "reflect": false,
      "defaultValue": "\"The email verification code is invalid or has expired, please try again.\""
    },
    "continueText": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": "Continue text",
            "name": "uiName"
          }],
        "text": ""
      },
      "attribute": "continue-text",
      "reflect": false,
      "defaultValue": "\"Continue\""
    },
    "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 the email verification fails 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 email. Please refresh the page and try again.\""
    },
    "demoData": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "DemoData<PortalVerifyEmailViewProps>",
        "resolved": "{ states?: { error: string; loading: boolean; success: boolean; }; data?: { oobCode: string; }; content?: { verifySuccessText?: string; verifyEmailText?: string; verifyInvalidText?: string; continueText?: string; }; }",
        "references": {
          "DemoData": {
            "location": "import",
            "path": "../../global/demo"
          },
          "PortalVerifyEmailViewProps": {
            "location": "import",
            "path": "./sqm-portal-verify-email-view"
          }
        }
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [{
            "text": undefined,
            "name": "undocumented"
          }, {
            "text": "object",
            "name": "uiType"
          }],
        "text": ""
      }
    }
  }; }
  static get states() { return {
    "ignored": {}
  }; }
}
function usePortalVerifyEmailDemo(props) {
  return deepmerge({
    states: { error: "", loading: false, success: true },
    data: {
      oobCode: "code",
    },
    callbacks: {
      failed: () => {
        console.log("failed");
      },
      gotoNextPage: () => { },
    },
    content: {
      verifySuccessText: props.verifySuccessText,
      verifyEmailText: props.verifyEmailText,
      verifyInvalidText: props.verifyInvalidText,
      continueText: props.continueText,
    },
  }, props.demoData || {}, { arrayMerge: (_, a) => a });
}
