var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
  if (kind === "a" && !f)
    throw new TypeError("Private accessor was defined without a getter");
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
    throw new TypeError("Cannot read private member from an object whose class did not declare it");
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _KlevuUtilViewport_instances, _KlevuUtilViewport_handleMatchMediaChange;
export class KlevuUtilViewport {
  constructor() {
    _KlevuUtilViewport_instances.add(this);
    this.sizes = [
      { name: "xs", minWidth: 0, maxWidth: 319 },
      { name: "sm", minWidth: 320, maxWidth: 511 },
      { name: "md", minWidth: 512, maxWidth: 991 },
      { name: "lg", minWidth: 992, maxWidth: 1199 },
      { name: "xl", minWidth: 1200, maxWidth: 9999 },
    ];
  }
  connectedCallback() {
    // Add listeners for all sizes provided
    for (const size of this.sizes) {
      window
        .matchMedia(`(min-width: ${size.minWidth}px) and (max-width: ${size.maxWidth}px)`)
        .addEventListener("change", __classPrivateFieldGet(this, _KlevuUtilViewport_instances, "m", _KlevuUtilViewport_handleMatchMediaChange).bind(this));
    }
  }
  disconnectedCallback() {
    for (const size of this.sizes) {
      window
        .matchMedia(`(min-width: ${size.minWidth}px) and (max-width: ${size.maxWidth}px)`)
        .removeEventListener("change", __classPrivateFieldGet(this, _KlevuUtilViewport_instances, "m", _KlevuUtilViewport_handleMatchMediaChange).bind(this));
    }
  }
  async getCurrentSize() {
    // Iterate over all given sizes and see which one matches
    for (const size of this.sizes) {
      if (window.matchMedia(`(min-width: ${size.minWidth}px)  and (max-width: ${size.maxWidth}px)`).matches) {
        return size;
      }
    }
  }
  render() {
    return null;
  }
  static get is() { return "klevu-util-viewport"; }
  static get properties() {
    return {
      "sizes": {
        "type": "unknown",
        "mutable": false,
        "complexType": {
          "original": "ViewportSize[]",
          "resolved": "ViewportSize[]",
          "references": {
            "ViewportSize": {
              "location": "local",
              "path": "/home/runner/work/frontend-sdk/frontend-sdk/packages/klevu-ui/src/components/klevu-util-viewport/klevu-util-viewport.tsx",
              "id": "src/components/klevu-util-viewport/klevu-util-viewport.tsx::ViewportSize"
            }
          }
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "List of sizes to listen for"
        },
        "defaultValue": "[\n    { name: \"xs\", minWidth: 0, maxWidth: 319 },\n    { name: \"sm\", minWidth: 320, maxWidth: 511 },\n    { name: \"md\", minWidth: 512, maxWidth: 991 },\n    { name: \"lg\", minWidth: 992, maxWidth: 1199 },\n    { name: \"xl\", minWidth: 1200, maxWidth: 9999 },\n  ]"
      }
    };
  }
  static get events() {
    return [{
        "method": "sizeChanged",
        "name": "sizeChanged",
        "bubbles": true,
        "cancelable": true,
        "composed": true,
        "docs": {
          "tags": [],
          "text": ""
        },
        "complexType": {
          "original": "ViewportSize",
          "resolved": "{ name: ViewportSizeName; minWidth: number; maxWidth: number; }",
          "references": {
            "ViewportSize": {
              "location": "local",
              "path": "/home/runner/work/frontend-sdk/frontend-sdk/packages/klevu-ui/src/components/klevu-util-viewport/klevu-util-viewport.tsx",
              "id": "src/components/klevu-util-viewport/klevu-util-viewport.tsx::ViewportSize"
            }
          }
        }
      }];
  }
  static get methods() {
    return {
      "getCurrentSize": {
        "complexType": {
          "signature": "() => Promise<ViewportSize | undefined>",
          "parameters": [],
          "references": {
            "Promise": {
              "location": "global",
              "id": "global::Promise"
            },
            "ViewportSize": {
              "location": "local",
              "path": "/home/runner/work/frontend-sdk/frontend-sdk/packages/klevu-ui/src/components/klevu-util-viewport/klevu-util-viewport.tsx",
              "id": "src/components/klevu-util-viewport/klevu-util-viewport.tsx::ViewportSize"
            }
          },
          "return": "Promise<ViewportSize | undefined>"
        },
        "docs": {
          "text": "",
          "tags": []
        }
      }
    };
  }
}
_KlevuUtilViewport_instances = new WeakSet(), _KlevuUtilViewport_handleMatchMediaChange = function _KlevuUtilViewport_handleMatchMediaChange(q) {
  if (!q.matches) {
    return;
  }
  // Find the name of the matching size and emit an event
  for (const size of this.sizes) {
    if (q.media.indexOf(`min-width: ${size.minWidth}px`) > -1) {
      this.sizeChanged.emit(size);
    }
  }
};
//# sourceMappingURL=klevu-util-viewport.js.map
