// A util class to return new settings object based on settings key
import frameSettingsOpts from '~/store/frameSettingsOpts.json';

function getSetting(settingKey, newValue, sectionSettings) {
	const setting = {};
	switch (settingKey) {
		case 'sleepWhenNoMotionDetected':
		case 'sleepMotionTime':
			setting.sleepWhenNoMotionDetected =
				(sectionSettings.sleepWhenNoMotionDetected === frameSettingsOpts.sleepWhenNoMotionDetected.disabled) ?
					sectionSettings.sleepWhenNoMotionDetected :
					sectionSettings.sleepMotionTime;
			break;
		case 'sleepInterval':
		case 'sleepIntervalStartH':
		case 'sleepIntervalStartM':
		case 'sleepIntervalEndH':
		case 'sleepIntervalEndM':
			setting.sleepInterval = sectionSettings.sleepInterval;
			setting.sleepIntervalStartTime = [sectionSettings.sleepIntervalStartH, sectionSettings.sleepIntervalStartM].join(':');
			setting.sleepIntervalEndTime = [sectionSettings.sleepIntervalEndH, sectionSettings.sleepIntervalEndM].join(':');
			break;
		case 'clockSlideshow':
			setting.clockSlideshow =
				(newValue === frameSettingsOpts.clockSlideshow.disabled) ?
					frameSettingsOpts.clockSlideshow.disabled : frameSettingsOpts.clockSlideshow.enabled;
			break;
		case 'clockSlideshowDisplay':
			setting.clockSlideshow = newValue;
			break;
		default:
			setting[settingKey] = newValue;
			break;
	}
	return setting;
}

export { getSetting };
