import { r as registerInstance, d as createEvent, h } from './index-33e43734.js';
import { f as formatUSD } from './formatUSD-dae09890.js';

let FormSiteService = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.fireenjinSubmit = createEvent(this, "fireenjinSubmit", 7);
    this.isGeneral = false;
    this.amount = 0;
    this.quantity = 1;
    this.price = 0;
  }
  onSuccess(event) {
    var _a, _b, _c, _d, _e;
    if (((_a = event === null || event === void 0 ? void 0 : event.detail) === null || _a === void 0 ? void 0 : _a.endpoint) === "deleteScopeService") {
      this.amount = 0;
      this.quantity = 1;
      this.siteServiceId = null;
    }
    else if (((_b = event === null || event === void 0 ? void 0 : event.detail) === null || _b === void 0 ? void 0 : _b.endpoint) === "addScopeService") {
      this.siteServiceId = (_e = (_d = (_c = event === null || event === void 0 ? void 0 : event.detail) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.addScopeService) === null || _e === void 0 ? void 0 : _e.id;
    }
  }
  onReset(event) {
    this.fireenjinSubmit.emit({
      endpoint: "deleteScopeService",
      event,
      data: {
        id: this.siteServiceId,
        siteId: this.siteId,
        jobId: this.jobId,
      },
    });
  }
  render() {
    return (h("ion-accordion", { value: `${this.isGeneral ? this.jobId : this.siteId}-${this.serviceId}` }, h("ion-item", { slot: "header" }, h("ion-label", null, h("h2", null, this.name ||
      (this.isGeneral ? "General Service" : "No Site Name")), this.siteServiceId ? (h("ion-text", { color: "primary" }, h("b", null, this.amount || 0, " ", (this === null || this === void 0 ? void 0 : this.unit) || ""), " ", "x ", h("b", null, this.quantity || 1, " Qty"), " x", " ", h("b", null, formatUSD(this.price || 0)))) : (h("p", null, "Click to Add"))), h("ion-text", { color: "success", slot: "end" }, this.siteServiceId && (h("small", null, formatUSD(parseFloat(this.amount || 0) *
      parseFloat(this.quantity || 1) *
      parseFloat(this.price || 0)))))), h("fireenjin-form", { slot: "content", disableLoader: true, name: `siteService-${this.siteId}-${this.serviceId}`, resetButton: "Remove", resetButtonColor: "danger", disableReset: true, endpoint: this.siteServiceId ? "editScopeService" : "addScopeService", beforeSubmit: async (data) => {
        const formData = {
          jobId: this.jobId,
          siteId: this.siteId,
          ...(this.siteServiceId
            ? { id: this.siteServiceId }
            : { serviceId: this.serviceId }),
          quantity: parseFloat((data === null || data === void 0 ? void 0 : data.quantity) || this.quantity || 1),
          amount: parseFloat((data === null || data === void 0 ? void 0 : data.amount) || this.amount || 1),
        };
        if (data === null || data === void 0 ? void 0 : data.price) {
          try {
            formData.price = parseFloat((data === null || data === void 0 ? void 0 : data.price) || 0);
          }
          catch (error) {
            console.log("Error setting price: ", error);
          }
        }
        return formData;
      } }, h("ion-grid", { class: "ion-no-padding" }, h("ion-row", { class: "ion-no-padding" }, h("ion-col", { size: "6", sizeXs: "4" }, h("fireenjin-input", { type: "number", name: "amount", value: this.amount || 0, label: "Amount", labelPosition: "stacked", min: "0", step: "0.01" })), h("ion-col", { size: "6", sizeXs: "4" }, h("fireenjin-input", { type: "number", name: "quantity", value: this.quantity || 1, label: "Quantity", labelPosition: "stacked", min: "1" })), h("ion-col", { size: "12", sizeXs: "4" }, h("fireenjin-input", { type: "number", name: "price", value: this.price || 0, label: "Price", labelPosition: "stacked", step: "0.01", min: "0" })))))));
  }
};

export { FormSiteService as floodteam_form_site_service };

//# sourceMappingURL=floodteam-form-site-service.entry.js.map