import type { NotificationPosition } from '../components/Notifications/CustomNotification';

export function isNotificationsEnabled(): boolean {
  try {
    const s = JSON.parse(localStorage.getItem('launcher_settings') || '{}');
    return s.notifications !== false; // по умолчанию true
  } catch {
    return true;
  }
}

export function positionFromSettingValue(
  v: string | undefined,
): NotificationPosition {
  switch (v) {
    case 'top-left':
      return { vertical: 'top', horizontal: 'left' };
    case 'top-center':
      return { vertical: 'top', horizontal: 'center' };
    case 'top-right':
      return { vertical: 'top', horizontal: 'right' };
    case 'bottom-left':
      return { vertical: 'bottom', horizontal: 'left' };
    case 'bottom-center':
      return { vertical: 'bottom', horizontal: 'center' };
    case 'bottom-right':
    default:
      return { vertical: 'bottom', horizontal: 'right' };
  }
}

export function getNotifPositionFromSettings(): NotificationPosition {
  try {
    const s = JSON.parse(localStorage.getItem('launcher_settings') || '{}');
    return positionFromSettingValue(s.notificationPosition);
  } catch {
    return { vertical: 'top', horizontal: 'right' };
  }
}
