function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
/**
 * 注册流程配置和状态管理
 * 支持多种验证方式的不同步骤流程
 */

/** 注册步骤类型 */
export var RegisterStep = /*#__PURE__*/function (RegisterStep) {
  RegisterStep["INITIAL_FORM"] = "INITIAL_FORM";
  RegisterStep["WAIT_EMAIL_LINK"] = "WAIT_EMAIL_LINK";
  RegisterStep["INPUT_VERIFICATION_CODE"] = "INPUT_VERIFICATION_CODE";
  RegisterStep["VERIFICATION_SUCCESS"] = "VERIFICATION_SUCCESS";
  RegisterStep["SET_PASSWORD"] = "SET_PASSWORD";
  RegisterStep["EMAIL_ALREADY_REGISTERED"] = "EMAIL_ALREADY_REGISTERED";
  RegisterStep["COMPLETE"] = "COMPLETE";
  return RegisterStep;
}({});

/** 验证方式类型 */
export var VerificationMethod = /*#__PURE__*/function (VerificationMethod) {
  VerificationMethod["EMAIL_LINK"] = "EMAIL_LINK";
  VerificationMethod["EMAIL_CODE"] = "EMAIL_CODE";
  VerificationMethod["PHONE_CODE"] = "PHONE_CODE";
  VerificationMethod["PASSWORD_ONLY"] = "PASSWORD_ONLY";
  return VerificationMethod;
}({});

/** 注册流程配置 */

/** 注册流程步骤定义 */

/** 注册流程数据 */

/** 预定义流程配置 */
export var REGISTER_FLOW_CONFIGS = _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, VerificationMethod.EMAIL_LINK, {
  verificationMethod: VerificationMethod.EMAIL_LINK,
  requirePasswordAtStart: true
}), VerificationMethod.EMAIL_CODE, {
  verificationMethod: VerificationMethod.EMAIL_CODE,
  requirePasswordAtStart: false,
  autoTransition: _defineProperty({}, RegisterStep.VERIFICATION_SUCCESS, {
    delay: 1500,
    nextStep: RegisterStep.SET_PASSWORD
  })
}), VerificationMethod.PHONE_CODE, {
  verificationMethod: VerificationMethod.PHONE_CODE,
  requirePasswordAtStart: false,
  autoTransition: _defineProperty({}, RegisterStep.VERIFICATION_SUCCESS, {
    delay: 1500,
    nextStep: RegisterStep.SET_PASSWORD
  })
}), VerificationMethod.PASSWORD_ONLY, {
  verificationMethod: VerificationMethod.PASSWORD_ONLY,
  requirePasswordAtStart: true
});

/** 步骤流转映射 */
export var STEP_TRANSITIONS = _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, VerificationMethod.EMAIL_LINK, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, RegisterStep.INITIAL_FORM, [RegisterStep.WAIT_EMAIL_LINK, RegisterStep.EMAIL_ALREADY_REGISTERED]), RegisterStep.WAIT_EMAIL_LINK, [RegisterStep.COMPLETE, RegisterStep.INITIAL_FORM]), RegisterStep.EMAIL_ALREADY_REGISTERED, [RegisterStep.INITIAL_FORM]), RegisterStep.INPUT_VERIFICATION_CODE, []), RegisterStep.VERIFICATION_SUCCESS, []), RegisterStep.SET_PASSWORD, []), RegisterStep.COMPLETE, [])), VerificationMethod.EMAIL_CODE, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, RegisterStep.INITIAL_FORM, [RegisterStep.INPUT_VERIFICATION_CODE, RegisterStep.EMAIL_ALREADY_REGISTERED]), RegisterStep.INPUT_VERIFICATION_CODE, [RegisterStep.VERIFICATION_SUCCESS, RegisterStep.INITIAL_FORM]), RegisterStep.VERIFICATION_SUCCESS, [RegisterStep.SET_PASSWORD]), RegisterStep.SET_PASSWORD, [RegisterStep.COMPLETE]), RegisterStep.EMAIL_ALREADY_REGISTERED, [RegisterStep.INITIAL_FORM]), RegisterStep.WAIT_EMAIL_LINK, []), RegisterStep.COMPLETE, [])), VerificationMethod.PHONE_CODE, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, RegisterStep.INITIAL_FORM, [RegisterStep.INPUT_VERIFICATION_CODE, RegisterStep.EMAIL_ALREADY_REGISTERED]), RegisterStep.INPUT_VERIFICATION_CODE, [RegisterStep.VERIFICATION_SUCCESS, RegisterStep.INITIAL_FORM]), RegisterStep.VERIFICATION_SUCCESS, [RegisterStep.SET_PASSWORD]), RegisterStep.SET_PASSWORD, [RegisterStep.COMPLETE]), RegisterStep.EMAIL_ALREADY_REGISTERED, [RegisterStep.INITIAL_FORM]), RegisterStep.WAIT_EMAIL_LINK, []), RegisterStep.COMPLETE, [])), VerificationMethod.PASSWORD_ONLY, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, RegisterStep.INITIAL_FORM, [RegisterStep.COMPLETE, RegisterStep.EMAIL_ALREADY_REGISTERED]), RegisterStep.EMAIL_ALREADY_REGISTERED, [RegisterStep.INITIAL_FORM]), RegisterStep.INPUT_VERIFICATION_CODE, []), RegisterStep.VERIFICATION_SUCCESS, []), RegisterStep.SET_PASSWORD, []), RegisterStep.WAIT_EMAIL_LINK, []), RegisterStep.COMPLETE, []));

/** 步骤定义映射 */
export var STEP_DEFINITIONS = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, RegisterStep.INITIAL_FORM, {
  step: RegisterStep.INITIAL_FORM,
  component: 'form',
  config: {
    showBack: true,
    showClose: true,
    canEditAccount: true,
    showResend: false
  }
}), RegisterStep.WAIT_EMAIL_LINK, {
  step: RegisterStep.WAIT_EMAIL_LINK,
  component: 'waiting',
  config: {
    showBack: true,
    showClose: true,
    canEditAccount: true,
    showResend: true
  }
}), RegisterStep.INPUT_VERIFICATION_CODE, {
  step: RegisterStep.INPUT_VERIFICATION_CODE,
  component: 'code-input',
  config: {
    showBack: true,
    showClose: true,
    canEditAccount: false,
    showResend: true
  }
}), RegisterStep.VERIFICATION_SUCCESS, {
  step: RegisterStep.VERIFICATION_SUCCESS,
  component: 'success',
  config: {
    showBack: false,
    showClose: false,
    canEditAccount: false,
    showResend: false
  }
}), RegisterStep.SET_PASSWORD, {
  step: RegisterStep.SET_PASSWORD,
  component: 'password-set',
  config: {
    showBack: true,
    showClose: true,
    canEditAccount: false,
    showResend: false
  }
}), RegisterStep.EMAIL_ALREADY_REGISTERED, {
  step: RegisterStep.EMAIL_ALREADY_REGISTERED,
  component: 'error',
  config: {
    showBack: true,
    showClose: true,
    canEditAccount: true,
    showResend: false
  }
}), RegisterStep.COMPLETE, {
  step: RegisterStep.COMPLETE,
  component: 'success',
  config: {
    showBack: false,
    showClose: false,
    canEditAccount: false,
    showResend: false
  }
});

/**
 * 验证步骤流转是否合法
 */
export function isValidTransition(verificationMethod, fromStep, toStep) {
  var _STEP_TRANSITIONS$ver;
  var validNextSteps = ((_STEP_TRANSITIONS$ver = STEP_TRANSITIONS[verificationMethod]) === null || _STEP_TRANSITIONS$ver === void 0 ? void 0 : _STEP_TRANSITIONS$ver[fromStep]) || [];
  return validNextSteps.includes(toStep);
}

/**
 * 获取步骤配置
 */
export function getStepDefinition(step) {
  return STEP_DEFINITIONS[step];
}

/**
 * 获取流程配置
 */
export function getFlowConfig(verificationMethod) {
  return REGISTER_FLOW_CONFIGS[verificationMethod];
}

/**
 * 根据认证配置决定使用哪种验证方式
 */
export function determineVerificationMethod(accountType, emailConfig, phoneConfig) {
  if (accountType === 'email') {
    // 邮箱注册
    if ((emailConfig === null || emailConfig === void 0 ? void 0 : emailConfig.require_email_verification) !== false) {
      // 默认使用验证码方式
      // TODO: 这里可以根据更多配置决定是用链接还是验证码
      return VerificationMethod.EMAIL_CODE;
    }
    return VerificationMethod.PASSWORD_ONLY;
  } else {
    // 手机号注册
    if ((phoneConfig === null || phoneConfig === void 0 ? void 0 : phoneConfig.require_phone_verification) !== false) {
      return VerificationMethod.PHONE_CODE;
    }
    return VerificationMethod.PASSWORD_ONLY;
  }
}