<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">'use strict';

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

const index = require('./index-ceb0d0a9.js');
const api = require('./api-54551431.js');
const serializeForm = require('./serializeForm-71d4d470.js');
const waitForHydrated = require('./waitForHydrated-11e4f06c.js');
require('./_commonjsHelpers-bcc1208a.js');

var QuoteStatusTypes;
(function (QuoteStatusTypes) {
  QuoteStatusTypes["APPROVAL"] = "approval";
  QuoteStatusTypes["PENDING"] = "pending";
  QuoteStatusTypes["REJECTED"] = "rejected";
  QuoteStatusTypes["COMPLETED"] = "completed";
})(QuoteStatusTypes || (QuoteStatusTypes = {}));

function resolveStatusColor(type) {
  switch (type) {
    case QuoteStatusTypes.REJECTED:
      return "red";
    case QuoteStatusTypes.PENDING:
      return "dark-blue";
    case QuoteStatusTypes.COMPLETED:
      return "green";
    default:
      return "dark-blue";
  }
}
const getStatusText = ({ type, text }) =&gt; {
  const statusColor = resolveStatusColor(type);
  return `&lt;span class="ux-text-status ux-text-status--${statusColor}"&gt;${text}&lt;/span&gt;`;
};

const row = ({ orderNumber, status, createdAt, positions, orderTotal, machine, detailLink, downloadLink, }) =&gt; {
  const statusText = getStatusText(status);
  if (downloadLink) {
    return `
            &lt;tr&gt;
                &lt;td&gt;${orderNumber}&lt;/td&gt;
                &lt;td&gt;${statusText}&lt;/td&gt;
                &lt;td&gt;${createdAt}&lt;/td&gt;
                &lt;td&gt;${positions}&lt;/td&gt;
                &lt;td&gt;${orderTotal}&lt;/td&gt;
                &lt;td&gt;${machine}&lt;/td&gt;
                &lt;td class="ux-iws-quote-table-links"&gt;
                    &lt;a class="ux-button ux-button--icon-only" href="${downloadLink}"&gt;&lt;ux-icon name="download"&gt;&lt;/ux-icon&gt;&lt;/a&gt;
                    &lt;a class="ux-button ux-button--icon-only" href="${detailLink}"&gt;&lt;ux-icon name="arrow-right"&gt;&lt;/ux-icon&gt;&lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
        `;
  }
  return `
        &lt;tr&gt;
            &lt;td&gt;${orderNumber}&lt;/td&gt;
            &lt;td&gt;${statusText}&lt;/td&gt;
            &lt;td&gt;${createdAt}&lt;/td&gt;
            &lt;td&gt;${positions}&lt;/td&gt;
            &lt;td&gt;${orderTotal}&lt;/td&gt;
            &lt;td&gt;${machine}&lt;/td&gt;
            &lt;td class="ux-iws-quote-table-links"&gt;
                &lt;a class="ux-button ux-button--icon-only" href="${detailLink}"&gt;&lt;ux-icon name="arrow-right"&gt;&lt;/ux-icon&gt;&lt;/a&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
    `;
};

const dataControllerShopItemCss = ".ux-iws-shop-item-overview__filter-container::before,.ux-iws-shop-item-overview__filter-container::after{content:\" \";display:table}.ux-iws-shop-item-overview__filter-container::after{clear:both}.ux-iws-shop-item-overview__filter-container .ux-tag{background-color:#285172}.ux-iws-shop-item-overview__filter-container .datepicker-range{display:-ms-flexbox;display:flex;-ms-flex-direction:row;flex-direction:row;-ms-flex-wrap:nowrap;flex-wrap:nowrap;-ms-flex-align:center;align-items:center;-ms-flex-pack:start;justify-content:flex-start}.ux-iws-shop-item-overview__filter-container .datepicker-range__divider{-ms-flex:0 0 20px;flex:0 0 20px}.ux-iws-shop-item-overview__filter-container .datepicker{-ms-flex:1 1 auto;flex:1 1 auto}.ux-iws-shop-item-overview__filter-dropdown{min-width:250px;max-width:300px;position:relative;display:inline-block;margin-right:18px;margin-bottom:20px}.ux-iws-shop-item-overview__result-set.result-set{margin-top:0;position:relative;text-align:center}.ux-iws-shop-item-overview__table-container .ux-text-status{display:-ms-flexbox;display:flex;-ms-flex-flow:row nowrap;flex-flow:row nowrap;-ms-flex-align:center;align-items:center;-ms-flex-pack:start;justify-content:flex-start}.ux-iws-shop-item-overview__table-container .ux-text-status::before{content:\"\";display:inline-block;background-color:currentColor;width:0.8em;height:0.8em;border-radius:100%;margin-right:0.8em}.ux-iws-shop-item-overview .ux-collapsible-button__container{padding:15px;text-align:center}";

let DataControllerShopItemQuote = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    /** endpoint where data can be requested */
    this.url = "";
    /** CSS selector for the filter */
    this.filterSelector = "";
    /** CSS selector for the filter */
    this.dateFormSelector = "";
    /** CSS selector for the sort form */
    this.sortFormSelector = "";
    /** CSS selector for the table */
    this.tableSelector = "";
    /** CSS selector for the ux tab element where the total number found is added as suffix concatenated with the totalNumberPrefix */
    this.uxTabSelector = "";
    /** CSS selector for the element where the number of filtered order should be placed */
    this.filteredNumberSelector = "";
    /** CSS selector for the scroll-sensor */
    this.scrollSensorSelector = "";
    /** Prefix text value on updating uxTab Name */
    this.totalNumberPrefix = "";
    /** element that contains all filters */
    this.filter = null;
    /** form element for filter */
    this.filterForm = null;
    /** form element for date range */
    this.dateForm = null;
    /** form element for sorting */
    this.sortForm = null;
    /** table element */
    this.table = null;
    /** table body element where the data should be put */
    this.tableBody = null;
    /** NodeList of DOM elements where the number of filtered orders should be put */
    this.filteredNumberElements = null;
    /** UX-Tab as HTMLUxTabElement where the updated total number of orders should be put */
    this.uxTabElement = null;
    /** URL for getting the next page */
    this.nextPage = "";
    /** DOM element where all the table rows should be put */
    this.scrollSensor = null;
  }
  componentDidLoad() {
    this.setDateForm();
    this.setSortForm();
    this.setFilter();
    this.setTable();
    this.setScrollSensor();
    this.setUxTabElement();
    this.setFilteredNumberElements();
    this.requestData(this.url);
  }
  /** Connect date form */
  setDateForm() {
    if (this.dateFormSelector === "")
      return;
    this.dateForm = document.querySelector(this.dateFormSelector);
    if (this.dateForm === null)
      return;
    this.dateForm.addEventListener("submit", (e) =&gt; {
      e.preventDefault();
      this.requestData(this.url);
      this.syncSortStateToTable();
    });
    this.dateForm.addEventListener("change", () =&gt; {
      this.requestData(this.url);
      this.syncSortStateToTable();
    });
  }
  /** Connect filter */
  setFilter() {
    if (this.filterSelector === "")
      return;
    this.filter = document.querySelector(this.filterSelector);
    waitForHydrated.waitForHydrated(this.filter, () =&gt; this.setFilterForm());
    this.filter.addEventListener("uxFilterChange", () =&gt; this.requestData(this.url));
  }
  /** Connect sort form */
  setSortForm() {
    if (this.sortFormSelector === "")
      return;
    this.sortForm = document.querySelector(this.sortFormSelector);
    if (this.sortForm === null)
      return;
    this.sortForm.addEventListener("submit", preventDefaultEvent);
  }
  /** Connect total number */
  setUxTabElement() {
    if (this.uxTabSelector === "")
      return;
    this.uxTabElement = document.querySelector(this.uxTabSelector);
  }
  /** Connect filtered number */
  setFilteredNumberElements() {
    if (this.filteredNumberSelector === "")
      return;
    this.filteredNumberElements = document.querySelectorAll(this.filteredNumberSelector);
  }
  setFilterForm() {
    this.filterForm = this.filter.querySelector("form");
    if (this.filterForm === null)
      return;
    this.filterForm.addEventListener("submit", preventDefaultEvent);
  }
  syncSortStateToTable() {
    if (this.table === null || this.sortForm === null)
      return;
    const { value } = this.sortForm.querySelector("input");
    const prevSorted = this.table.querySelector(`ux-table-sort[sorted-direction="desc"], ux-table-sort[sorted-direction="asc"]`);
    if (prevSorted !== null) {
      prevSorted.sortedDirection = "";
    }
    const ascSort = this.table.querySelector(`ux-table-sort[asc-name="${value}"]`);
    const descSort = this.table.querySelector(`ux-table-sort[desc-name="${value}"]`);
    if (ascSort !== null) {
      ascSort.sortedDirection = "asc";
    }
    if (descSort !== null) {
      descSort.sortedDirection = "desc";
    }
  }
  updateNumbers(filtered, total) {
    writeToElements(this.filteredNumberElements, filtered.toString());
    this.updateTabNumber(total);
  }
  updateTabNumber(total) {
    if (this.uxTabElement == null)
      return;
    var totalNumberText = "(" + total.toString() + ")";
    if (this.totalNumberPrefix !== "") {
      totalNumberText =
        this.totalNumberPrefix + " (" + total.toString() + ")";
    }
    this.uxTabElement.name = totalNumberText;
  }
  /** connect table */
  setTable() {
    var _a;
    if (this.tableSelector === "")
      return;
    this.table = document.querySelector(this.tableSelector);
    this.tableBody = (_a = this.table) === null || _a === void 0 ? void 0 : _a.querySelector("tbody");
    if (this.table !== null &amp;&amp; this.sortForm !== null) {
      this.table.addEventListener("uxTableSort", (e) =&gt; {
        const value = e.detail;
        if (value === "")
          return;
        this.sortForm.querySelector("input").value = value;
        this.requestData(this.url);
      });
      this.syncSortStateToTable();
    }
  }
  /** connect scroll-sensor */
  setScrollSensor() {
    if (this.scrollSensorSelector === "")
      return;
    this.scrollSensor = document.querySelector(this.scrollSensorSelector);
    if (this.scrollSensor !== null) {
      this.scrollSensor.addEventListener("uxInfiniteScrollSensorScrolledIntoView", () =&gt; {
        this.requestData(this.nextPage);
      });
    }
  }
  /** post filter, date and sort settings to get data from the endpoint */
  initialRequest() {
    this.requestData(this.url);
  }
  getSerializedFormData() {
    return [
      serializeForm.serializeForm(this.dateForm),
      serializeForm.serializeForm(this.filterForm),
      serializeForm.serializeForm(this.sortForm),
    ]
      .filter((str) =&gt; str !== "")
      .join("&amp;");
  }
  /** Send the real request and handle response */
  requestData(url) {
    if (url === "")
      return;
    const options = isMockUrl(url)
      ? {}
      : {
        method: "POST",
        body: this.getSerializedFormData(),
        headers: {
          "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
        },
      };
    api.api(url, options).then((data) =&gt; {
      if (this.url === url) {
        this.clearExistingData();
      }
      this.appendItemsToTable(data.items);
      this.updateNumbers(data.filteredCount, data.totalCount);
      this.nextPage = data.nextPage || "";
      if (this.nextPage !== "" &amp;&amp; this.scrollSensor !== null) {
        this.scrollSensor.hasFired = false;
      }
    });
  }
  clearExistingData() {
    if (this.tableBody !== null)
      this.tableBody.textContent = "";
  }
  appendItemsToTable(items) {
    if (this.tableBody === null)
      return;
    this.tableBody.insertAdjacentHTML("beforeend", items.map(row).join(""));
  }
  render() {
    return null;
  }
  static get watchers() { return {
    "dateFormSelector": ["setDateForm"],
    "filterSelector": ["setFilter"],
    "sortFormSelector": ["setSortForm"],
    "uxTabSelector": ["setUxTabElement"],
    "filteredNumberSelector": ["setFilteredNumberElements"],
    "tableSelector": ["setTable"],
    "scrollSensorSelector": ["setScrollSensor"],
    "url": ["initialRequest"]
  }; }
};
function isMockUrl(url) {
  return url.indexOf("mock-data/") &gt; -1;
}
function preventDefaultEvent(e) {
  e.preventDefault();
}
function writeToElements(nodes, text) {
  if (nodes === null)
    return;
  [].forEach.call(nodes, (element) =&gt; (element.textContent = text));
}
DataControllerShopItemQuote.style = dataControllerShopItemCss;

exports.ux_iws_data_controller_shop_item_quote = DataControllerShopItemQuote;
</pre></body></html>