import { isDemo, setUserIdentity } from "@saasquatch/component-boilerplate";
import { Component, h, Prop } from "@stencil/core";
import deepmerge from "deepmerge";
import { LogoutCurrentUserView, } from "./sqm-logout-current-user-view";
import { useLogoutCurrentUser } from "./useLogoutCurrentUser";
import { withHooks } from "@saasquatch/stencil-hooks";
import { getProps } from "../../utils/utils";
/**
 * @uiName Sign out current user
 * @exampleGroup Instant Access
 * @compatibility Built for instant access
 * @validParents ["sqm-portal-container","template", "sqm-referred-registration", "sqb-auth-template-switch", "div","sqm-divided-layout","template","sqm-tab","sqb-program-section","sqb-conditional-section"]
 * @example Sign out current user - <sqm-logout-current-user user-identification-text="{email}" switch-user-link="#" switch-user-text="not you?"></sqm-logout-current-user>
 */
export class LogoutCurrentUser {
  constructor() {
    /**
     * @required
     * @uiName User identification text
     */
    this.userIdentificationText = "{email}";
    /**
     * @required
     * @uiName Switch user button label
     */
    this.switchUserText = "not you?";
    /**
     * @required
     * @uiName Error text
     */
    this.emailErrorText = "Error fetching email";
    withHooks(this);
  }
  disconnectedCallback() { }
  render() {
    const props = isDemo()
      ? useDemoLogoutCurrentUser(this)
      : useLogoutCurrentUser(getProps(this));
    const content = {
      userIdentificationText: this.userIdentificationText,
      switchUserText: this.switchUserText,
      emailErrorText: this.emailErrorText,
    };
    return h(LogoutCurrentUserView, Object.assign({}, props, content));
  }
  static get is() { return "sqm-logout-current-user"; }
  static get encapsulation() { return "shadow"; }
  static get properties() { return {
    "userIdentificationText": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": undefined,
            "name": "required"
          }, {
            "text": "User identification text",
            "name": "uiName"
          }],
        "text": ""
      },
      "attribute": "user-identification-text",
      "reflect": false,
      "defaultValue": "\"{email}\""
    },
    "switchUserText": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": undefined,
            "name": "required"
          }, {
            "text": "Switch user button label",
            "name": "uiName"
          }],
        "text": ""
      },
      "attribute": "switch-user-text",
      "reflect": false,
      "defaultValue": "\"not you?\""
    },
    "emailErrorText": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": undefined,
            "name": "required"
          }, {
            "text": "Error text",
            "name": "uiName"
          }],
        "text": ""
      },
      "attribute": "email-error-text",
      "reflect": false,
      "defaultValue": "\"Error fetching email\""
    },
    "demoData": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "DemoData<CopyTextViewProps>",
        "resolved": "{ loading?: boolean; textColor?: string; buttonType?: \"primary\" | \"secondary\"; copyString?: string; tooltiptext?: string; open?: boolean; copyButtonLabel?: string; disabled?: boolean; textAlign?: \"left\" | \"right\" | \"center\"; buttonStyle?: \"icon\" | \"button-outside\" | \"button-below\"; error?: boolean; errorText?: string; notificationText?: string; showNotificationText?: boolean; inputPlaceholderText?: string; dateAvailable?: string; isCopied?: boolean; backgroundColor?: string; borderRadius?: string; borderColor?: string; onClick?: () => void; }",
        "references": {
          "DemoData": {
            "location": "import",
            "path": "../../global/demo"
          },
          "CopyTextViewProps": {
            "location": "import",
            "path": "../views/copy-text-view"
          }
        }
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [{
            "text": undefined,
            "name": "required"
          }, {
            "text": "Switch user button link",
            "name": "uiName"
          }],
        "text": ""
      }
    }
  }; }
}
function useDemoLogoutCurrentUser(props) {
  return deepmerge({
    onSwitchClick: () => setUserIdentity(undefined),
    filledInEmailText: "john@example.com",
    switchUserText: props.switchUserText,
    emailErrorText: props.emailErrorText,
    loading: false,
  }, props.demoData || {}, { arrayMerge: (_, a) => a });
}
