import{r as registerInstance}from"./index-3ded372f.js";import{a as api}from"./api-0c31171f.js";import{s as serializeForm}from"./serializeForm-a39bb4a7.js";import{w as waitForHydrated}from"./waitForHydrated-24c52eea.js";import"./_commonjsHelpers-5e4b1d1a.js";var QuoteStatusTypes;(function(t){t["APPROVAL"]="approval";t["PENDING"]="pending";t["REJECTED"]="rejected";t["COMPLETED"]="completed"})(QuoteStatusTypes||(QuoteStatusTypes={}));function resolveStatusColor(t){switch(t){case QuoteStatusTypes.REJECTED:return"red";case QuoteStatusTypes.PENDING:return"dark-blue";case QuoteStatusTypes.COMPLETED:return"green";default:return"dark-blue"}}var getStatusText=function(t){var e=t.type,r=t.text;var o=resolveStatusColor(e);return''+r+""};var row=function(t){var e=t.orderNumber,r=t.status,o=t.createdAt,i=t.positions,n=t.orderTotal,s=t.machine,l=t.detailLink,a=t.downloadLink;var u=getStatusText(r);if(a){return"\n
\n "+e+" | \n "+u+" | \n "+o+" | \n "+i+" | \n "+n+" | \n "+s+' | \n \n \n \n | \n
\n '}return"\n \n "+e+" | \n "+u+" | \n "+o+" | \n "+i+" | \n "+n+" | \n "+s+' | \n \n \n | \n
\n '};var 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}';var DataControllerShopItemQuote=function(){function t(t){registerInstance(this,t);this.url="";this.filterSelector="";this.dateFormSelector="";this.sortFormSelector="";this.tableSelector="";this.uxTabSelector="";this.filteredNumberSelector="";this.scrollSensorSelector="";this.totalNumberPrefix="";this.filter=null;this.filterForm=null;this.dateForm=null;this.sortForm=null;this.table=null;this.tableBody=null;this.filteredNumberElements=null;this.uxTabElement=null;this.nextPage="";this.scrollSensor=null}t.prototype.componentDidLoad=function(){this.setDateForm();this.setSortForm();this.setFilter();this.setTable();this.setScrollSensor();this.setUxTabElement();this.setFilteredNumberElements();this.requestData(this.url)};t.prototype.setDateForm=function(){var t=this;if(this.dateFormSelector==="")return;this.dateForm=document.querySelector(this.dateFormSelector);if(this.dateForm===null)return;this.dateForm.addEventListener("submit",(function(e){e.preventDefault();t.requestData(t.url);t.syncSortStateToTable()}));this.dateForm.addEventListener("change",(function(){t.requestData(t.url);t.syncSortStateToTable()}))};t.prototype.setFilter=function(){var t=this;if(this.filterSelector==="")return;this.filter=document.querySelector(this.filterSelector);waitForHydrated(this.filter,(function(){return t.setFilterForm()}));this.filter.addEventListener("uxFilterChange",(function(){return t.requestData(t.url)}))};t.prototype.setSortForm=function(){if(this.sortFormSelector==="")return;this.sortForm=document.querySelector(this.sortFormSelector);if(this.sortForm===null)return;this.sortForm.addEventListener("submit",preventDefaultEvent)};t.prototype.setUxTabElement=function(){if(this.uxTabSelector==="")return;this.uxTabElement=document.querySelector(this.uxTabSelector)};t.prototype.setFilteredNumberElements=function(){if(this.filteredNumberSelector==="")return;this.filteredNumberElements=document.querySelectorAll(this.filteredNumberSelector)};t.prototype.setFilterForm=function(){this.filterForm=this.filter.querySelector("form");if(this.filterForm===null)return;this.filterForm.addEventListener("submit",preventDefaultEvent)};t.prototype.syncSortStateToTable=function(){if(this.table===null||this.sortForm===null)return;var t=this.sortForm.querySelector("input").value;var e=this.table.querySelector('ux-table-sort[sorted-direction="desc"], ux-table-sort[sorted-direction="asc"]');if(e!==null){e.sortedDirection=""}var r=this.table.querySelector('ux-table-sort[asc-name="'+t+'"]');var o=this.table.querySelector('ux-table-sort[desc-name="'+t+'"]');if(r!==null){r.sortedDirection="asc"}if(o!==null){o.sortedDirection="desc"}};t.prototype.updateNumbers=function(t,e){writeToElements(this.filteredNumberElements,t.toString());this.updateTabNumber(e)};t.prototype.updateTabNumber=function(t){if(this.uxTabElement==null)return;var e="("+t.toString()+")";if(this.totalNumberPrefix!==""){e=this.totalNumberPrefix+" ("+t.toString()+")"}this.uxTabElement.name=e};t.prototype.setTable=function(){var t=this;var e;if(this.tableSelector==="")return;this.table=document.querySelector(this.tableSelector);this.tableBody=(e=this.table)===null||e===void 0?void 0:e.querySelector("tbody");if(this.table!==null&&this.sortForm!==null){this.table.addEventListener("uxTableSort",(function(e){var r=e.detail;if(r==="")return;t.sortForm.querySelector("input").value=r;t.requestData(t.url)}));this.syncSortStateToTable()}};t.prototype.setScrollSensor=function(){var t=this;if(this.scrollSensorSelector==="")return;this.scrollSensor=document.querySelector(this.scrollSensorSelector);if(this.scrollSensor!==null){this.scrollSensor.addEventListener("uxInfiniteScrollSensorScrolledIntoView",(function(){t.requestData(t.nextPage)}))}};t.prototype.initialRequest=function(){this.requestData(this.url)};t.prototype.getSerializedFormData=function(){return[serializeForm(this.dateForm),serializeForm(this.filterForm),serializeForm(this.sortForm)].filter((function(t){return t!==""})).join("&")};t.prototype.requestData=function(t){var e=this;if(t==="")return;var r=isMockUrl(t)?{}:{method:"POST",body:this.getSerializedFormData(),headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"}};api(t,r).then((function(r){if(e.url===t){e.clearExistingData()}e.appendItemsToTable(r.items);e.updateNumbers(r.filteredCount,r.totalCount);e.nextPage=r.nextPage||"";if(e.nextPage!==""&&e.scrollSensor!==null){e.scrollSensor.hasFired=false}}))};t.prototype.clearExistingData=function(){if(this.tableBody!==null)this.tableBody.textContent=""};t.prototype.appendItemsToTable=function(t){if(this.tableBody===null)return;this.tableBody.insertAdjacentHTML("beforeend",t.map(row).join(""))};t.prototype.render=function(){return null};Object.defineProperty(t,"watchers",{get:function(){return{dateFormSelector:["setDateForm"],filterSelector:["setFilter"],sortFormSelector:["setSortForm"],uxTabSelector:["setUxTabElement"],filteredNumberSelector:["setFilteredNumberElements"],tableSelector:["setTable"],scrollSensorSelector:["setScrollSensor"],url:["initialRequest"]}},enumerable:false,configurable:true});return t}();function isMockUrl(t){return t.indexOf("mock-data/")>-1}function preventDefaultEvent(t){t.preventDefault()}function writeToElements(t,e){if(t===null)return;[].forEach.call(t,(function(t){return t.textContent=e}))}DataControllerShopItemQuote.style=dataControllerShopItemCss;export{DataControllerShopItemQuote as ux_iws_data_controller_shop_item_quote};