"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.subscribeToPushNotifications = subscribeToPushNotifications;
var _axios = _interopRequireDefault(require("axios"));
var _reactNative = require("react-native");
var _roomStore = require("../../roomStore");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const PUSH_API_URL = 'https://push.ethoradev.com/api/v1';
const pushAxios = _axios.default.create({
  baseURL: PUSH_API_URL,
  headers: {
    'Content-Type': 'application/json'
  }
});
async function subscribeToPushNotifications(fcmToken, userJid, projectName = '') {
  const deviceType = _reactNative.Platform.select({
    ios: 'ios',
    android: 'android',
    default: 'web'
  });
  const payload = {
    projectId: projectName,
    registrationToken: fcmToken,
    deviceType,
    jid: `${userJid}@xmpp.ethoradev.com`
  };
  console.log('payload', payload);
  try {
    const token = _roomStore.store.getState().chatSettingStore?.user?.token || '';
    const response = await pushAxios.post('/subscriptions', payload, {
      headers: {
        Authorization: `Bearer ${token}`
      }
    });
    console.log('Successfully subscribed to push notifications', response.data);
    return response.data;
  } catch (error) {
    console.error('Failed to subscribe to push notifications:', error);
  }
}
//# sourceMappingURL=push.api.js.map