import { __require as u } from "./QueryHandler.js";
import { __require as c } from "./Util.js";
var a, h;
function f() {
  if (h) return a;
  h = 1;
  var o = u(), n = c().each;
  function s(e, r) {
    this.query = e, this.isUnconditional = r, this.handlers = [], this.mql = window.matchMedia(e);
    var i = this;
    this.listener = function(t) {
      i.mql = t.currentTarget || t, i.assess();
    }, this.mql.addListener(this.listener);
  }
  return s.prototype = {
    constuctor: s,
    /**
     * add a handler for this query, triggering if already active
     *
     * @param {object} handler
     * @param {function} handler.match callback for when query is activated
     * @param {function} [handler.unmatch] callback for when query is deactivated
     * @param {function} [handler.setup] callback for immediate execution when a query handler is registered
     * @param {boolean} [handler.deferSetup=false] should the setup callback be deferred until the first time the handler is matched?
     */
    addHandler: function(e) {
      var r = new o(e);
      this.handlers.push(r), this.matches() && r.on();
    },
    /**
     * removes the given handler from the collection, and calls it's destroy methods
     *
     * @param {object || function} handler the handler to remove
     */
    removeHandler: function(e) {
      var r = this.handlers;
      n(r, function(i, t) {
        if (i.equals(e))
          return i.destroy(), !r.splice(t, 1);
      });
    },
    /**
     * Determine whether the media query should be considered a match
     *
     * @return {Boolean} true if media query can be considered a match, false otherwise
     */
    matches: function() {
      return this.mql.matches || this.isUnconditional;
    },
    /**
     * Clears all handlers and unbinds events
     */
    clear: function() {
      n(this.handlers, function(e) {
        e.destroy();
      }), this.mql.removeListener(this.listener), this.handlers.length = 0;
    },
    /*
        * Assesses the query, turning on all handlers if it matches, turning them off if it doesn't match
        */
    assess: function() {
      var e = this.matches() ? "on" : "off";
      n(this.handlers, function(r) {
        r[e]();
      });
    }
  }, a = s, a;
}
export {
  f as __require
};
//# sourceMappingURL=MediaQuery.js.map
