import { Build, h, } from "@stencil/core";
import * as jsonLogic from "json-logic-js";
import { toastController } from "@ionic/core";
import renderHandlebars from "../../../helpers/renderHandlebars";
import testJob from "../../../helpers/seeds/testJob";
import testLocation from "../../../helpers/seeds/testLocation";
import testUser from "../../../helpers/seeds/testUser";
import state from "../../../store";
import getEventTypeOptions from "../../../helpers/getEventTypeOptions";
import getNotionDatabaseOptions from "../../../helpers/getNotionDatabaseOptions";
export class appTrigger {
  constructor() {
    this.seedData = {
      addJob: testJob,
      editJob: testJob,
      addLocation: testLocation,
      editLocation: testLocation,
      addUser: testUser,
      editUser: testUser,
      signContract: {
        job: testJob,
        url: "https://firebasestorage.googleapis.com/v0/b/ftms-ca85b.appspot.com/o/A%20New%20Job%20added%20(customer%20alert).png.png?alt=media&token=a64c1904-cebb-429e-bbfd-5351d301eaea",
        efile: {
          id: "test",
        },
      },
      addLog: {
        id: "test-log",
      },
      addNote: {
        id: "test-note",
      },
      editNote: {
        id: "test-note",
      },
      addPayable: {
        id: "addPayable-test",
      },
      editPayable: {
        id: "payable-test",
      },
      addPayment: {
        id: "payment-test",
      },
      editPayment: {
        id: "payment-test",
      },
    };
    this.payloadKey = {
      addJob: "job",
      editJob: "job",
      addLocation: "location",
      editLocation: "location",
      addUser: "user",
      editUser: "user",
      addLog: "log",
      addNote: "note",
      editNote: "note",
      addPayable: "payable",
      editPayable: "payable",
      addPayment: "payment",
      editPayment: "payment",
    };
    this.sampleOutput = {};
    this.defaultAlertPayload = {
      types: ["email"],
      emails: [],
      userIds: [],
      payload: {},
      options: {},
      sendAt: null,
      templateId: null,
      tags: [],
    };
    this.defaultTotallerPayload = {
      totallerId: null,
      before: null,
      after: null,
      extras: {},
      mergeData: {},
      dryRun: false,
    };
    this.defaultNotionPayload = {
      pageId: "{{data.notionId}}",
      docPath: null,
      databaseId: null,
    };
    this.triggerId = undefined;
    this.trigger = {};
    this.triggerWillFire = false;
    this.currentTab = "settings";
    this.showAdvanced = false;
    this.payload = undefined;
  }
  ionChange(event) {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
    console.log("ionInput:", event);
    if (((_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.name) && !event.target.name.startsWith("ion-"))
      this.setByPath(this.trigger, event.target.name, event.detail.value);
    if (((_b = event === null || event === void 0 ? void 0 : event.target) === null || _b === void 0 ? void 0 : _b.name) === "type" && !((_c = this.trigger) === null || _c === void 0 ? void 0 : _c.sampleData)) {
      if ((_d = this.seedData) === null || _d === void 0 ? void 0 : _d[(_e = event.detail) === null || _e === void 0 ? void 0 : _e.value])
        this.trigger.sampleData = (_f = this.seedData) === null || _f === void 0 ? void 0 : _f[(_g = event.detail) === null || _g === void 0 ? void 0 : _g.value];
      const alertPayload = {
        ...this.payload,
        types: [...(((_j = (_h = this.trigger) === null || _h === void 0 ? void 0 : _h.payload) === null || _j === void 0 ? void 0 : _j.types) || [])],
        emails: [...(((_l = (_k = this.trigger) === null || _k === void 0 ? void 0 : _k.payload) === null || _l === void 0 ? void 0 : _l.emails) || [])],
        userIds: [...(((_o = (_m = this.trigger) === null || _m === void 0 ? void 0 : _m.payload) === null || _o === void 0 ? void 0 : _o.userIds) || [])],
        templateId: ((_q = (_p = this.trigger) === null || _p === void 0 ? void 0 : _p.payload) === null || _q === void 0 ? void 0 : _q.templateId) || null,
        payload: this.payloadKey[(_r = this.trigger) === null || _r === void 0 ? void 0 : _r.type]
          ? {
            [this.payloadKey[(_s = this.trigger) === null || _s === void 0 ? void 0 : _s.type]]: "@data",
          }
          : {
            "...": "@data",
          },
        options: ((_u = (_t = this.trigger) === null || _t === void 0 ? void 0 : _t.payload) === null || _u === void 0 ? void 0 : _u.options) || {},
        sendAt: ((_w = (_v = this.trigger) === null || _v === void 0 ? void 0 : _v.payload) === null || _w === void 0 ? void 0 : _w.sendAt) || null,
        tags: ((_y = (_x = this.trigger) === null || _x === void 0 ? void 0 : _x.payload) === null || _y === void 0 ? void 0 : _y.tags) || [],
      };
      this.payload =
        ((_z = this.trigger) === null || _z === void 0 ? void 0 : _z.type) === "time"
          ? {
            action: "alert",
            queries: [
              {
                collection: "jobs",
                aliasAs: "job",
                filter: {
                  whereIn: {
                    status: [
                      "book",
                      "evaluate",
                      "claim",
                      "mitigate",
                      "monitor",
                      "review",
                    ],
                  },
                },
              },
            ],
            payload: alertPayload,
          }
          : alertPayload;
    }
    else if (event.target.name === "payload") {
      this.generateSampleOutput();
    }
    else if (event.target.name === "sampleData") {
      this.generateSampleOutput();
      this.triggerWillFire = this.checkIfTriggerFires(this.trigger.when);
    }
  }
  onChange(event) {
    setTimeout(() => {
      var _a, _b, _c, _d, _e, _f;
      console.log("ionChange:", event);
      if (((_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.name) === "action") {
        this.showAdvanced = ((_b = event === null || event === void 0 ? void 0 : event.target) === null || _b === void 0 ? void 0 : _b.value) !== "alert";
        this.trigger = { ...this.trigger, action: (_c = event === null || event === void 0 ? void 0 : event.target) === null || _c === void 0 ? void 0 : _c.value };
        this.payload =
          ((_d = this.trigger) === null || _d === void 0 ? void 0 : _d.payload) ||
            (((_e = this.trigger) === null || _e === void 0 ? void 0 : _e.action) === "totaller"
              ? this.defaultTotallerPayload
              : ((_f = this.trigger) === null || _f === void 0 ? void 0 : _f.action) === "notion"
                ? this.defaultNotionPayload
                : this.defaultAlertPayload);
      }
    }, 1000);
  }
  async onCodeChange(event) {
    if (event.target.name === "payload") {
      this.payload = JSON.parse(event.target.value);
      this.trigger = { ...this.trigger, payload: this.payload };
      this.generateSampleOutput();
    }
    else if (event.target.name === "sampleData") {
      this.trigger.sampleData = JSON.parse(event.target.value);
      this.generateSampleOutput();
      this.triggerWillFire = this.checkIfTriggerFires(this.trigger.when);
    }
    else if (event.target.name === "when") {
      this.trigger.when = event.target.value;
      this.triggerWillFire = this.checkIfTriggerFires(this.trigger.when);
    }
    else if (event.target.name === "batch.when") {
      this.trigger.batch.when = event.target.value;
    }
    else if (event.target.name === "batch.transformer") {
      this.trigger.batch.transformer = event.target.value;
    }
  }
  onSuccess(event) {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
    if (((_a = event === null || event === void 0 ? void 0 : event.detail) === null || _a === void 0 ? void 0 : _a.endpoint) === "findTrigger") {
      this.trigger = ((_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.trigger) || null;
      this.payload =
        ((_d = this.trigger) === null || _d === void 0 ? void 0 : _d.payload) ||
          (((_e = this.trigger) === null || _e === void 0 ? void 0 : _e.action) === "totaller"
            ? this.defaultTotallerPayload
            : ((_f = this.trigger) === null || _f === void 0 ? void 0 : _f.action) === "notion"
              ? this.defaultNotionPayload
              : this.defaultAlertPayload);
    }
    else if (((_g = event === null || event === void 0 ? void 0 : event.detail) === null || _g === void 0 ? void 0 : _g.endpoint) === "addTrigger" &&
      this.triggerId === "new") {
      const routerEl = document.querySelector("ion-router");
      this.triggerId = ((_k = (_j = (_h = event === null || event === void 0 ? void 0 : event.detail) === null || _h === void 0 ? void 0 : _h.data) === null || _j === void 0 ? void 0 : _j.addTemplate) === null || _k === void 0 ? void 0 : _k.id) || "new";
      if (routerEl)
        routerEl.push(`/triggers/${this.triggerId}`);
    }
  }
  setByPath(obj, path, value) {
    const pList = path.split(".");
    const len = pList.length;
    for (let i = 0; i < len - 1; i++) {
      const elem = pList[i];
      if (!obj[elem])
        obj[elem] = {};
      obj = obj[elem];
    }
    obj[pList[len - 1]] = value;
  }
  checkIfTriggerFires(when) {
    return !!jsonLogic.apply(typeof when === "string" ? JSON.parse(when) : when, {
      data: this.trigger.sampleData,
    });
  }
  generateSampleOutput() {
    var _a, _b, _c;
    let output = renderHandlebars(JSON.stringify(((_a = this.trigger) === null || _a === void 0 ? void 0 : _a.payload) || {}), {
      data: ((_b = this.trigger) === null || _b === void 0 ? void 0 : _b.sampleData) || {},
    });
    output = output.replace('"@data"', JSON.stringify(((_c = this.trigger) === null || _c === void 0 ? void 0 : _c.sampleData) || {}));
    this.jsonViewerEl.innerHTML = output;
    this.sampleOutput = JSON.parse(output);
    return output;
  }
  async save() {
    this.formEl.submit();
    (await toastController.create({
      message: "Trigger saved successfully!",
      duration: 2000,
    })).present();
  }
  async componentDidLoad() {
    if (!(Build === null || Build === void 0 ? void 0 : Build.isBrowser))
      return;
    this.fireenjinTrigger.emit({
      name: "subscribe",
      payload: {
        collection: "triggers",
        id: this.triggerId,
        callback: () => {
          this.formEl.fetchData();
        },
      },
    });
  }
  disconnectedCallback() {
    this.fireenjinTrigger.emit({
      name: "unsubscribe",
      payload: {
        collection: "triggers",
        id: this.triggerId,
      },
    });
  }
  render() {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40;
    return [
      h("ion-content", { class: "ion-padding" }, h("fireenjin-form", { ref: (el) => (this.formEl = el), fetch: this.triggerId === "new" ? null : "findTrigger", "fetch-key": "trigger", endpoint: this.triggerId === "new" ? "addTrigger" : "editTrigger", documentId: this.triggerId === "new" ? null : this.triggerId, beforeSubmit: async (data) => ({
          ...data,
          payload: this.payload,
        }), formData: this.trigger, filterData: "name,type,when,action,payload,sampleData,active,batch", hideControls: true }, h("ion-card", { style: {
          overflow: "visible",
        } }, h("fireenjin-input-logic", { variables: {
          "job.title": {
            label: "Job Title",
            value: null,
          },
          "job.status": {
            label: "Job Status",
            options: [
              {
                label: "Started",
                value: "started",
              },
            ],
          },
        } }), h("ion-segment", { onIonChange: (event) => { var _a; return (this.currentTab = ((_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.value) || "settings"); }, style: { "--background": "rgba(0,0,0,0.2)" }, color: "primary", scrollable: true, value: this.currentTab }, h("ion-segment-button", { value: "settings", layout: "icon-start" }, h("ion-label", null, "Settings"), h("ion-icon", { name: "settings" })), h("ion-segment-button", { value: "action", layout: "icon-start" }, h("ion-label", null, "Action"), h("ion-icon", { name: "flash" })), h("ion-segment-button", { value: "test", layout: "icon-start" }, h("ion-label", null, "Test"), h("ion-icon", { name: "flashlight" }))), h("ion-card-content", { style: {
          opacity: this.currentTab === "settings" ? "1" : "0",
          height: this.currentTab === "settings" ? "auto" : "0",
          padding: this.currentTab === "settings" ? "1rem 2rem" : "0",
        } }, h("ion-grid", null, h("ion-row", null, h("ion-col", { size: "10" }, h("fireenjin-input", { "data-fill": true, labelPosition: "stacked", type: "text", name: "name", label: "Name", required: true })), h("ion-col", { size: "2" }, h("fireenjin-toggle", { value: (_a = this.trigger) === null || _a === void 0 ? void 0 : _a.active, color: "primary", lines: "none", label: "Active", labelPosition: "stacked", name: "active" })))), h("fireenjin-select", { labelPosition: "stacked", "data-fill": true, name: "type", label: "Type", options: getEventTypeOptions(), required: true }), h("ion-item", { class: "json-editor-field", style: { zIndex: "3" } }, h("ion-label", null, h("h2", null, "When is this triggered?"), h("fireenjin-code-editor", { autoExpand: true, value: ((_b = this.trigger) === null || _b === void 0 ? void 0 : _b.when) || "{}", language: "json", name: "when" }))), h("ion-grid", null, h("ion-row", null, h("ion-col", { size: "10", class: "ion-align-self-center" }, h("h1", { style: {
          color: "var(--ion-text-color)",
          display: "block",
        } }, "Trigger Batching")), h("ion-col", { size: "2" }, h("fireenjin-toggle", { value: (_d = (_c = this.trigger) === null || _c === void 0 ? void 0 : _c.batch) === null || _d === void 0 ? void 0 : _d.active, color: "primary", lines: "none", label: "Active", labelPosition: "stacked", name: "batch.active" }))), h("ion-row", { style: {
          display: ((_f = (_e = this.trigger) === null || _e === void 0 ? void 0 : _e.batch) === null || _f === void 0 ? void 0 : _f.active) ? "block" : "none",
        } }, h("ion-col", null, h("fireenjin-input", { label: "Frequency", labelPosition: "stacked", name: "batch.frequency", type: "number", min: "5", max: "30" }), h("ion-item", { class: "json-editor-field", style: {
          zIndex: "3",
        } }, h("ion-label", null, h("h2", null, "When is this batched?"), h("fireenjin-code-editor", { autoExpand: true, value: ((_h = (_g = this.trigger) === null || _g === void 0 ? void 0 : _g.batch) === null || _h === void 0 ? void 0 : _h.when) || "{}", language: "json", name: "batch.when" }))), h("ion-item", { class: "json-editor-field" }, h("ion-label", null, h("h2", null, "Do we need to transform the template data?"), h("fireenjin-code-editor", { autoExpand: true, value: ((_k = (_j = this.trigger) === null || _j === void 0 ? void 0 : _j.batch) === null || _k === void 0 ? void 0 : _k.transformer) || "{}", language: "json", name: "batch.transformer" }))))))), h("ion-card-content", { style: {
          opacity: this.currentTab === "action" ? "1" : "0",
          height: this.currentTab === "action" ? "auto" : "0",
          padding: this.currentTab === "action" ? "1rem 2rem" : "0",
        } }, h("ion-grid", null, h("ion-row", null, h("ion-col", { size: "12", sizeMd: ((_l = this.trigger) === null || _l === void 0 ? void 0 : _l.action) === "alert" ? "7" : "12" }, h("fireenjin-select", { name: "action", label: "Action", labelPosition: "stacked", placeholder: "Select an Action", value: (_m = this.trigger) === null || _m === void 0 ? void 0 : _m.action, options: [
          {
            label: "Send Alert",
            value: "alert",
          },
          {
            label: "Run Totaller",
            value: "totaller",
          },
          {
            label: "Sync to Notion",
            value: "notion",
          },
        ], interface: "action-sheet" }), ((_o = this.trigger) === null || _o === void 0 ? void 0 : _o.action) === "notion" && [
        h("fireenjin-select", { name: "payload.databaseId", label: "Notion Page", labelPosition: "stacked", placeholder: "Select a Page", value: (_q = (_p = this.trigger) === null || _p === void 0 ? void 0 : _p.payload) === null || _q === void 0 ? void 0 : _q.databaseId, options: getNotionDatabaseOptions(), interface: "action-sheet" }),
        h("fireenjin-input", { name: "payload.docPath", label: "Firestore Document Path", labelPosition: "stacked", value: (_s = (_r = this.trigger) === null || _r === void 0 ? void 0 : _r.payload) === null || _s === void 0 ? void 0 : _s.docPath, placeholder: "/jobs/{{data.id}}" }),
      ], ((_t = this.trigger) === null || _t === void 0 ? void 0 : _t.action) === "alert" && (h("fireenjin-select", { "data-fill": true, multiple: true, name: "payload.types", label: "Types of Alerts", value: ((_v = (_u = this.trigger) === null || _u === void 0 ? void 0 : _u.payload) === null || _v === void 0 ? void 0 : _v.types) || ["email"], options: [
          "email",
          "feed",
          "text",
          "push",
          "call",
          "slack",
        ].map((value) => ({
          label: value,
          value,
        })) })), ((_w = this.trigger) === null || _w === void 0 ? void 0 : _w.action) === "alert" && (h("fireenjin-select", { name: "payload.templateId", label: "Template", labelPosition: "stacked", placeholder: "Select Message Template", value: ((_y = (_x = this.trigger) === null || _x === void 0 ? void 0 : _x.payload) === null || _y === void 0 ? void 0 : _y.templateId) || null, options: (state.templates || [])
          .filter((template) => !(template === null || template === void 0 ? void 0 : template.partial))
          .map((template) => ({
          label: template === null || template === void 0 ? void 0 : template.subject,
          value: template === null || template === void 0 ? void 0 : template.id,
        })), interface: "action-sheet" }))), ((_z = this.trigger) === null || _z === void 0 ? void 0 : _z.action) === "alert" && (h("ion-col", { size: "12", sizeMd: ((_0 = this.trigger) === null || _0 === void 0 ? void 0 : _0.action) === "alert" ? "5" : "12", style: { overflow: "auto" } }, h("floodteam-template", { id: "email-preview", allowFullscreen: true, zoom: 0.5, rawHtml: ((_1 = (state.templates || []).find((template) => { var _a, _b; return (template === null || template === void 0 ? void 0 : template.id) === ((_b = (_a = this.trigger) === null || _a === void 0 ? void 0 : _a.payload) === null || _b === void 0 ? void 0 : _b.templateId); })) === null || _1 === void 0 ? void 0 : _1.html) || "", data: this.sampleOutput.payload || {} })))), h("ion-row", null, h("ion-col", null, ((_2 = this.trigger) === null || _2 === void 0 ? void 0 : _2.action) === "alert" && (h("fireenjin-select-tags", { name: "payload.emails", label: "Email Addresses", options: (((_4 = (_3 = this.trigger) === null || _3 === void 0 ? void 0 : _3.payload) === null || _4 === void 0 ? void 0 : _4.emails) || []).map((email) => ({
          label: email,
          value: email,
        })), value: ((_6 = (_5 = this.trigger) === null || _5 === void 0 ? void 0 : _5.payload) === null || _6 === void 0 ? void 0 : _6.emails) || [], allowAdding: true })), ((_7 = this.trigger) === null || _7 === void 0 ? void 0 : _7.action) === "alert" && (h("fireenjin-select-tags", { name: "payload.options.email.cc", label: "Email CCs", options: (((_11 = (_10 = (_9 = (_8 = this.trigger) === null || _8 === void 0 ? void 0 : _8.payload) === null || _9 === void 0 ? void 0 : _9.options) === null || _10 === void 0 ? void 0 : _10.email) === null || _11 === void 0 ? void 0 : _11.cc) || []).map((email) => ({
          label: email,
          value: email,
        })), value: ((_15 = (_14 = (_13 = (_12 = this.trigger) === null || _12 === void 0 ? void 0 : _12.payload) === null || _13 === void 0 ? void 0 : _13.options) === null || _14 === void 0 ? void 0 : _14.email) === null || _15 === void 0 ? void 0 : _15.cc) || [], allowAdding: true })), ((_16 = this.trigger) === null || _16 === void 0 ? void 0 : _16.action) === "alert" && (h("fireenjin-select-tags", { name: "payload.options.email.bcc", label: "Email BCCs", options: (((_20 = (_19 = (_18 = (_17 = this.trigger) === null || _17 === void 0 ? void 0 : _17.payload) === null || _18 === void 0 ? void 0 : _18.options) === null || _19 === void 0 ? void 0 : _19.email) === null || _20 === void 0 ? void 0 : _20.bcc) || []).map((email) => ({
          label: email,
          value: email,
        })), value: ((_24 = (_23 = (_22 = (_21 = this.trigger) === null || _21 === void 0 ? void 0 : _21.payload) === null || _22 === void 0 ? void 0 : _22.options) === null || _23 === void 0 ? void 0 : _23.email) === null || _24 === void 0 ? void 0 : _24.bcc) || [], allowAdding: true })), ((_25 = this.trigger) === null || _25 === void 0 ? void 0 : _25.action) === "alert" && (h("fireenjin-select-tags", { name: "payload.userIds", label: "User IDs", options: (((_27 = (_26 = this.trigger) === null || _26 === void 0 ? void 0 : _26.payload) === null || _27 === void 0 ? void 0 : _27.userIds) || []).map((userId) => ({
          label: userId,
          value: userId,
        })), value: ((_29 = (_28 = this.trigger) === null || _28 === void 0 ? void 0 : _28.payload) === null || _29 === void 0 ? void 0 : _29.userIds) || [], allowAdding: true })), ((_30 = this.trigger) === null || _30 === void 0 ? void 0 : _30.action) === "alert" && (h("fireenjin-select-tags", { name: "payload.locationIds", label: "Locations", options: [
          ...(((_32 = (_31 = this.trigger) === null || _31 === void 0 ? void 0 : _31.payload) === null || _32 === void 0 ? void 0 : _32.locationIds) || [])
            .filter((locationId) => {
            var _a, _b;
            return !((_b = (_a = state === null || state === void 0 ? void 0 : state.locations) === null || _a === void 0 ? void 0 : _a.find) === null || _b === void 0 ? void 0 : _b.call(_a, (location) => (location === null || location === void 0 ? void 0 : location.id) === locationId));
          })
            .map((locationId) => ({
            id: locationId,
            name: locationId,
          })),
          ...((state === null || state === void 0 ? void 0 : state.locations) || []),
        ].map(({ id, name }) => ({
          label: name,
          value: id,
        })), value: ((_34 = (_33 = this.trigger) === null || _33 === void 0 ? void 0 : _33.payload) === null || _34 === void 0 ? void 0 : _34.locationIds) || [], allowAdding: true }))))), h("ion-item", { href: "#", detail: true, detailIcon: this.showAdvanced ? "chevron-up" : "chevron-down", onClick: () => (this.showAdvanced = !this.showAdvanced) }, h("ion-label", null, "Advanced")), h("ion-item", { style: {
          opacity: this.showAdvanced ? "1" : "0",
          height: this.showAdvanced ? "auto" : "0",
          overflow: "visible",
        }, class: "json-editor-field" }, h("ion-label", { class: "ion-text-wrap" }, h("h2", null, "What payload is passed to the action?"), h("fireenjin-code-editor", { ref: (el) => (this.payloadEl = el), autoExpand: true, value: JSON.stringify(((_35 = this.trigger) === null || _35 === void 0 ? void 0 : _35.payload) ||
          (((_36 = this.trigger) === null || _36 === void 0 ? void 0 : _36.action) === "totaller"
            ? this.defaultTotallerPayload
            : ((_37 = this.trigger) === null || _37 === void 0 ? void 0 : _37.action) === "notion"
              ? {}
              : this.defaultAlertPayload), null, 4), language: "json", name: "payload" })))), h("ion-card-content", { style: {
          opacity: this.currentTab === "test" ? "1" : "0",
          height: this.currentTab === "test" ? "auto" : "0",
          padding: this.currentTab === "test" ? "1rem 2rem" : "0",
        } }, h("ion-grid", null, h("ion-row", null, h("ion-col", { size: "12", sizeMd: "6" }, h("fireenjin-code-editor", { ref: (el) => (this.sampleDataEl = el), autoExpand: true, value: JSON.stringify(((_38 = this.trigger) === null || _38 === void 0 ? void 0 : _38.sampleData) || {}, null, 4), language: "json", name: "sampleData" })), h("ion-col", { size: "12", sizeMd: "6" }, h("fireenjin-json-viewer", { ref: (el) => (this.jsonViewerEl = el), watcher: true }))))))), h("br", null), h("br", null), h("br", null), h("br", null), h("br", null), h("br", null), h("br", null), h("br", null)),
      h("floodteam-navigation-footer", null, h("floodteam-title-bar", { back: "/triggers" }, h("ion-breadcrumbs", null, h("ion-breadcrumb", { href: "/triggers" }, h("ion-icon", { class: "ft-icon-style", slot: "start", name: "flash" }), "Triggers"), h("ion-breadcrumb", { onClick: () => {
          var _a;
          return this.fireenjinTrigger.emit({
            name: "pin",
            payload: {
              icon: "flash",
              href: `/triggers/${this.triggerId}`,
              name: ((_a = this.trigger) === null || _a === void 0 ? void 0 : _a.name) || "Add a Trigger",
            },
          });
        } }, h("ion-icon", { color: ((_39 = ((state === null || state === void 0 ? void 0 : state.pins) || [])
          .map((pin) => pin === null || pin === void 0 ? void 0 : pin.href)) === null || _39 === void 0 ? void 0 : _39.includes(`/triggers/${this.triggerId}`))
          ? "primary"
          : null, slot: "start", name: "pin" }), (this.triggerId === "new" && "Add a Trigger") ||
        ((_40 = this.trigger) === null || _40 === void 0 ? void 0 : _40.name) ||
        "Edit Trigger")), h("ion-buttons", { slot: "end" }, h("ion-button", { color: this.triggerWillFire ? "warning" : "medium", fill: this.triggerWillFire ? "solid" : "outline", disabled: !this.triggerWillFire, onClick: () => this.fireenjinSubmit.emit({
          endpoint: "addAlert",
          data: JSON.parse(this.generateSampleOutput()),
        }) }, "Fire"), h("ion-button", { fill: "solid", color: "primary", onClick: () => this.save() }, "Save")))),
      ,
    ];
  }
  static get is() { return "app-trigger"; }
  static get originalStyleUrls() {
    return {
      "$": ["app-trigger.css"]
    };
  }
  static get styleUrls() {
    return {
      "$": ["app-trigger.css"]
    };
  }
  static get properties() {
    return {
      "triggerId": {
        "type": "any",
        "mutable": false,
        "complexType": {
          "original": "any",
          "resolved": "any",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "trigger-id",
        "reflect": false
      }
    };
  }
  static get states() {
    return {
      "trigger": {},
      "triggerWillFire": {},
      "currentTab": {},
      "showAdvanced": {},
      "payload": {}
    };
  }
  static get events() {
    return [{
        "method": "fireenjinFetch",
        "name": "fireenjinFetch",
        "bubbles": true,
        "cancelable": true,
        "composed": true,
        "docs": {
          "tags": [],
          "text": ""
        },
        "complexType": {
          "original": "any",
          "resolved": "any",
          "references": {}
        }
      }, {
        "method": "fireenjinSubmit",
        "name": "fireenjinSubmit",
        "bubbles": true,
        "cancelable": true,
        "composed": true,
        "docs": {
          "tags": [],
          "text": ""
        },
        "complexType": {
          "original": "FireEnjinSubmitEvent",
          "resolved": "FireEnjinSubmitEvent",
          "references": {
            "FireEnjinSubmitEvent": {
              "location": "import",
              "path": "@fireenjin/sdk"
            }
          }
        }
      }, {
        "method": "fireenjinTrigger",
        "name": "fireenjinTrigger",
        "bubbles": true,
        "cancelable": true,
        "composed": true,
        "docs": {
          "tags": [],
          "text": ""
        },
        "complexType": {
          "original": "FireEnjinTriggerInput",
          "resolved": "FireEnjinTriggerInput",
          "references": {
            "FireEnjinTriggerInput": {
              "location": "import",
              "path": "@fireenjin/sdk"
            }
          }
        }
      }];
  }
  static get listeners() {
    return [{
        "name": "ionInput",
        "method": "ionChange",
        "target": undefined,
        "capture": false,
        "passive": false
      }, {
        "name": "ionChange",
        "method": "onChange",
        "target": undefined,
        "capture": false,
        "passive": false
      }, {
        "name": "fireenjinCodeChange",
        "method": "onCodeChange",
        "target": undefined,
        "capture": false,
        "passive": false
      }, {
        "name": "fireenjinSuccess",
        "method": "onSuccess",
        "target": "document",
        "capture": false,
        "passive": false
      }, {
        "name": "ionRouteDidChange",
        "method": "componentDidLoad",
        "target": undefined,
        "capture": false,
        "passive": false
      }];
  }
}
