const settingsService = require('../../store/settings-store.js') const themeService = require('../../store/theme-store.js') const transport = require('../../transport/ble-core.js') const bootloaderService = require('../bootloader/service.js') const toolNavigation = require('../tools/navigation.js') function getSettingsPageState( settingsState = settingsService.getState(), themeState = themeService.getState(), transportState = transport.getState(), bootloaderState = bootloaderService.getState() ) { const nightModeEnabledSwitch = settingsState.nightModeFollowSystem ? themeState.themeMode === 'dark' : settingsState.nightModeEnabled const modbusProtocolOptions = settingsService.MODBUS_PROTOCOL_OPTIONS const modbusProtocolIndex = Math.max(0, modbusProtocolOptions.findIndex((option) => ( option.key === settingsState.modbusProtocolMode ))) const modbusProtocol = modbusProtocolOptions[modbusProtocolIndex] || modbusProtocolOptions[0] return { ...settingsState, ...themeState, ...bootloaderState, connectedDevice: transportState.connectedDevice, genericModbusMinPacketLength: settingsService.GENERIC_MODBUS_MIN_PACKET_LENGTH, isGenericProtocol: modbusProtocol.key === 'generic', isPrivateProtocol: modbusProtocol.key === 'private', modbusProtocolIndex, modbusProtocolOptions, modbusProtocolText: modbusProtocol.label, nightModeEnabledSwitch, statusPollMaxInterval: settingsService.STATUS_POLL_MAX_INTERVAL, statusPollMinInterval: settingsService.STATUS_POLL_MIN_INTERVAL, toolEntries: toolNavigation.getToolEntries() } } module.exports = { getSettingsPageState }