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 { initializeAppI18nForTests, provideAppI18nForTests } from '../../../core/i18n/app-i18n.testing';
import { MobileAppUpdateService } from './mobile-app-update.service';
import { MobilePlatformService } from './mobile-platform.service';

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

  initializeAppI18nForTests(injector);

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

describe('MobileAppUpdateService', () => {
  it('reports unsupported state on browser shells', () => {
    const service = createService(false);

    expect(service.isCapacitor).toBe(false);
    expect(service.state().status).toBe('unsupported');
  });

  it('exposes capacitor support flag from the mobile platform service', () => {
    const service = createService(true);

    expect(service.isCapacitor).toBe(false);
  });
});
