import { Injectable } from '@angular/core';
import { fromEvent } from 'rxjs';
import { map, take, tap } from 'rxjs/operators';

@Injectable({
  providedIn: 'root',
})
export class EnvironmentService {
  constructor() {}

  // /** Returns whether app is used within native container*/
  // isNative(): Promise<boolean> {
  //   return fromEvent(window, 'message')
  //     .pipe(
  //       map((evt: MessageEvent) => evt.data),
  //       tap(console.log.bind(window)),
  //       map((data) => data.status === 'INIT'),
  //       take(1)
  //     )
  //     .toPromise();
  // }

  /** Returns whether current device is mobile phone or tablet */
  async isMobile(): Promise<boolean> {
    return 'orientation' in window;
  }

  /** Returns whether current device is desktop */
  async isDesktop(): Promise<boolean> {
    return !(await this.isMobile());
  }
}
