
/**
 * Device module.
 * @module base/utils/device
 */

import { pxToInt } from './string'

/**
 * DeviceInfo class.
 */
export class DeviceInfo {
  constructor(options) {
    this.breakpoints = options.breakpoints || {}
  }

  /** Return breakpoints. */
  get breakpoints() {
    return this._breakpoints
  }

  /**
   * Set breakpoints (pixel values will be converted to integers).
   *
   * @param {Object} breakpoints - Breakpoints
   */
  set breakpoints(breakpoints) {
    var newBreakpoints = {}

    for (let breakpoint in breakpoints) {
      if (breakpoints.hasOwnProperty(breakpoint)) {
        newBreakpoints[breakpoint] = pxToInt(breakpoints[breakpoint])
      }
    }

    this._breakpoints = newBreakpoints
  }

  _checkWhetherBreakpointExists(breakpoint) {
    if (!this._breakpoints[breakpoint]) {
      throw new Error('Breakpoint "'+ breakpoint + '" doesn\'t exist.')
    }
  }

  /**
   * Check if current device width is equal to the given breakpoint.
   *
   * @param   {String} breakpoint - Breakpoint to check.
   * @returns {Boolean}
   *   `true` if device width is equal to the given breakpoint, otherwise `false`.
   */
  isEqual(breakpoint) {
    this._checkWhetherBreakpointExists(breakpoint)

    return window.innerWidth == this._breakpoints[breakpoint]
  }

  /**
   * Check if current device width is larger than given breakpoint.
   *
   * @param   {String} breakpoint - Breakpoint to check.
   * @returns {Boolean}
   *   `true` if device width is larger than given breakpoint, otherwise `false`.
   */
  isLargerThan(breakpoint) {
    this._checkWhetherBreakpointExists(breakpoint)

    return window.innerWidth > this._breakpoints[breakpoint]
  }

  /**
   * Check if current device width is smaller than given breakpoint.
   *
   * @param   {String} breakpoint - Breakpoint to check.
   * @returns {Boolean}
   *   `true` if device width is smaller than given breakpoint, otherwise `false`.
   */
  isSmallerThan(breakpoint) {
    this._checkWhetherBreakpointExists(breakpoint)

    return window.innerWidth < this._breakpoints[breakpoint]
  }

  /**
   * Check if device width is equal or larger than given breakpoint.
   *
   * @param   {String} breakpoint - Breakpoint to check.
   * @returns {Boolean}
   *   `true` if device width is equal or larger than given breakpoint, otherwise `false`.
   */
  isLargerThanOrEqual(breakpoint) {
    return this.isEqual(breakpoint) || this.isLargerThan(breakpoint)
  }

  /**
   * Check if device width is equal or smaller than given breakpoint.
   *
   * @param   {String} breakpoint - Breakpoint to check.
   * @returns {Boolean}
   *   `true` if device width is equal or smaller than given breakpoint, otherwise `false`.
   */
  isSmallerThanOrEqual(breakpoint) {
    return this.isEqual(breakpoint) || this.isSmallerThan(breakpoint)
  }
}

export default {
  deviceType,
  hasMouse,
  hasTouch,
  passiveEvents,
  primaryInput
}

@@ -2823,94 +2823,4 @@
 %7D%0A%7D%0A
-%0Aexport default %7B%0A  deviceType,%0A  hasMouse,%0A  hasTouch,%0A  passiveEvents,%0A  primaryInput%0A%7D%0A

Remove deprecated device exports