/* eslint-disable prefer-rest-params */
/* eslint-disable import/prefer-default-export */
import { Service } from '../service'

export class Application extends Service {
  constructor () {
    super(...arguments)
    this.bar = 0
    this.top = 0
    this.left = 0
    this.insetFooter = 0
    this.right = 0
    this.bottom = 0
    this.footer = 0
    this.application = {
      bar: {},
      top: {},
      left: {},
      insetFooter: {},
      right: {},
      bottom: {},
      footer: {}
    }
  }

  register (uid, location, size) {
    this.application[location] = {
      [uid]: size
    }
    this.update(location)
  }

  unregister (uid, location) {
    if (this.application[location][uid] == null) return
    delete this.application[location][uid]
    this.update(location)
  }

  update (location) {
    this[location] = Object.values(this.application[location]).reduce((acc, cur) => acc + cur, 0)
  }
}
Application.property = 'application'
