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 OrderReturnStatusTypes;(function(e){e["OPEN"]="open";e["CANCELED"]="canceled";e["IN_PROCESS"]="in_process";e["PARTIALLY_COMPLETED"]="partially_completed";e["COMPLETED"]="completed"})(OrderReturnStatusTypes||(OrderReturnStatusTypes={}));function resolveStatusColor(e){switch(e){case OrderReturnStatusTypes.OPEN:return"grey";case OrderReturnStatusTypes.CANCELED:return"red";case OrderReturnStatusTypes.IN_PROCESS:return"dark-blue";case OrderReturnStatusTypes.PARTIALLY_COMPLETED:return"orange";case OrderReturnStatusTypes.COMPLETED:return"green";default:return"grey"}}var getStatusText=function(e){var t=e.type,r=e.text;var o=resolveStatusColor(t);return''+r+""};var row=function(e){var t=e.returnNumber,r=e.status,o=e.createdAt,n=e.createdBy,i=e.positions,l=e.detailLink;var s=getStatusText(r);return"\n
\n "+t+" | \n "+s+" | \n "+o+" | \n "+n+" | \n "+i+' | \n | \n
\n '};var dataControllerOrderReturnCss='.order-return-overview__filter-container::before,.order-return-overview__filter-container::after{content:" ";display:table}.order-return-overview__filter-container::after{clear:both}.order-return-overview__filter-container .ux-tag{background-color:#285172}.order-return-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}.order-return-overview__filter-container .datepicker-range__divider{-ms-flex:0 0 20px;flex:0 0 20px}.order-return-overview__filter-container .datepicker{-ms-flex:1 1 auto;flex:1 1 auto}.order-return-overview__filter-dropdown{min-width:250px;max-width:300px;position:relative;display:inline-block;margin-right:18px;margin-bottom:20px}.order-return-overview__result-set.result-set{margin-top:0;position:relative;text-align:center}.order-return-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}.order-return-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}.order-return-overview .ux-collapsible-button__container{padding:15px;text-align:center}';var DataControllerOrderReturn=function(){function e(e){registerInstance(this,e);this.url="";this.filterSelector="";this.dateFormSelector="";this.sortFormSelector="";this.tableSelector="";this.totalNumberSelector="";this.filteredNumberSelector="";this.scrollSensorSelector="";this.filter=null;this.filterForm=null;this.dateForm=null;this.sortForm=null;this.table=null;this.tableBody=null;this.filteredNumberElements=null;this.totalNumberElements=null;this.nextPage="";this.scrollSensor=null}e.prototype.componentDidLoad=function(){this.setDateForm();this.setSortForm();this.setFilter();this.setTable();this.setScrollSensor();this.setTotalNumberElements();this.setFilteredNumberElements();this.requestData(this.url)};e.prototype.setDateForm=function(){if(this.dateFormSelector==="")return;this.dateForm=document.querySelector(this.dateFormSelector);if(this.dateForm===null)return;this.dateForm.addEventListener("submit",(function(e){return e.preventDefault()}))};e.prototype.setFilter=function(){var e=this;if(this.filterSelector==="")return;this.filter=document.querySelector(this.filterSelector);waitForHydrated(this.filter,(function(){return e.setFilterForm()}));this.filter.addEventListener("uxFilterChange",(function(){return e.requestData(e.url)}))};e.prototype.setSortForm=function(){if(this.sortFormSelector==="")return;this.sortForm=document.querySelector(this.sortFormSelector);if(this.sortForm===null)return;this.sortForm.addEventListener("submit",preventDefaultEvent)};e.prototype.setTotalNumberElements=function(){if(this.totalNumberSelector==="")return;this.totalNumberElements=document.querySelectorAll(this.totalNumberSelector)};e.prototype.setFilteredNumberElements=function(){if(this.filteredNumberSelector==="")return;this.filteredNumberElements=document.querySelectorAll(this.filteredNumberSelector)};e.prototype.setFilterForm=function(){this.filterForm=this.filter.querySelector("form");if(this.filterForm===null)return;this.filterForm.addEventListener("submit",preventDefaultEvent)};e.prototype.syncSortStateToTable=function(){if(this.table===null||this.sortForm===null)return;var e=this.sortForm.querySelector("input").value;var t=this.table.querySelector('ux-table-sort[sorted-direction="desc"], ux-table-sort[sorted-direction="asc"]');if(t!==null){t.sortedDirection=""}var r=this.table.querySelector('ux-table-sort[asc-name="'+e+'"]');var o=this.table.querySelector('ux-table-sort[desc-name="'+e+'"]');if(r!==null){r.sortedDirection="asc"}if(o!==null){o.sortedDirection="desc"}};e.prototype.updateNumbers=function(e,t){writeToElements(this.filteredNumberElements,e.toString());writeToElements(this.totalNumberElements,t.toString())};e.prototype.setTable=function(){var e=this;var t;if(this.tableSelector==="")return;this.table=document.querySelector(this.tableSelector);this.tableBody=(t=this.table)===null||t===void 0?void 0:t.querySelector("tbody");if(this.table!==null&&this.sortForm!==null){this.table.addEventListener("uxTableSort",(function(t){var r=t.detail;if(r==="")return;e.sortForm.querySelector("input").value=r;e.requestData(e.url)}));this.syncSortStateToTable()}};e.prototype.setScrollSensor=function(){var e=this;if(this.scrollSensorSelector==="")return;this.scrollSensor=document.querySelector(this.scrollSensorSelector);if(this.scrollSensor!==null){this.scrollSensor.addEventListener("uxInfiniteScrollSensorScrolledIntoView",(function(){e.requestData(e.nextPage)}))}};e.prototype.initialRequest=function(){this.requestData(this.url)};e.prototype.getSerializedFormData=function(){return[serializeForm(this.dateForm),serializeForm(this.filterForm),serializeForm(this.sortForm)].filter((function(e){return e!==""})).join("&")};e.prototype.requestData=function(e){var t=this;if(e==="")return;var r=isMockUrl(e)?{}:{method:"POST",body:this.getSerializedFormData(),headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"}};api(e,r).then((function(r){if(t.url===e){t.clearExistingData();t.replaceFilter(r.filterHTML)}t.appendItemsToTable(r.items);t.updateNumbers(r.filteredCount,r.totalCount);t.nextPage=r.nextPage||"";if(t.nextPage!==""&&t.scrollSensor!==null){t.scrollSensor.hasFired=false}}))};e.prototype.replaceFilter=function(e){if(typeof e==="string"&&e.length>0&&this.filter!==null){var t=this.filter.parentElement;if(t!==null){t.style.height=t.offsetHeight+"px"}this.filter.outerHTML=e;this.setFilter();setTimeout((function(){t.style.height="auto"}),200)}};e.prototype.clearExistingData=function(){if(this.tableBody!==null)this.tableBody.textContent=""};e.prototype.appendItemsToTable=function(e){if(this.tableBody===null)return;this.tableBody.insertAdjacentHTML("beforeend",e.map(row).join(""))};e.prototype.render=function(){return null};Object.defineProperty(e,"watchers",{get:function(){return{dateFormSelector:["setDateForm"],filterSelector:["setFilter"],sortFormSelector:["setSortForm"],totalNumberSelector:["setTotalNumberElements"],filteredNumberSelector:["setFilteredNumberElements"],tableSelector:["setTable"],scrollSensorSelector:["setScrollSensor"],url:["initialRequest"]}},enumerable:false,configurable:true});return e}();function isMockUrl(e){return e.indexOf("mock-data/")>-1}function preventDefaultEvent(e){e.preventDefault()}function writeToElements(e,t){if(e===null)return;[].forEach.call(e,(function(e){return e.textContent=t}))}DataControllerOrderReturn.style=dataControllerOrderReturnCss;export{DataControllerOrderReturn as ux_iws_data_controller_order_return};