/* COPYRIGHT Esri - https://js.arcgis.com/1.2/LICENSE.txt */
import { c as customElement } from "../../chunks/runtime.js";
import { css, html } from "lit";
import { b as calculatePCI } from "../../chunks/pciUtils.js";
import { createRef, ref } from "lit-html/directives/ref.js";
import { LitElement, safeClassMap } from "@arcgis/lumina";
const styles = css`/** @license
 * Copyright 2025 Esri
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

:host {
  display: block;
  --calcite-label-margin-bottom: 0;
}

.label-display {
  display: block;
  padding-bottom: 1rem;
}

.display-flex {
  display: flex;
}

.display-grid {
  display: grid;
}

.display-none {
  display: none;
}

.padding-top-1 {
  padding-top: 1rem;
}

.main-input {
  width: 300px;
  padding-inline-end: 1rem;
}

.float-end {
  float: inline-end;
}

.position-relative {
  position: relative;
}

.position-right {
  position: absolute;
  right: 0px;
}`;
class PciCalculator extends LitElement {
  constructor() {
    super(...arguments);
    this.showAddDeduct = false;
    this._deductValuesElement = createRef();
  }
  static {
    this.properties = { showAddDeduct: [16, {}, { state: true }] };
  }
  static {
    this.styles = styles;
  }
  render() {
    const pciClass = !this.showAddDeduct ? "display-grid" : "display-none";
    const deductClass = this.showAddDeduct ? "position-relative" : "display-none";
    return html`<div class=${safeClassMap(pciClass)}><div class="label-display"><calcite-label class="label-display">\r\n              Enter comma delimited deduct values${this._getDeductValuesInput()}</calcite-label></div><div>${this._getCalculateButton()}</div></div><div class=${safeClassMap(deductClass)}><div class="position-right"><calcite-action appearance=transparent class="float-end" icon=x @click=${() => this._toggleShowAddDeduct()} scale=s text></calcite-action></div><deduct-calculator class="display-grid padding-top-1" @deductValueComplete=${this._addDeductValue}></deduct-calculator></div>`;
  }
  _getDeductValuesInput() {
    return html`<div class="display-flex"><calcite-input class="main-input" ${ref(this._deductValuesElement)}></calcite-input><calcite-action appearance=transparent icon=plus-circle @click=${() => this._toggleShowAddDeduct()} scale=s text></calcite-action></div>`;
  }
  _getCalculateButton() {
    return this._deductValuesElement.value ? html`<calcite-button @click=${() => this._calculatePCI(this._deductValuesElement?.value?.value || "")}>\r\n        Calculate PCI</calcite-button>` : void 0;
  }
  _toggleShowAddDeduct() {
    this.showAddDeduct = !this.showAddDeduct;
  }
  _addDeductValue(_evt) {
    this._toggleShowAddDeduct();
    if (this._deductValuesElement.value) {
      this._deductValuesElement.value.value += Math.abs(Number.parseFloat(this._deductValuesElement.value.value)) > 0 ? `,${_evt.detail}` : _evt.detail;
    }
  }
  _calculatePCI(deductValuesString) {
    const pci = calculatePCI(deductValuesString, true);
    const rating = pci <= 10 ? "Failed" : pci <= 25 ? "Serious" : pci <= 40 ? "Very Poor" : pci <= 55 ? "Poor" : pci <= 70 ? "Fair" : pci <= 85 ? "Satisfactory" : "Good";
    console.log(`PCI: ${pci}`);
    console.log(`Rating: ${rating}`);
    alert("See debug console for results");
  }
}
customElement("pci-calculator", PciCalculator);
export {
  PciCalculator
};
