'use strict';

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

const index = require('./index-cba1c3ae.js');
const store = require('./store-49e3b933.js');
require('./getHandlebarsHelpers-7b2b1728.js');
require('./_commonjsHelpers-a5111d61.js');
require('./logic-d8c34975.js');
require('./index-1f381af8.js');
require('./localforage-af1b8c0e.js');

const FormSiteAreas = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.fireenjinSubmit = index.createEvent(this, "fireenjinSubmit", 7);
    this.isAffected = false;
  }
  onChange(event) {
    var _a;
    if (event.target.name === "affected") {
      this.isAffected = !!((_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.checked);
    }
  }
  removeArea(index, affected) {
    var _a, _b, _c, _d, _e, _f;
    if (!confirm("Are you sure you want to remove this area?"))
      return;
    if (affected) {
      const affectedAreas = ((_a = store.state === null || store.state === void 0 ? void 0 : store.state.site) === null || _a === void 0 ? void 0 : _a.affectedAreas) || [];
      store.state.site.affectedAreas = (_b = affectedAreas.filter) === null || _b === void 0 ? void 0 : _b.call(affectedAreas, (_area, i) => i !== index);
    }
    else {
      const areas = ((_c = store.state.site) === null || _c === void 0 ? void 0 : _c.areas) || [];
      store.state.site.areas = (_d = areas.filter) === null || _d === void 0 ? void 0 : _d.call(areas, (_area, i) => i !== index);
    }
    store.state.site = { ...store.state === null || store.state === void 0 ? void 0 : store.state.site };
    this.fireenjinSubmit.emit({
      endpoint: "editSite",
      id: this.siteId,
      data: {
        jobId: this.jobId,
        areas: ((_e = store.state.site) === null || _e === void 0 ? void 0 : _e.areas) || [],
        affectedAreas: ((_f = store.state.site) === null || _f === void 0 ? void 0 : _f.affectedAreas) || [],
      },
    });
  }
  render() {
    var _a, _b, _c, _d, _e, _f, _g;
    return [
      index.h("fireenjin-form", { name: "measure", hideControls: true, disableLoader: true, endpoint: this.siteId ? "editSite" : "addSite", documentId: this.siteId, beforeSubmit: async (data) => {
          var _a, _b;
          const affectedAreas = ((_a = store.state.site) === null || _a === void 0 ? void 0 : _a.affectedAreas) || [];
          const areas = ((_b = store.state.site) === null || _b === void 0 ? void 0 : _b.areas) || [];
          if (this.isAffected) {
            affectedAreas.push({
              height: ((data === null || data === void 0 ? void 0 : data.height) && parseFloat(data.height)) || 0,
              length: ((data === null || data === void 0 ? void 0 : data.length) && parseFloat(data.length)) || 0,
              width: ((data === null || data === void 0 ? void 0 : data.width) && parseFloat(data.width)) || 0,
            });
          }
          else {
            areas.push({
              height: ((data === null || data === void 0 ? void 0 : data.height) && parseFloat(data.height)) || 0,
              length: ((data === null || data === void 0 ? void 0 : data.length) && parseFloat(data.length)) || 0,
              width: ((data === null || data === void 0 ? void 0 : data.width) && parseFloat(data.width)) || 0,
            });
          }
          return { jobId: this.jobId, areas, affectedAreas };
        } }, index.h("ion-grid", null, index.h("ion-row", { class: "ion-align-items-center" }, index.h("ion-col", { size: "2" }, index.h("ion-label", { style: {
          fontSize: "14px !important",
          fontWeight: "bold",
          display: "block",
          background: "transparent",
          textAlign: "left",
          padding: "0",
          fontFamily: "var(--ion-font-family)",
          marginBottom: "14px",
        }, position: "stacked" }, "Affected"), index.h("ion-toggle", { style: { padding: "5px 5px 5px 5px" }, name: "affected" })), index.h("ion-col", { size: "3" }, index.h("fireenjin-input", { type: "number", label: "Length", labelPosition: "stacked", name: "length", required: true })), index.h("ion-col", { size: "3" }, index.h("fireenjin-input", { type: "number", label: "Width", labelPosition: "stacked", name: "width", required: true })), index.h("ion-col", { size: "3" }, index.h("fireenjin-input", { type: "number", label: "Height", labelPosition: "stacked", name: "height" })), index.h("ion-col", { size: "1" }, index.h("ion-button", { type: "submit", size: "small", color: "primary" }, index.h("ion-icon", { slot: "icon-only", name: "add-circle" })))))),
      index.h("ion-list", null, index.h("ion-item-divider", null, index.h("ion-label", null, "Affected Areas"), index.h("div", { slot: "end" }, index.h("ion-text", null, ((_a = store.state.site) === null || _a === void 0 ? void 0 : _a.affectedAreaTotalSqft)
        ? store.state.site.affectedAreaTotalSqft
        : 0, " ", "sqft", " "), index.h("ion-text", null, ((_b = store.state.site) === null || _b === void 0 ? void 0 : _b.affectedAreaTotalCuft)
        ? store.state.site.affectedAreaTotalCuft
        : 0, " ", "cuft", " "))), (((_c = store.state.site) === null || _c === void 0 ? void 0 : _c.affectedAreas) ? (_d = store.state.site) === null || _d === void 0 ? void 0 : _d.affectedAreas : []).map((area, index$1) => (index.h("ion-item", null, index.h("ion-label", null, (area === null || area === void 0 ? void 0 : area.length) ? area.length : 0, " ft", " x ", (area === null || area === void 0 ? void 0 : area.width) ? area.width : 0, " ft", " x ", (area === null || area === void 0 ? void 0 : area.height) ? area.height : 0, " ft"), index.h("ion-button", { onClick: () => this.removeArea(index$1, true), fill: "clear", slot: "end", style: {
          "--color": "var(--ion-text-color)",
          "--color-hover": "var(--ion-color-danger",
        } }, index.h("ion-icon", { slot: "icon-only", name: "close-circle" }))))), index.h("ion-item-divider", null, index.h("ion-label", null, "Site Areas"), index.h("div", { slot: "end" }, index.h("ion-text", null, ((_e = store.state.site) === null || _e === void 0 ? void 0 : _e.areaTotalSqft) ? store.state.site.areaTotalSqft : 0, " sqft", " "), index.h("ion-text", null, ((_f = store.state.site) === null || _f === void 0 ? void 0 : _f.areaTotalCuft) ? store.state.site.areaTotalCuft : 0, " cuft", " "))), (((_g = store.state.site) === null || _g === void 0 ? void 0 : _g.areas) ? store.state.site.areas : []).map((area, index$1) => (index.h("ion-item", null, index.h("ion-label", null, (area === null || area === void 0 ? void 0 : area.length) ? area.length : 0, " ft", " x ", (area === null || area === void 0 ? void 0 : area.width) ? area.width : 0, " ft", " x ", (area === null || area === void 0 ? void 0 : area.height) ? area.height : 0, " ft"), index.h("ion-button", { onClick: () => this.removeArea(index$1), fill: "clear", slot: "end", style: {
          "--color": "var(--ion-text-color)",
          "--color-hover": "var(--ion-color-danger",
        } }, index.h("ion-icon", { slot: "icon-only", name: "close-circle" })))))),
    ];
  }
};

const FormSiteInfo = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
  }
  render() {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
    return (index.h("fireenjin-form", { name: "info", endpoint: ((_a = store.state.site) === null || _a === void 0 ? void 0 : _a.id) ? "editSite" : "addSite", submitButton: ((_b = store.state.site) === null || _b === void 0 ? void 0 : _b.id) ? "Save" : "Next", resetButton: ((_c = store.state.site) === null || _c === void 0 ? void 0 : _c.id) ? "Delete Site" : null, resetButtonColor: "danger", beforeSubmit: (data) => ({
        ...data,
        jobId: this.jobId,
        chamber: ((data === null || data === void 0 ? void 0 : data.chamber) && parseInt(data.chamber)) || 0,
        class: ((data === null || data === void 0 ? void 0 : data.class) && parseInt(data.class)) || 0,
        level: ((data === null || data === void 0 ? void 0 : data.level) && parseInt(data.level)) || 0,
        offsets: ((data === null || data === void 0 ? void 0 : data.offsets) && parseInt(data.offsets)) || 0,
      }), documentId: (_d = store.state.site) === null || _d === void 0 ? void 0 : _d.id, disableLoader: true, disableEnterButton: true }, index.h("ion-grid", null, index.h("ion-row", null, index.h("ion-col", null, index.h("floodteam-input-room", { label: "Room", labelPosition: "stacked", value: (_e = store.state.site) === null || _e === void 0 ? void 0 : _e.name, required: true }))), index.h("ion-row", null, index.h("ion-col", { size: "6", sizeSm: "3" }, index.h("fireenjin-input", { label: "Level", labelPosition: "stacked", type: "number", placeholder: "What level is the site on?", name: "level", value: (_f = store.state.site) === null || _f === void 0 ? void 0 : _f.level })), index.h("ion-col", { size: "6", sizeSm: "3" }, index.h("fireenjin-input", { label: "Chamber", labelPosition: "stacked", type: "number", placeholder: "What drying chamber is this in?", name: "chamber", value: (_g = store.state.site) === null || _g === void 0 ? void 0 : _g.chamber })), index.h("ion-col", { size: "6", sizeSm: "3" }, index.h("fireenjin-input", { label: "Offsets", labelPosition: "stacked", type: "number", placeholder: "Wall Offsets", name: "offsets", value: (_h = store.state.site) === null || _h === void 0 ? void 0 : _h.offsets })), index.h("ion-col", { size: "6", sizeSm: "3" }, index.h("fireenjin-input", { label: "Class", labelPosition: "stacked", type: "number", placeholder: "What class of water loss in this site?", name: "class", value: (_j = store.state.site) === null || _j === void 0 ? void 0 : _j.class }))), index.h("ion-row", null, index.h("ion-col", null, index.h("ion-item-divider", null, "Material Info"))), index.h("ion-row", null, index.h("ion-col", { size: "12", sizeSm: "6", sizeMd: "4" }, index.h("floodteam-input-material", { label: "Flooring", labelPosition: "stacked", name: "floorType", options: [
        {
          label: "Tile",
          value: "tile",
        },
        {
          label: "Carpet & Pad",
          value: "carpet",
        },
        {
          label: "Concrete",
          value: "concrete",
        },
        {
          label: "Wood",
          value: "wood",
        },
      ], value: (_k = store.state.site) === null || _k === void 0 ? void 0 : _k.floorType })), index.h("ion-col", { size: "12", sizeSm: "6", sizeMd: "4" }, index.h("floodteam-input-material", { label: "Walling", labelPosition: "stacked", name: "wallType", options: [
        {
          label: "Drywall",
          value: "drywall",
        },
        {
          label: "Insulation",
          value: "insulation",
        },
      ], value: (_l = store.state.site) === null || _l === void 0 ? void 0 : _l.wallType })), index.h("ion-col", { size: "12", sizeSm: "6", sizeMd: "4" }, index.h("floodteam-input-material", { label: "Ceiling Type", labelPosition: "stacked", name: "ceilingType", value: (_m = store.state.site) === null || _m === void 0 ? void 0 : _m.ceilingType }))))));
  }
};

const photoCarouselCss = "floodteam-photo-carousel{display:block;position:relative;margin:0 auto;min-height:200px;padding-top:56.25%;}floodteam-photo-carousel ion-slides::after{content:\"\";display:block;height:40px;width:100%;position:absolute;left:0;right:0;top:0;background:transparent;background:linear-gradient(\n    0deg,\n    rgba(0, 0, 0, 0) 10%,\n    rgba(0, 0, 0, 0.3) 80%\n  )}floodteam-photo-carousel ion-slides{position:absolute !important;top:0;left:0;right:0;bottom:0;overflow:hidden !important}floodteam-photo-carousel ion-slide{margin:auto}floodteam-photo-carousel input[type=\"file\"]{height:0px;width:0px;visibility:hidden;opacity:0 !important;display:block;overflow:hidden;float:left}floodteam-photo-carousel floodteam-fallback{--floodteam-fallback-icon-size:10vw}floodteam-photo-carousel floodteam-fallback ion-icon{max-width:120px;max-height:120px;color:var(--ion-color-base-dark)}floodteam-photo-carousel .photo-pagination{position:absolute;top:10px;left:8px;color:#666;display:block;z-index:2;padding-right:10px}@media only screen and (max-width: 500px){floodteam-photo-carousel .photo-pagination{top:5px;left:4px}floodteam-photo-carousel ion-fab-button{height:45px !important;width:45px !important}}";

const PhotoCarousel = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.fireenjinTrigger = index.createEvent(this, "fireenjinTrigger", 7);
    this.badgeColor = "medium";
    this.addButtonColor = "primary";
    this.hideAddButton = false;
    this.photos = [];
    this.currentSlide = 0;
    this.options = {};
    this.name = "photocarousel";
    this.type = "site";
    this.multiple = true;
    this.tags = [];
  }
  async onSlideChange() {
    this.currentSlide = (await this.photoSlidesEl.getActiveIndex()) + 1;
  }
  async getCurrentSlide() {
    this.currentSlide = (await this.photoSlidesEl.getActiveIndex()) + 1;
    return this.currentSlide;
  }
  async getPhoto() {
    return this.photos[this.currentSlide - 1];
  }
  async slideNext() {
    return this.photoSlidesEl.slideNext();
  }
  async slidePrev() {
    return this.photoSlidesEl.slidePrev();
  }
  async slideTo(slideNumber) {
    return this.photoSlidesEl.slideTo(slideNumber - 1);
  }
  async selectFiles() {
    this.fireenjinTrigger.emit({
      name: "photos",
      multiple: !!this.multiple,
      payload: {
        path: this.uploadPath || `jobs/${this.jobId}/photos`,
        jobId: this.jobId,
        siteId: this.siteId,
        tags: this.tags || [],
      },
    });
  }
  async update() {
    this.currentSlide = (await this.photoSlidesEl.getActiveIndex()) + 1;
    return this.photoSlidesEl.update();
  }
  componentDidLoad() {
    var _a;
    if (!(index.Build === null || index.Build === void 0 ? void 0 : index.Build.isBrowser))
      return;
    if (!((_a = this.photoSlidesEl) === null || _a === void 0 ? void 0 : _a.getActiveIndex)) {
      setTimeout(this.componentDidLoad, 200);
      return;
    }
    setTimeout(async () => {
      this.currentSlide = (await this.photoSlidesEl.getActiveIndex()) + 1;
      await this.photoSlidesEl.update();
    }, 200);
  }
  render() {
    var _a, _b;
    return (index.h(index.Host, null, ((_a = this.photos) === null || _a === void 0 ? void 0 : _a.length) ? (index.h("ion-badge", { color: this.badgeColor, class: "photo-pagination" }, this.currentSlide, " / ", this.photos.length)) : null, !this.hideAddButton ? (index.h("ion-button", { class: "select-photo ion-float-right", color: this.addButtonColor, onClick: () => this.selectFiles() }, "Add")) : null, ((_b = this.photos) === null || _b === void 0 ? void 0 : _b.length) ? (index.h("ion-slides", { ref: (el) => (this.photoSlidesEl = el), pager: false, options: this.options }, this.photos.map((photo) => (index.h("ion-slide", null, index.h("ion-img", { src: photo.url })))))) : (index.h("floodteam-fallback", { icon: "image", message: "No Picture Taken..." }))));
  }
};
PhotoCarousel.style = photoCarouselCss;

exports.floodteam_form_site_areas = FormSiteAreas;
exports.floodteam_form_site_info = FormSiteInfo;
exports.floodteam_photo_carousel = PhotoCarousel;
