import '@angular/compiler';
import { Injector, runInInjectionContext } from '@angular/core';
import {
  describe,
  expect,
  it
} from 'vitest';

import { ElectronBridgeService } from '../../../core/platform/electron/electron-bridge.service';
import { ViewportService } from '../../../core/platform/viewport.service';
import { MobilePlatformService } from './mobile-platform.service';

function createService(options: { isMobile: boolean }): MobilePlatformService {
  const injector = Injector.create({
    providers: [
      MobilePlatformService,
      {
        provide: ElectronBridgeService,
        useValue: { isAvailable: false }
      },
      {
        provide: ViewportService,
        useValue: {
          isMobile: () => options.isMobile
        }
      }
    ]
  });

  return runInInjectionContext(injector, () => injector.get(MobilePlatformService));
}

describe('MobilePlatformService', () => {
  it('reports browser runtime and hides attachment button on desktop viewport', () => {
    const service = createService({ isMobile: false });

    expect(service.runtime()).toBe('browser');
    expect(service.shouldShowAttachmentButton()).toBe(false);
  });

  it('enables attachment button on mobile viewport in browser runtime', () => {
    const service = createService({ isMobile: true });

    expect(service.shouldShowAttachmentButton()).toBe(true);
  });
});
