'use strict';

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

const index = require('./index-ee190ee0.js');
const tslib_es6 = require('./tslib.es6-8eb3c9db.js');
const index_min = require('./index.min-0ca13044.js');
const store = require('./store-235e38ab.js');
require('./_commonjsHelpers-a5111d61.js');
require('./index-4901314f.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 fireenjin-editor{--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}";

const PageTemplate = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.templateId = undefined;
    this.db = undefined;
    this.template = undefined;
    this.firstLoad = true;
  }
  onSuccess(event) {
    var _a, _b, _c, _d;
    if (((_a = event === null || event === void 0 ? void 0 : event.detail) === null || _a === void 0 ? void 0 : _a.endpoint) === "addTemplate" &&
      this.templateId === "new") {
      const routerEl = document.querySelector("ion-router");
      this.templateId = ((_d = (_c = (_b = event === null || event === void 0 ? void 0 : event.detail) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.addTemplate) === null || _d === void 0 ? void 0 : _d.id) || "new";
      if (routerEl)
        routerEl.push(`/templates/${this.templateId}`);
    }
  }
  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;
    }
  }
  onTemplateChange() {
    setTimeout(() => {
      var _a;
      this.template = (_a = this.editorEl) === null || _a === void 0 ? void 0 : _a.template;
    }, 500);
  }
  componentDidLoad() {
    if (!(index.Build === null || index.Build === void 0 ? void 0 : index.Build.isBrowser))
      return;
    this.db.watchDocument("templates", this.templateId, ({ data }) => {
      console.log("Template Doc Updated:", data);
      if (!this.firstLoad)
        this.editorEl.fetchData();
      this.firstLoad = false;
    });
  }
  async openPdfPreview() {
    var _a;
    if (!((_a = this.editorEl) === null || _a === void 0 ? void 0 : _a.save))
      return;
    await this.editorEl.save();
    await this.editorEl.generatePdf();
  }
  render() {
    var _a, _b;
    return [
      index.h("ion-content", null, index.h("fireenjin-mx-editor", { ref: (el) => (this.editorEl = el),
        // partials={(state?.templates || []).filter(
        //   (template) => template?.partial
        // )}
        // frames={(state?.templates || []).filter(
        //   (template) => template?.type === "frame"
        // )}
        colors: {
          primary: "#004b8f",
          "primary-contrast": "#ffffff",
          secondary: "#0779bf",
          "secondary-contrast": "#ffffff",
          tertiary: "#00b0db",
          "tertiary-contrast": "#000000",
          success: "#95c11f",
          "success-contrast": "#000000",
          warning: "#ffc409",
          "warning-contrast": "#000000",
          danger: "#ff4e6e",
          "danger-contrast": "#000000",
          dark: "#222428",
          "dark-contrast": "#ffffff",
          medium: "#92949c",
          "medium-contrast": "#ffffff",
          light: "#f4f5f8",
          "light-contrast": "#000000",
        }, templates: store.state === null || store.state === void 0 ? void 0 : store.state.templates, templateId: this.templateId === "new" ? null : this.templateId, fetch: true })),
      index.h("fireenjin-render-template", { style: {
          position: "absolute",
          minHeight: "216px",
          minWidth: "384px",
          maxHeight: "216px",
          maxWidth: "384px",
          bottom: "50px",
          right: "18px",
        }, zoom: "0.2", partials: ((store.state === null || store.state === void 0 ? void 0 : store.state.templates) || []), template: this.template, allowFullscreen: true, enableClicks: true }),
      index.h("ion-footer", null, index.h("fireenjin-chip-bar", null, index.h("ion-router-link", { href: "/templates" }, index.h("ion-chip", { color: "light" }, index.h("ion-icon", { name: "arrow-back-circle" }), index.h("ion-label", null, "Back"))), index.h("ion-router-link", { onClick: () => { var _a, _b; return (_b = (_a = this.editorEl) === null || _a === void 0 ? void 0 : _a.save) === null || _b === void 0 ? void 0 : _b.call(_a); } }, index.h("ion-chip", { color: "light" }, index.h("ion-icon", { name: "save" }), index.h("ion-label", null, "Save"))), index.h("ion-router-link", { onClick: () => { var _a, _b; return (_b = (_a = this.editorEl) === null || _a === void 0 ? void 0 : _a.openTemplateInfoModal) === null || _b === void 0 ? void 0 : _b.call(_a); } }, index.h("ion-chip", { color: "light" }, index.h("ion-icon", { name: "information-circle" }), index.h("ion-label", null, ((_a = this.template) === null || _a === void 0 ? void 0 : _a.name) || ((_b = this.template) === null || _b === void 0 ? void 0 : _b.subject) || "Info"))), index.h("ion-router-link", { onClick: () => { var _a, _b; return (_b = (_a = this.editorEl) === null || _a === void 0 ? void 0 : _a.openLayoutModal) === null || _b === void 0 ? void 0 : _b.call(_a); } }, index.h("ion-chip", { color: "light" }, index.h("ion-icon", { name: "scan" }), index.h("ion-label", null, "Layout"))), index.h("ion-router-link", { onClick: () => { var _a, _b; return (_b = (_a = this.editorEl) === null || _a === void 0 ? void 0 : _a.openSampleDataModal) === null || _b === void 0 ? void 0 : _b.call(_a); } }, index.h("ion-chip", { color: "light" }, index.h("ion-icon", { name: "document-text" }), index.h("ion-label", null, "Sample Data"))), index.h("ion-router-link", { onClick: () => { var _a, _b; return (_b = (_a = this.editorEl) === null || _a === void 0 ? void 0 : _a.openHeadModal) === null || _b === void 0 ? void 0 : _b.call(_a); } }, index.h("ion-chip", { color: "light" }, index.h("ion-icon", { name: "search-circle" }), index.h("ion-label", null, "Edit Head"))), index.h("ion-router-link", { onClick: () => { var _a, _b; return (_b = (_a = this.editorEl) === null || _a === void 0 ? void 0 : _a.openRoutesModal) === null || _b === void 0 ? void 0 : _b.call(_a); } }, index.h("ion-chip", { color: "light" }, index.h("ion-icon", { name: "globe" }), index.h("ion-label", null, "Edit Routes"))), index.h("ion-router-link", { onClick: () => { var _a, _b; return (_b = (_a = this.editorEl) === null || _a === void 0 ? void 0 : _a.openCodeModal) === null || _b === void 0 ? void 0 : _b.call(_a); } }, index.h("ion-chip", { color: "light" }, index.h("ion-icon", { name: "code-slash" }), index.h("ion-label", null, "Code"))), index.h("ion-router-link", { onClick: () => { var _a, _b; return (_b = (_a = this.editorEl) === null || _a === void 0 ? void 0 : _a.openSendEmailModal) === null || _b === void 0 ? void 0 : _b.call(_a); } }, index.h("ion-chip", { color: "light" }, index.h("ion-icon", { name: "mail" }), index.h("ion-label", null, "Email"))), index.h("ion-router-link", { onClick: () => this.openPdfPreview() }, index.h("ion-chip", { color: "light" }, index.h("ion-icon", { name: "document" }), index.h("ion-label", null, "PDF"))))),
    ];
  }
};
tslib_es6.__decorate([
  index_min.index_min.debounce(500)
], PageTemplate.prototype, "onTemplateChange", null);
PageTemplate.style = pageTemplateCss;

exports.fireenjin_mx_page_template = PageTemplate;
