'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-fd2bbf0b.js');
const store = require('./store-906b67b1.js');
require('./index-81aa1bcb.js');

const pageTemplateCss = "fireenjin-mx-page-template .tabs-bar{background-color:var(--ion-background-color, #fff) !important}fireenjin-mx-page-template floodteam-floating-button ion-fab{margin-top:20px}fireenjin-mx-page-template .ce-toolbar{background-color:var(--ion-background-color)}fireenjin-mx-page-template .ce-toolbox{background:var(--ion-background-color) !important}fireenjin-mx-page-template ion-item{--background:transparent}fireenjin-mx-page-template .gjs-editor-cont{top:50px}fireenjin-mx-page-template .sample-editor{display:block;height:300px;position:relative;--min-height:300px}fireenjin-mx-page-template ion-item.sample-editor ion-label{position:absolute;top:0;left:0;color:var(--ion-color-medium-shade) !important;font-size:12px !important;font-weight:bold;text-transform:uppercase;font-family:arial;display:block;background:transparent;text-align:left;padding:0 0 8px 0;font-family:var(--ion-font-family)}fireenjin-mx-page-template .preview-wrapper{margin:30px auto;max-width:650px}fireenjin-mx-page-template fireenjin-editor{margin:15px auto;--editor-background:var(--ion-color-base);--editor-color:var(--ion-text-color);--editor-color-shadow:var(--ion-color-base-dark);--editor-color-punctuation:rgba(var(--ion-color-secondary-rgb), 0.6);--editor-color-property:var(--ion-color-primary)}fireenjin-mx-page-template .pdf-wrapper{background-color:#fff;--ion-text-color:#000}";

let PageTemplate = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
  }
  onSuccess(event) {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j;
    if (((_a = event === null || event === void 0 ? void 0 : event.detail) === null || _a === void 0 ? void 0 : _a.endpoint) === "findTemplate") {
      this.template = ((_c = (_b = event.detail) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.template) || null;
    }
    else if (((_d = event === null || event === void 0 ? void 0 : event.detail) === null || _d === void 0 ? void 0 : _d.endpoint) === "addTemplate" &&
      this.templateId === "new") {
      const routerEl = document.querySelector("ion-router");
      this.templateId = ((_g = (_f = (_e = event === null || event === void 0 ? void 0 : event.detail) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.addTemplate) === null || _g === void 0 ? void 0 : _g.id) || "new";
      if (routerEl)
        routerEl.push(`/templates/${this.templateId}`);
    }
    else if (((_h = event === null || event === void 0 ? void 0 : event.detail) === null || _h === void 0 ? void 0 : _h.endpoint) === "editTemplate") {
      if ((_j = this.editorEl) === null || _j === void 0 ? void 0 : _j.fetchData)
        this.editorEl.fetchData();
    }
  }
  async onTrigger(event) {
    var _a;
    if (((_a = event === null || event === void 0 ? void 0 : event.detail) === null || _a === void 0 ? void 0 : _a.name) === "preview") {
      store.state.isPreviewing = !store.state.isPreviewing;
    }
  }
  componentDidLoad() {
    if (!(index.Build === null || index.Build === void 0 ? void 0 : index.Build.isBrowser))
      return;
    this.db.watchDocument("templates", this.templateId, () => {
      this.editorEl.fetchData();
    });
  }
  render() {
    return [
      index.h("ion-content", null, index.h("fireenjin-mx-editor", { ref: (el) => (this.editorEl = el), partials: store.state === null || store.state === void 0 ? void 0 : store.state.partials, isPreviewing: store.state === null || store.state === void 0 ? void 0 : store.state.isPreviewing, templateId: this.templateId })),
      index.h("ion-fab", { vertical: "bottom", horizontal: "end", slot: "fixed", onClick: () => { var _a, _b; return (_b = (_a = this.editorEl) === null || _a === void 0 ? void 0 : _a.openControls) === null || _b === void 0 ? void 0 : _b.call(_a); } }, index.h("ion-fab-button", null, index.h("ion-icon", { name: "code-working-outline" }))),
      index.h("app-footer", null),
    ];
  }
};
PageTemplate.style = pageTemplateCss;

exports.fireenjin_mx_page_template = PageTemplate;

//# sourceMappingURL=fireenjin-mx-page-template.cjs.entry.js.map