/*
	Author: Jeremy Espinosa
	Filename: currentWindow.js
	Description: This is to get the window size, breakpoint
	Dependencies: 
		- underscore
	How to use:
		1. Just call the B2C.currentWindow.init() function and it will return what you need
		2. It consist of different function to get the window size , breakpoint
*/

;(function($) {
    'use strict'

    B2C.currentWindow = {
        init: function() {
            this._default = {
                windowSize: 0,
                breakpoint: {
                    sm: 0,
                    md: 767,
                    lg: 1023
                }
            }

            B2C.currentWindow.windowResize()
            B2C.currentWindow.setWindowSize()
        },

        windowResize: function() {
            let self = B2C.currentWindow

            window.addEventListener(
                'resize',
                _.debounce(function() {
                    self.setWindowSize()
                }, 300)
            )
        },

        setWindowSize: function() {
            let self = B2C.currentWindow,
                windowSize = window.innerWidth

            self._default.windowSize = windowSize
        },

        getWindowSize: function() {
            return B2C.currentWindow._default.windowSize
        },

        getBreakpoint: function() {
            let self = B2C.currentWindow,
                windowSize = self.getWindowSize(),
                breakpoint = ''

            if (windowSize < self._default.breakpoint.md) {
                breakpoint = 'mobile'
            } else if (
                windowSize > self._default.breakpoint.md &&
                windowSize < self._default.breakpoint.lg
            ) {
                breakpoint = 'tablet'
            } else {
                breakpoint = 'desktop'
            }

            return breakpoint
        }
    }
})(jQuery)
