'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-8277cbb3.js');
const domContextHooks_module = require('./dom-context-hooks.module-e7b6727c.js');
const index_module = require('./index.module-f8c8495f.js');
const cjs = require('./cjs-1066ec21.js');
const utils = require('./utils-6847bc06.js');
require('./JSS-8503a151.js');
const sqmLogoutCurrentUserView = require('./sqm-logout-current-user-view-f330d641.js');

const GET_USER_DETAILS = index_module.dist.gql `
  query getUserDetails {
    viewer {
      ... on User {
        id
        accountId
        email
      }
    }
  }
`;
function useLogoutCurrentUser(props) {
  var _a, _b;
  const user = index_module.J();
  const { loading, data } = index_module.wn(GET_USER_DETAILS, {}, !user);
  const onSwitchClick = () => {
    index_module.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) {
    index.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";
    domContextHooks_module.h$1(this);
  }
  disconnectedCallback() { }
  render() {
    const props = index_module.isDemo()
      ? useDemoLogoutCurrentUser(this)
      : useLogoutCurrentUser(utils.getProps(this));
    const content = {
      userIdentificationText: this.userIdentificationText,
      switchUserText: this.switchUserText,
      emailErrorText: this.emailErrorText,
    };
    return index.h(sqmLogoutCurrentUserView.LogoutCurrentUserView, Object.assign({}, props, content));
  }
};
function useDemoLogoutCurrentUser(props) {
  return cjs.cjs({
    onSwitchClick: () => index_module.setUserIdentity(undefined),
    filledInEmailText: "john@example.com",
    switchUserText: props.switchUserText,
    emailErrorText: props.emailErrorText,
    loading: false,
  }, props.demoData || {}, { arrayMerge: (_, a) => a });
}

exports.sqm_logout_current_user = LogoutCurrentUser;
