/* COPYRIGHT Esri - https://js.arcgis.com/1.2/LICENSE.txt */
import { c as customElement } from "../../chunks/runtime.js";
import { css, html } from "lit";
import { E as EDistressType, a as ESeverity, c as calculateDeductValue } from "../../chunks/pciUtils.js";
import { createRef, ref } from "lit-html/directives/ref.js";
import { LitElement, createEvent } 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;
}`;
class DeductCalculator extends LitElement {
  constructor() {
    super(...arguments);
    this._densityElement = createRef();
    this._typeElement = createRef();
    this._severityElement = createRef();
    this._types = Object.keys(EDistressType).filter((k) => !Number.isNaN(Number(EDistressType[k])));
    this.deductValueComplete = createEvent();
  }
  static {
    this.styles = styles;
  }
  render() {
    return html`<div class="label-display"><calcite-label class="label-display">\r\n            Density %${this._getDensityInput()}</calcite-label><calcite-label class="label-display">\r\n            Type${this._getTypeInput()}</calcite-label><calcite-label class="label-display">\r\n            Severity${this._getSeverityInput()}</calcite-label></div><div>${this._getCalculateInput()}</div>`;
  }
  _getDensityInput() {
    return html`<calcite-input max=100 min=0 type=number ${ref(this._densityElement)}></calcite-input>`;
  }
  _getTypeInput() {
    return html`<calcite-select label ${ref(this._typeElement)}>${this._types.map((t, i) => html`<calcite-option .value=${EDistressType[t].toString()}>${`${t} (${i + 1})`}</calcite-option>`)}</calcite-select>`;
  }
  _getSeverityInput() {
    return html`<calcite-select label ${ref(this._severityElement)}><calcite-option .value=${ESeverity.H}>\r\n          High</calcite-option><calcite-option .value=${ESeverity.M}>\r\n          Medium</calcite-option><calcite-option .value=${ESeverity.L}>\r\n          Low</calcite-option></calcite-select>`;
  }
  _getCalculateInput() {
    const _type = this._typeElement.value && Number.parseFloat(this._typeElement.value.value);
    const _sev = this._severityElement.value && this._severityElement.value.value;
    const _den = this._densityElement.value && Number.parseFloat(this._densityElement.value.value);
    return html`<calcite-button @click=${() => this._calculateDeduct(_type, _sev, _den)}>\r\n        Calculate Deduct Value</calcite-button>`;
  }
  _calculateDeduct(type, severity, density) {
    if (type && severity && !Number.isNaN(density)) {
      const dv = calculateDeductValue(type.toString(), severity.toString(), density.toString(), true);
      this.deductValueComplete.emit(dv);
      alert(dv);
    } else {
      alert("Type, severity, and a density number are required");
    }
  }
}
customElement("deduct-calculator", DeductCalculator);
export {
  DeductCalculator
};
