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 __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
  if (kind === "m")
    throw new TypeError("Private method is not writable");
  if (kind === "a" && !f)
    throw new TypeError("Private accessor was defined without a setter");
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
    throw new TypeError("Cannot write private member to an object whose class did not declare it");
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var _KlevuModal_instances, _KlevuModal_dialogRef, _KlevuModal_close;
import { Host, h } from "@stencil/core";
/**
 * Stylized modal dialog.
 * @slot header - The title of the modal
 * @slot default - The content of the modal
 * @csspart modal-base The container for modal dialog
 * @csspart modal-header The header for modal dialog
 * @csspart modal-dialog The dialog component
 * @csspart modal-body The body for modal dialog
 */
export class KlevuModal {
  constructor() {
    _KlevuModal_instances.add(this);
    _KlevuModal_dialogRef.set(this, void 0);
    this.startOpen = false;
  }
  componentDidLoad() {
    if (this.startOpen) {
      this.openModal();
    }
  }
  /**
   * Opens the modal.
   */
  async openModal() {
    var _a;
    (_a = __classPrivateFieldGet(this, _KlevuModal_dialogRef, "f")) === null || _a === void 0 ? void 0 : _a.showModal();
  }
  /**
   * Closes the modal.
   */
  async closeModal() {
    var _a;
    (_a = __classPrivateFieldGet(this, _KlevuModal_dialogRef, "f")) === null || _a === void 0 ? void 0 : _a.close();
  }
  render() {
    return (h(Host, null, h("div", { part: "modal-base" }, h("dialog", { ref: (el) => (__classPrivateFieldSet(this, _KlevuModal_dialogRef, el, "f")), onCancel: __classPrivateFieldGet(this, _KlevuModal_instances, "m", _KlevuModal_close).bind(this), part: "modal-dialog" }, h("header", { part: "modal-header" }, h("slot", { name: "header" }), h("form", { method: "dialog", onSubmit: __classPrivateFieldGet(this, _KlevuModal_instances, "m", _KlevuModal_close).bind(this) }, h("button", null, h("klevu-icon", { name: "close" })))), h("main", { part: "modal-body" }, h("slot", null))))));
  }
  static get is() { return "klevu-modal"; }
  static get encapsulation() { return "shadow"; }
  static get originalStyleUrls() {
    return {
      "$": ["klevu-modal.css"]
    };
  }
  static get styleUrls() {
    return {
      "$": ["klevu-modal.css"]
    };
  }
  static get properties() {
    return {
      "startOpen": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Should show the modal on load."
        },
        "attribute": "start-open",
        "reflect": false,
        "defaultValue": "false"
      }
    };
  }
  static get events() {
    return [{
        "method": "klevuCloseModal",
        "name": "klevuCloseModal",
        "bubbles": true,
        "cancelable": true,
        "composed": true,
        "docs": {
          "tags": [],
          "text": "Emitted when the modal is closed."
        },
        "complexType": {
          "original": "void",
          "resolved": "void",
          "references": {}
        }
      }];
  }
  static get methods() {
    return {
      "openModal": {
        "complexType": {
          "signature": "() => Promise<void>",
          "parameters": [],
          "references": {
            "Promise": {
              "location": "global",
              "id": "global::Promise"
            }
          },
          "return": "Promise<void>"
        },
        "docs": {
          "text": "Opens the modal.",
          "tags": []
        }
      },
      "closeModal": {
        "complexType": {
          "signature": "() => Promise<void>",
          "parameters": [],
          "references": {
            "Promise": {
              "location": "global",
              "id": "global::Promise"
            }
          },
          "return": "Promise<void>"
        },
        "docs": {
          "text": "Closes the modal.",
          "tags": []
        }
      }
    };
  }
}
_KlevuModal_dialogRef = new WeakMap(), _KlevuModal_instances = new WeakSet(), _KlevuModal_close = function _KlevuModal_close(e) {
  const event = this.klevuCloseModal.emit();
  if (event.defaultPrevented) {
    e.preventDefault();
  }
};
//# sourceMappingURL=klevu-modal.js.map
