'use strict';

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

const index$1 = require('./index-df541290.js');
const index$2 = require('./index-07607ed6.js');
const index = require('./index-aa81d689.js');
require('./index-e4cf4aa6.js');
require('./_commonjsHelpers-5bbc2693.js');

const sv = {
  Qty: "Antal",
  Unit: "Enhet",
  Name: "Namn",
  Price: "Pris",
  VAT: "Moms",
  "Clear/remove item": "Töm/ta bort artikel",
};

function create(language) {
  return index.dist.create({
    sv,
  }, language);
}

const styleCss = ".sc-ig-item-input-h{display:block}[hidden].sc-ig-item-input-h{display:none}*.sc-ig-item-input{z-index:0}.sc-ig-item-input-h>form.sc-ig-item-input{display:flex;flex-wrap:nowrap}.sc-ig-item-input-h>form.sc-ig-item-input>smoothly-input.sc-ig-item-input{border:1px solid rgb(var(--smoothly-medium-color));margin-left:-1px;flex-grow:1}.sc-ig-item-input-h>form.sc-ig-item-input>smoothly-input.sc-ig-item-input>#itemName.sc-ig-item-input{flex-grow:2}.sc-ig-item-input-h>form.sc-ig-item-input>smoothly-trigger.sc-ig-item-input{float:right;padding-top:.3em}";

const IntergiroItemInput = class {
  constructor(hostRef) {
    index$1.registerInstance(this, hostRef);
    this.itemChanged = index$1.createEvent(this, "itemChanged", 7);
    this.itemCleared = index$1.createEvent(this, "itemCleared", 7);
    this.item = {};
  }
  componentWillLoad() {
    this.t = create(this.element);
  }
  clearInputs(e) {
    if (e.detail.name == "clear") {
      e.stopPropagation();
      e.preventDefault();
      const quantity = document.getElementById("itemQuantity");
      const unit = document.getElementById("itemUnit");
      const name = document.getElementById("itemName");
      const price = document.getElementById("itemPrice");
      const vat = document.getElementById("itemVat");
      const inputs = [quantity, unit, name, price, vat];
      for (const input of inputs)
        if (hasStringValue(input) || hasNumberValue(input))
          input.value = "";
      this.updateItem();
      this.itemCleared.emit();
    }
  }
  updateItem() {
    const quantity = document.getElementById("itemQuantity");
    const unit = document.getElementById("itemUnit");
    const name = document.getElementById("itemName");
    const price = document.getElementById("itemPrice");
    const vat = document.getElementById("itemVat");
    const item = index$2.Item.fromVatInclusivePrice(hasNumberValue(price) ? price.value : 0, hasNumberValue(vat) ? vat.value : undefined, undefined, hasStringValue(name) ? name.value : undefined, hasStringValue(quantity) && Number(quantity.value) > 0 ? Number(quantity.value) : undefined, hasStringValue(unit) ? unit.value : undefined, undefined);
    this.itemChanged.emit(item);
  }
  render() {
    const t = this.t;
    return [
      index$1.h("form", { name: "item" }, index$1.h("smoothly-input", { class: "left small", onKeyDown: this.updateItem.bind(this), id: "itemQuantity", value: this.item.quantity, type: "text", name: "quantity" }, t("Qty")), index$1.h("smoothly-input", { class: "small", onKeyDown: this.updateItem.bind(this), id: "itemUnit", value: this.item.unit, type: "text", name: "unit" }, t("Unit")), index$1.h("smoothly-input", { class: "big", onKeyDown: this.updateItem.bind(this), id: "itemName", value: this.item.name, type: "text", name: "name" }, t("Name")), index$1.h("smoothly-input", { class: "medium", onKeyDown: this.updateItem.bind(this), id: "itemPrice", value: this.inclusivePrice, type: "price", name: "price" }, t("Price")), index$1.h("smoothly-input", { class: "medium", onKeyDown: this.updateItem.bind(this), id: "itemVat", value: this.vatPercentage, type: "percent", name: "vat" }, t("VAT")), index$1.h("smoothly-trigger", { fill: "clear", name: "clear" }, index$1.h("smoothly-icon", { toolTip: t("Clear/remove item"), size: "small", name: "trash" }))),
    ];
  }
  get element() { return index$1.getElement(this); }
};
function hasStringValue(element) {
  return typeof element.value === "string";
}
function hasNumberValue(element) {
  return typeof element.value === "number";
}
IntergiroItemInput.style = styleCss;

exports.ig_item_input = IntergiroItemInput;
