import { r as registerInstance, c as createEvent, h, H as Host } from './index-e582ed08.js';

const klevuModalCss = ":host{display:block}dialog{border:none !important;border-radius:var(--klevu-border-radius-m);padding:0;box-shadow:var(--klevu-elevation-1)}main{padding:var(--klevu-spacing-04)}header{padding:var(--klevu-spacing-04);display:flex;justify-content:space-between;align-items:center}button{border:none;background-color:transparent;appearance:none;border-radius:100%;height:30px;width:30px}";

var __classPrivateFieldGet = (undefined && undefined.__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 = (undefined && undefined.__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;
const KlevuModal = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.klevuCloseModal = createEvent(this, "klevuCloseModal", 7);
    _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))))));
  }
};
_KlevuModal_dialogRef = new WeakMap(), _KlevuModal_instances = new WeakSet(), _KlevuModal_close = function _KlevuModal_close(e) {
  const event = this.klevuCloseModal.emit();
  if (event.defaultPrevented) {
    e.preventDefault();
  }
};
KlevuModal.style = klevuModalCss;

export { KlevuModal as klevu_modal };

//# sourceMappingURL=klevu-modal.entry.js.map