import { createRequire as _createRequire } from 'node:module';
const require = _createRequire(import.meta.url);
import {
  buildVerificationUris,
  isLoggedInToAccount,
  loginWithDeviceCode,
  requestDeviceCode
} from "./chunk-HWT3LUJJ.js";
import {
  wixCliLoginEnd,
  wixCliLoginStart
} from "./chunk-TOBTRYZF.js";
import "./chunk-7WVNO7VU.js";
import "./chunk-RPTAJN5Y.js";
import "./chunk-YL4347CI.js";
import "./chunk-TODKQSCF.js";
import "./chunk-AFPDHQYI.js";
import "./chunk-HYKBBZLS.js";
import "./chunk-C5RTKQVL.js";
import "./chunk-LU3R3EBR.js";
import "./chunk-XZUGLEBK.js";
import "./chunk-VASURI4S.js";
import "./chunk-SDLCFZRL.js";
import "./chunk-MTT3QXBC.js";
import {
  init_esm_shims
} from "./chunk-EXLZF52D.js";

// src/commands/non-interactive-login.ts
init_esm_shims();
function emit(event) {
  console.log(`${JSON.stringify(event)}
`);
}
async function nonInteractiveLogin({
  biLogger
}) {
  void biLogger.report(wixCliLoginStart({}));
  const loggedInUser = await isLoggedInToAccount();
  if (loggedInUser) {
    emit({
      email: loggedInUser.userInfo.email,
      event: "logged_in",
      userId: loggedInUser.userInfo.userId
    });
    void biLogger.report(wixCliLoginEnd({ isSuccess: true }));
    return;
  }
  const deviceCode = await requestDeviceCode();
  const { coloredVerificationUri } = buildVerificationUris(
    deviceCode.verificationUri
  );
  emit({
    event: "awaiting_user",
    expiresInSeconds: deviceCode.expiresIn,
    userCode: deviceCode.userCode,
    verificationUri: coloredVerificationUri
  });
  const controller = new AbortController();
  const { userInfo } = await loginWithDeviceCode(deviceCode, {
    signal: controller.signal
  });
  void biLogger.report(wixCliLoginEnd({ isSuccess: true }));
  emit({
    email: userInfo.email,
    event: "success",
    userId: userInfo.userId
  });
}
export {
  nonInteractiveLogin
};
//# sourceMappingURL=non-interactive-login-NN2AZQOM.js.map