export type DetectedOS = 'windows' | 'mac' | 'ios' | 'android' | 'other';

/**
 * Erkennt das Besucher-OS clientseitig (SSR-safe: startet 'other', updated
 * onMounted). Für OS-aware Download-CTAs auf der Landing-Page.
 */
export function useOS() {
  const os = ref<DetectedOS>('other');

  onMounted(() => {
    const ua = (navigator.userAgent || '').toLowerCase();
    const platform = (navigator.platform || '').toLowerCase();
    const touch = navigator.maxTouchPoints || 0;

    if (/iphone|ipad|ipod/.test(ua) || (platform === 'macintel' && touch > 1)) {
      // iPadOS gibt sich als "MacIntel" mit Touchpoints aus.
      os.value = 'ios';
    } else if (/android/.test(ua)) {
      os.value = 'android';
    } else if (ua.includes('win') || platform.includes('win')) {
      os.value = 'windows';
    } else if (ua.includes('mac') || platform.includes('mac')) {
      os.value = 'mac';
    } else {
      os.value = 'other';
    }
  });

  return { os };
}
