import { withHooks } from "@saasquatch/stencil-hooks";
import { Component, h, Prop } from "@stencil/core";
import { useWidgetEmailVerification } from "./useEmailVerification";
import { WidgetEmailVerificationView, } from "./sqm-email-verification-view";
import { getProps } from "../../../utils/utils";
import { isDemo, useSetParent } from "@saasquatch/component-boilerplate";
import deepmerge from "deepmerge";
import { SHOW_CODE_NAMESPACE } from "../keys";
/**
 * @uiName Widget Verification Gate
 */
export class WidgetEmailVerification {
  constructor() {
    /**
     * @uiName Verify email widget header text
     */
    this.verifyEmailHeaderText = "Start by verifying your email. We’ll send you a code through our referral provider, impact.com.";
    /**
     * @uiName Send code to email alert header
     */
    this.sendCodeErrorHeader = "There was an error sending your code";
    /**
     * @uiName Support link text
     */
    this.supportLink = "support team";
    /**
     * @uiName Send code to email alert description
     */
    this.sendCodeErrorDescription = "Please try again. If this problem continues, contact our program {supportLink}.";
    /**
     * @uiName Email input label
     */
    this.emailLabel = "Email";
    /**
     * @uiName Send code button text
     */
    this.sendCodeText = "Send code";
    /**
     * @uiName Send code button text
     */
    this.emailValidationErrorText = "Please enter a valid email";
    withHooks(this);
  }
  disconnectedCallback() { }
  getTextProps() {
    return getProps(this);
  }
  render() {
    const props = isDemo()
      ? useDemoWidgetEmailVerification(this)
      : useWidgetEmailVerification(this);
    return h(WidgetEmailVerificationView, Object.assign({}, props));
  }
  static get is() { return "sqm-email-verification"; }
  static get encapsulation() { return "shadow"; }
  static get properties() { return {
    "verifyEmailHeaderText": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": "Verify email widget header text",
            "name": "uiName"
          }],
        "text": ""
      },
      "attribute": "verify-email-header-text",
      "reflect": false,
      "defaultValue": "\"Start by verifying your email. We\u2019ll send you a code through our referral provider, impact.com.\""
    },
    "sendCodeErrorHeader": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": "Send code to email alert header",
            "name": "uiName"
          }],
        "text": ""
      },
      "attribute": "send-code-error-header",
      "reflect": false,
      "defaultValue": "\"There was an error sending your code\""
    },
    "supportLink": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": "Support link text",
            "name": "uiName"
          }],
        "text": ""
      },
      "attribute": "support-link",
      "reflect": false,
      "defaultValue": "\"support team\""
    },
    "sendCodeErrorDescription": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": "Send code to email alert description",
            "name": "uiName"
          }],
        "text": ""
      },
      "attribute": "send-code-error-description",
      "reflect": false,
      "defaultValue": "\"Please try again. If this problem continues, contact our program {supportLink}.\""
    },
    "emailLabel": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": "Email input label",
            "name": "uiName"
          }],
        "text": ""
      },
      "attribute": "email-label",
      "reflect": false,
      "defaultValue": "\"Email\""
    },
    "sendCodeText": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": "Send code button text",
            "name": "uiName"
          }],
        "text": ""
      },
      "attribute": "send-code-text",
      "reflect": false,
      "defaultValue": "\"Send code\""
    },
    "emailValidationErrorText": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": "Send code button text",
            "name": "uiName"
          }],
        "text": ""
      },
      "attribute": "email-validation-error-text",
      "reflect": false,
      "defaultValue": "\"Please enter a valid email\""
    },
    "demoData": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "DemoData<WidgetEmailVerificationViewProps>",
        "resolved": "{ states?: { error: boolean; initialLoading: boolean; loading: boolean; email: string; sendCodeError: boolean; }; }",
        "references": {
          "DemoData": {
            "location": "import",
            "path": "../../../global/demo"
          },
          "WidgetEmailVerificationViewProps": {
            "location": "import",
            "path": "./sqm-email-verification-view"
          }
        }
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [{
            "text": undefined,
            "name": "undocumented"
          }, {
            "text": "object",
            "name": "uiType"
          }],
        "text": ""
      }
    }
  }; }
}
function useDemoWidgetEmailVerification(props) {
  const setShowCode = useSetParent(SHOW_CODE_NAMESPACE);
  return deepmerge({
    states: {
      error: true,
      initialLoading: false,
      loading: false,
      email: "test@example.com",
      sendCodeError: true,
    },
    callbacks: {
      submitEmail: async () => setShowCode(true),
    },
    text: props.getTextProps(),
  }, props.demoData || {}, { arrayMerge: (_, a) => a });
}
