'use strict';

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

const index = require('./index-e0385008.js');

const inputMeasureCss = "floodteam-input-measure ion-label{--padding-start:0;--padding-end:0}";

const InputMeasure = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.name = "size";
    this.disabled = false;
    this.required = false;
    this.value = undefined;
    this.lines = "full";
    this.label = undefined;
    this.labelPosition = "stacked";
    this.unit = "ft";
    this.unitOptions = [
      {
        name: "feet",
        label: "Feet",
        value: "ft",
      },
      {
        name: "inche",
        label: "Inches",
        value: "in",
      },
    ];
    this.disableUnit = false;
    this.totalInches = undefined;
  }
  async onValue(value, oldVal) {
    if (`${value}` === `${oldVal}`)
      return;
    const [feet, inchesDecimal] = (this.value || 0).toString().split(".");
    const inches = Math.round(parseFloat(`0.${inchesDecimal || 0}`) * 12);
    this.totalInches = parseInt(feet || "0") * 12 + inches;
    if (this.unit === "ft") {
      this.feetInputEl.value = feet || 0;
      this.inchesInputEl.value = inches || 0;
    }
    else {
      this.feetInputEl.value = 0;
      this.inchesInputEl.value = this.totalInches || 0;
    }
  }
  async updateValue() {
    var _a, _b, _c;
    this.totalInches =
      this.unit === "ft"
        ? parseInt(((_a = this.feetInputEl) === null || _a === void 0 ? void 0 : _a.value) || "0") * 12 +
          parseInt(((_b = this.inchesInputEl) === null || _b === void 0 ? void 0 : _b.value) || "0")
        : parseInt(((_c = this.inchesInputEl) === null || _c === void 0 ? void 0 : _c.value) || "0");
    this.value = this.totalInches / 12;
  }
  async changeUnit(value) {
    this.unit = value || "ft";
    if (this.unit === "ft") {
      const [feet, inchesDecimal] = (this.value || 0).toString().split(".");
      const inches = Math.round(parseFloat(`0.${inchesDecimal || "0"}`) * 12);
      this.feetInputEl.value = parseInt(feet || "0");
      this.inchesInputEl.value = inches || 0;
    }
    else {
      this.feetInputEl.value = 0;
      this.inchesInputEl.value = this.totalInches || 0;
    }
  }
  render() {
    return (index.h(index.Host, null, index.h("ion-item", { style: {
        "--padding-start": "4px",
        "--inner-padding-end": "0",
      }, lines: this.lines }, this.label && (index.h("ion-label", { position: this.labelPosition }, this.label)), index.h("ion-grid", { class: "ion-no-padding" }, index.h("ion-row", { class: "ion-no-padding", style: {
        paddingTop: "8px",
      } }, index.h("ion-col", { class: "ion-no-padding", style: {
        position: "relative",
        opacity: this.unit === "ft" ? "1" : "0",
        height: this.unit === "ft" ? "auto" : "0",
      }, size: this.unit === "ft" ? "6" : "12" }, index.h("ion-input", { ref: (el) => (this.feetInputEl = el), disabled: this.disabled, onIonChange: () => this.updateValue(), type: "number", placeholder: this.unit, min: 0 }), index.h("small", { style: {
        opacity: "0.8",
        position: "absolute",
        top: "3px",
        right: "15px",
        pointerEvents: "none",
      } }, "'")), index.h("ion-col", { class: "ion-no-padding", size: this.unit === "ft" ? "6" : "12", style: {
        position: "relative",
      } }, index.h("ion-input", { onIonChange: () => this.updateValue(), placeholder: this.unit === "ft" && "in", ref: (el) => (this.inchesInputEl = el), disabled: this.disabled, type: "number", min: 0, max: this.unit === "ft" && 11 }), index.h("small", { style: {
        opacity: "0.8",
        position: "absolute",
        top: "3px",
        right: "15px",
        pointerEvents: "none",
      } }, "\"")))), index.h("ion-chip", { slot: "end", style: { margin: "0", float: "right" } }, this.unit, index.h("ion-select", { style: {
        opacity: "0",
        display: "flex",
        width: "0",
        margin: "0",
        padding: "0",
      }, onIonChange: (event) => { var _a; return this.changeUnit((_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.value); }, selectedText: this.unit, disabled: this.disableUnit, value: this.unit }, (this.unitOptions || []).map((option) => (index.h("ion-select-option", { value: option === null || option === void 0 ? void 0 : option.value }, (option === null || option === void 0 ? void 0 : option.label) || (option === null || option === void 0 ? void 0 : option.name))))), index.h("ion-icon", { name: "chevron-down-circle" }))), index.h("ion-input", { name: this.name, value: this.value, style: { height: "0", width: "0", opacity: "0" }, required: this.required })));
  }
  static get watchers() { return {
    "value": ["onValue"]
  }; }
};
InputMeasure.style = inputMeasureCss;

exports.floodteam_input_measure = InputMeasure;
