import type { ImageSourcePropType } from 'react-native';

/**
 * Geräte-spezifische PNG-Icons (apps/rebreak-native/assets/devices).
 * React Native braucht statische require()-Pfade — daher das feste Mapping.
 */
const ICONS = {
  iphone: require('../../assets/devices/iphone.png'),
  android: require('../../assets/devices/android.png'),
  tablet: require('../../assets/devices/tablet.png'),
  macbook: require('../../assets/devices/macbook.png'),
  laptop: require('../../assets/devices/laptop.png'),
  computer: require('../../assets/devices/computer.png'),
} as const;

/**
 * Wählt das passende Geräte-PNG anhand Plattform (+ optional Modell-String).
 * Fällt auf `laptop` zurück (generischer Desktop).
 */
export function deviceImage(
  platform?: string | null,
  model?: string | null,
): ImageSourcePropType {
  const p = (platform ?? '').toLowerCase();
  const m = (model ?? '').toLowerCase();

  if (p.startsWith('ipad') || m.includes('ipad') || p.includes('tablet')) return ICONS.tablet;
  if (p.startsWith('ios') || p.startsWith('iphone') || m.includes('iphone')) return ICONS.iphone;
  if (p.startsWith('android')) return ICONS.android;
  if (p.startsWith('mac') || p === 'darwin' || m.includes('macbook') || m.includes('mac')) {
    return ICONS.macbook;
  }
  if (p.startsWith('win') || m.includes('windows')) return ICONS.computer;
  return ICONS.laptop;
}
