"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.checkEmailExist = checkEmailExist;
exports.loginEmail = loginEmail;
exports.loginSocial = loginSocial;
exports.loginViaJwt = loginViaJwt;
exports.registerSocial = registerSocial;
exports.uploadFile = uploadFile;
var _apiClient = _interopRequireWildcard(require("../apiClient"));
var _roomStore = require("../../roomStore");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
// import {
//   getAuth,
//   GoogleAuthProvider,
//   signInWithPopup,
//   User as FirebaseUser,
// } from 'firebase/auth';
// import { app } from '../../../firebase-config';

// login functions
async function loginEmail(email, password) {
  const res = await _apiClient.default.post('/users/login-with-email', {
    email,
    password
  }, {
    headers: {
      Authorization: (0, _apiClient.getCurrentAppToken)()
    }
  });
  console.log('loginEmail res', res.data);
  return res;
}
function loginSocial(idToken, accessToken, loginType, authToken = 'authToken') {
  return _apiClient.default.post('/users/login', {
    idToken,
    accessToken,
    loginType,
    authToken
  }, {
    headers: {
      Authorization: (0, _apiClient.getCurrentAppToken)()
    }
  });
}
function registerSocial(idToken, accessToken, authToken, loginType, signUpPlan) {
  return _apiClient.default.post('/users', {
    idToken,
    accessToken,
    loginType,
    authToken: authToken,
    signupPlan: signUpPlan
  }, {
    headers: {
      Authorization: (0, _apiClient.getCurrentAppToken)()
    }
  });
}
function checkEmailExist(email) {
  return _apiClient.default.get('/users/checkEmail/' + email, {
    headers: {
      Authorization: (0, _apiClient.getCurrentAppToken)()
    }
  });
}
async function loginViaJwt(clientToken) {
  console.log('🟡 loginViaJwt: Sending JWT request to /users/client');
  const response = await _apiClient.default.post('/users/client', null, {
    headers: {
      'x-custom-token': clientToken
    }
  });
  console.log('✅ loginViaJwt: Received response', {
    hasUser: !!response.data.user,
    hasToken: !!response.data.token,
    hasRefreshToken: !!response.data.refreshToken,
    userData: response.data.user ? {
      _id: response.data.user._id,
      email: response.data.user.email,
      firstName: response.data.user.firstName,
      lastName: response.data.user.lastName,
      xmppUsername: response.data.user.xmppUsername
    } : null
  });
  const user = {
    ...response.data.user,
    refreshToken: response.data.refreshToken,
    token: response.data.token
  };
  return user;
}

// export const signInWithGoogle = async () => {
//   const auth = getAuth(app);
//   const googleProvider = new GoogleAuthProvider();
//   googleProvider.addScope('https://www.googleapis.com/auth/userinfo.email');
//   googleProvider.addScope('https://www.googleapis.com/auth/userinfo.profile');
//   try {
//     const res = await signInWithPopup(auth, googleProvider);
//     const user = res.user as FirebaseUser;
//     const idToken = await auth?.currentUser?.getIdToken();
//     const credential = GoogleAuthProvider.credentialFromResult(res);
//     return {
//       user,
//       idToken,
//       credential,
//     };
//   } catch (error) {
//     console.error(error);
//     return {};
//   }
// };

function uploadFile(formData) {
  const token = _roomStore.store.getState().chatSettingStore?.user?.token ?? '';
  return _apiClient.default.post('/files/', formData, {
    headers: {
      Authorization: token,
      Accept: '*/*',
      'Content-Type': 'multipart/form-data'
    }
  });
}
//# sourceMappingURL=auth.api.js.map