"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useDeviceManagement = void 0;
var _react = require("react");
var _deviceManager = require("../../../utils/deviceManager");
var _errorHandlers = require("../utils/errorHandlers");
/**
 * Provide device session management helpers tied to the current active session.
 *
 * @param options - Device management configuration
 */
const useDeviceManagement = ({
  oxyServices,
  activeSessionId,
  onError,
  clearSessionState,
  logger
}) => {
  const getDeviceSessions = (0, _react.useCallback)(async () => {
    if (!activeSessionId) throw new Error('No active session');
    try {
      return await oxyServices.getDeviceSessions(activeSessionId);
    } catch (error) {
      (0, _errorHandlers.handleAuthError)(error, {
        defaultMessage: 'Failed to get device sessions',
        code: 'GET_DEVICE_SESSIONS_ERROR',
        onError,
        logger
      });
      throw error instanceof Error ? error : new Error('Failed to get device sessions');
    }
  }, [activeSessionId, logger, onError, oxyServices]);
  const logoutAllDeviceSessions = (0, _react.useCallback)(async () => {
    if (!activeSessionId) throw new Error('No active session');
    try {
      await oxyServices.logoutAllDeviceSessions(activeSessionId);
      await clearSessionState();
    } catch (error) {
      (0, _errorHandlers.handleAuthError)(error, {
        defaultMessage: 'Failed to logout all device sessions',
        code: 'LOGOUT_ALL_DEVICES_ERROR',
        onError,
        logger
      });
      throw error instanceof Error ? error : new Error('Failed to logout all device sessions');
    }
  }, [activeSessionId, clearSessionState, logger, onError, oxyServices]);
  const updateDeviceName = (0, _react.useCallback)(async deviceName => {
    if (!activeSessionId) throw new Error('No active session');
    try {
      await oxyServices.updateDeviceName(activeSessionId, deviceName);
      await _deviceManager.DeviceManager.updateDeviceName(deviceName);
    } catch (error) {
      (0, _errorHandlers.handleAuthError)(error, {
        defaultMessage: 'Failed to update device name',
        code: 'UPDATE_DEVICE_NAME_ERROR',
        onError,
        logger
      });
      throw error instanceof Error ? error : new Error('Failed to update device name');
    }
  }, [activeSessionId, logger, onError, oxyServices]);
  return {
    getDeviceSessions,
    logoutAllDeviceSessions,
    updateDeviceName
  };
};
exports.useDeviceManagement = useDeviceManagement;
//# sourceMappingURL=useDeviceManagement.js.map