import {
  describe,
  expect,
  it
} from 'vitest';

import {
  detectRuntimePlatform,
  isCapacitorNativeRuntime,
  shouldUseMobileAttachmentPicker,
  type RuntimePlatform
} from './platform-detection.rules';

describe('platform-detection.rules', () => {
  describe('detectRuntimePlatform', () => {
    it('prefers electron when the preload API is present', () => {
      expect(
        detectRuntimePlatform({
          hasElectronApi: true,
          capacitorIsNative: true
        })
      ).toBe<RuntimePlatform>('electron');
    });

    it('detects capacitor when running in a native shell without electron', () => {
      expect(
        detectRuntimePlatform({
          hasElectronApi: false,
          capacitorIsNative: true
        })
      ).toBe<RuntimePlatform>('capacitor');
    });

    it('falls back to browser for web runtimes', () => {
      expect(
        detectRuntimePlatform({
          hasElectronApi: false,
          capacitorIsNative: false
        })
      ).toBe<RuntimePlatform>('browser');
    });
  });

  describe('shouldUseMobileAttachmentPicker', () => {
    it('enables the picker on capacitor native and mobile web viewports', () => {
      expect(shouldUseMobileAttachmentPicker('capacitor', true)).toBe(true);
      expect(shouldUseMobileAttachmentPicker('browser', true)).toBe(true);
    });

    it('keeps drag-and-drop on desktop browser and electron', () => {
      expect(shouldUseMobileAttachmentPicker('browser', false)).toBe(false);
      expect(shouldUseMobileAttachmentPicker('electron', true)).toBe(false);
    });
  });

  describe('isCapacitorNativeRuntime', () => {
    it('returns false when Capacitor is unavailable', () => {
      expect(isCapacitorNativeRuntime()).toBe(false);
    });
  });
});
