import { r as registerInstance, h as h$1 } from './index-38ad4957.js';
import { n as h } from './dom-context-hooks.module-50442785.js';
import { d as dist, J, w as wn, s as setUserIdentity, i as isDemo } from './index.module-b23fdad8.js';
import { c as cjs } from './cjs-bdfb4486.js';
import { g as getProps } from './utils-334c1e34.js';
import './JSS-67b5cff8.js';
import { L as LogoutCurrentUserView } from './sqm-logout-current-user-view-376c1bf6.js';

const GET_USER_DETAILS = dist.gql `
  query getUserDetails {
    viewer {
      ... on User {
        id
        accountId
        email
      }
    }
  }
`;
function useLogoutCurrentUser(props) {
  var _a, _b;
  const user = J();
  const { loading, data } = wn(GET_USER_DETAILS, {}, !user);
  const onSwitchClick = () => {
    setUserIdentity(undefined);
  };
  const filledInEmailText = (_a = props.userIdentificationText) === null || _a === void 0 ? void 0 : _a.replace("{email}", (_b = data === null || data === void 0 ? void 0 : data.viewer) === null || _b === void 0 ? void 0 : _b.email);
  return {
    loading,
    onSwitchClick,
    filledInEmailText,
    ...props,
  };
}

const LogoutCurrentUser = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    /**
     * @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";
    h(this);
  }
  disconnectedCallback() { }
  render() {
    const props = isDemo()
      ? useDemoLogoutCurrentUser(this)
      : useLogoutCurrentUser(getProps(this));
    const content = {
      userIdentificationText: this.userIdentificationText,
      switchUserText: this.switchUserText,
      emailErrorText: this.emailErrorText,
    };
    return h$1(LogoutCurrentUserView, Object.assign({}, props, content));
  }
};
function useDemoLogoutCurrentUser(props) {
  return cjs({
    onSwitchClick: () => setUserIdentity(undefined),
    filledInEmailText: "john@example.com",
    switchUserText: props.switchUserText,
    emailErrorText: props.emailErrorText,
    loading: false,
  }, props.demoData || {}, { arrayMerge: (_, a) => a });
}

export { LogoutCurrentUser as sqm_logout_current_user };
