/*! Select 5.0.0 for DataTables
 * Copyright (c) SpryMedia Ltd - datatables.net/license
 */
import DataTable,{Dom,util}from"datatables.net";var _instCounter=0;class FixedHeader{destroy(){this.s.dt.off(".dtfc"),Dom.s("body").off(".dtfc"),Dom.w.off(this.s.namespace),this.dom.header.rightBlocker&&this.dom.header.rightBlocker.remove(),this.dom.header.leftBlocker&&this.dom.header.leftBlocker.remove(),this.dom.footer.rightBlocker&&this.dom.footer.rightBlocker.remove(),this.dom.footer.leftBlocker&&this.dom.footer.leftBlocker.remove(),this.c.header&&this._modeChange("in-place","header",!0),this.c.footer&&this.dom.tfoot.count()&&this._modeChange("in-place","footer",!0)}enable(t,e){this.s.enable=t,!e&&void 0!==e||(this._positions(),this._scroll(!0))}enabled(){return this.s.enable}headerOffset(t){return void 0!==t&&(this.c.headerOffset=t,this.s.headerOffset=t,this.update()),this.s.headerOffset}footerOffset(t){return void 0!==t&&(this.c.footerOffset=t,this.s.footerOffset=t,this.update()),this.s.footerOffset}update(t=!0){var e=this.s.dt.table().node();(this.s.enable||this.s.autoDisable)&&(Dom.s(e).isVisible()?(this.s.autoDisable=!1,this.enable(!0,!1)):(this.s.autoDisable=!0,this.enable(!1,!1)),0!==Dom.s(e).children("thead").count())&&(this._positions(),this._scroll(t),this._widths(this.dom.header),this._widths(this.dom.footer))}constructor(t,e){t=new DataTable.Api(t),this.c=util.object.assign({},FixedHeader.defaults,e),this.s={dt:t,position:{theadBottom:0,theadTop:0,tbodyTop:0,tbodyHeight:0,tbodyWidth:0,tfootTop:0,tfootBottom:0,width:0,left:0,tfootHeight:0,theadHeight:0,windowHeight:document.querySelector("html").clientHeight,visible:!0},headerMode:null,headerOffset:0,footerMode:null,footerOffset:0,autoWidth:t.settings()[0].features.autoWidth,namespace:".dtfc"+_instCounter++,scrollLeft:{header:-1,footer:-1},enable:!0,autoDisable:!1},this.dom={floatingHeader:null,thead:Dom.s(t.table().header()),tbody:Dom.s(t.table().body()),tfoot:Dom.s(t.table().footer()),header:{host:null,scrollAdjust:null,floating:null,floatingParent:Dom.c("div").classAdd("dtfh-floatingparent").append(Dom.c("div").classAdd("dtfh-floating-limiter").append(Dom.c("div"))),limiter:null,placeholder:null,rightBlocker:null,leftBlocker:null},footer:{host:null,scrollAdjust:null,floating:null,floatingParent:Dom.c("div").classAdd("dtfh-floatingparent").append(Dom.c("div").classAdd("dtfh-floating-limiter").append(Dom.c("div"))),limiter:null,placeholder:null,rightBlocker:null,leftBlocker:null}},this.dom.header.host=this.dom.thead.parent(),this.dom.header.limiter=this.dom.header.floatingParent.children(),this.dom.header.scrollAdjust=this.dom.header.limiter.children(),this.dom.footer.host=this.dom.tfoot.parent(),this.dom.footer.limiter=this.dom.footer.floatingParent.children(),this.dom.footer.scrollAdjust=this.dom.footer.limiter.children(),e=t.settings()[0];if(e._fixedHeader)throw"FixedHeader already initialised on table "+e.table.id;(e._fixedHeader=this)._init()}_init(){var o=this,i=this.s.dt;Dom.w.on("scroll"+this.s.namespace,function(){o._scroll()}),Dom.w.on("resize"+this.s.namespace,DataTable.util.throttle(function(){o.s.position.windowHeight=Dom.w.height(),o.update()},50)),i.on("column-reorder.dt.dtfc column-visibility.dt.dtfc column-sizing.dt.dtfc responsive-display.dt.dtfc",function(t,e){o.update()}),Dom.s("body").on("draw.dt.dtfc",function(t,e){o.update(e!==i.settings()[0])}),i.on("destroy.dtfc",function(){o.destroy()}),this._positions(),this._scroll()}_clone(t,e){var o,i,s=this,d=this.s.dt,a=this.dom[t],r="header"===t?this.dom.thead:this.dom.tfoot;if("footer"!==t||!this._scrollEnabled())return e||!a.floating?(a.floating&&(null!==a.placeholder&&a.placeholder.detach(),a.floating.detach()),e=Dom.s(d.table().node()),o=e.parent(),i=this._scrollEnabled(),a.floating=Dom.s(d.table().node().cloneNode(!1)).attr("aria-hidden","true").css({top:"0px",left:"0px"}).attrRemove("id"),a.floatingParent.css({width:o.get(0).offsetWidth+"px",position:"fixed",left:i?e.offset().left+o.scrollLeft()+"px":"0px"}).css("header"===t?{top:this.s.headerOffset+"px",bottom:""}:{top:"",bottom:this.s.footerOffset+"px"}).classAdd("footer"===t?"dtfh-floatingparent-foot":"dtfh-floatingparent-head").appendTo("body").children().eq(0),a.limiter.css({width:"100%",overflow:"hidden",height:"fit-content"}),a.scrollAdjust.append(a.floating),this._stickyPosition(a.floating,"-"),(i=function(){var t=o.scrollLeft();s.s.scrollLeft={footer:t,header:t},a.limiter.scrollLeft(s.s.scrollLeft.header)})(),o.off("scroll.dtfh").on("scroll.dtfh",i),a.scrollAdjust.css({width:"fit-content",paddingRight:s.s.dt.settings()[0].browser.barWidth+"px"}),(e=Dom.s(d.table().container()).find("footer"===t?"div.dtfc-bottom-blocker":"div.dtfc-top-blocker")).count()&&e.clone().appendTo(a.floatingParent).css({position:"fixed",right:e.width()+"px"}),a.placeholder=r.clone(!0),a.placeholder.find("*[id]").attrRemove("id"),a.host.prepend(a.placeholder),a.floating.append(r),a.placeholder.insertAfter(a.host.find("header"===t?"colgroup":"tbody")),a.floating.append(r),this._widths(a),i):void a.floating.classRemove("fixedHeader-floating fixedHeader-locked")}_stickyPosition(t,e){var s;this._scrollEnabled()&&(s="rtl"===Dom.s(this.s.dt.table().node()).css("direction"),t.find("th").each(function(t){var e,o,i,t=Dom.s(t);"sticky"===t.css("position")&&(e=t.css("right"),o=t.css("left"),"auto"===e||s?"auto"!==o&&s&&(i=+o.replace(/px/g,""),t.css("left",(0<i?i:0)+"px")):(i=+e.replace(/px/g,""),t.css("right",(0<i?i:0)+"px")))}))}_horizontal(t,e){var o,i=this.dom[t],s=this.s.scrollLeft;i.floating&&s[t]!==e&&(this._scrollEnabled()&&(o=Dom.s(this.s.dt.table().node().parentNode).scrollLeft(),i.floating.scrollLeft(o),i.floatingParent.scrollLeft(o)),s[t]=e)}_modeChange(t,e,o){var i,s,d,a,r,l,h,f,n=this.s.dt,c=this.dom[e],p=this.s.position,g=this._scrollEnabled();"footer"===e&&g||(i=function(t){var e;null!=(e=c.floating)&&e.get(0).style.setProperty("width",t+"px","important"),g||c.floatingParent.get(0).style.setProperty("width",t+"px","important")},d=this.dom["footer"===e?"tfoot":"thead"],s=d.find(document.activeElement).count()?document.activeElement:null,l=Dom.s(this.s.dt.table().node()).parent(),"in-place"===t?(c.placeholder&&(c.placeholder.remove(),c.placeholder=null),c.host&&(c.host.contains(d)||("header"===e?d.insertAfter(c.host.find("colgroup")):c.host.append(d)),c.floating&&(c.floating.remove(),c.floating=null,this._stickyPosition(c.host,"+")),c.floatingParent&&(c.floatingParent.find("div.dtfc-top-blocker").remove(),c.floatingParent.remove()),c.host.parent().parent().scrollLeft(l.scrollLeft()))):"in"===t?(d=this._clone(e,o),r=l.offset(),f=(a=Dom.w.scrollTop())+Dom.w.height(),h=g?r.top:p.tbodyTop,r=g?r.top+l.height("outer"):p.tfootTop,l="footer"===e?f<h?p.tfootHeight:h+p.tfootHeight-f:a+this.s.headerOffset+p.theadHeight-r,h="header"===e?"top":"bottom",f=this.s[e+"Offset"]-(0<l?l:0),null!=(a=c.floating)&&a.classAdd("fixedHeader-floating"),c.floatingParent.css({[h]:f+"px",left:p.left+"px","z-index":"3"}),i(p.width),d&&d(),"footer"===e&&c.floating&&c.floating.css("top","")):"below"===t?(this._clone(e,o),null!=(r=c.floating)&&r.classAdd("fixedHeader-locked"),c.floatingParent.css({position:"absolute",top:p.tfootTop-p.theadHeight+"px",left:p.left+"px"}),i(p.width)):"above"===t&&(this._clone(e,o),null!=(l=c.floating)&&l.classAdd("fixedHeader-locked"),c.floatingParent.css({position:"absolute",top:p.tbodyTop+"px",left:p.left+"px"}),i(p.width)),s&&s!==document.activeElement&&setTimeout(function(){s&&s.focus()},10),this.s.scrollLeft.header=-1,this.s.scrollLeft.footer=-1,this.s["header"===e?"headerMode":"footerMode"]=t,n.trigger("fixedheader-mode",[t,e]))}_positions(){var t=this.s.dt,e=t.table(),o=this.s.position,e=Dom.s(e.node()),i=this._scrollEnabled(),s=Dom.s(".fh-fixedHeader"),s=(!this.c.headerOffset&&s.count()?this.s.headerOffset=s.height("outer"):this.s.headerOffset=this.c.headerOffset,Dom.s(".fh-fixedFooter")),s=(!this.c.footerOffset&&s.count()?this.s.footerOffset=s.height("outer"):this.s.footerOffset=this.c.footerOffset,Dom.s(t.table().header())),t=Dom.s(t.table().footer()),d=this.dom.tbody,a=e.parent();o.visible=e.isVisible(),o.width=e.width("outer"),o.left=e.offset().left,o.theadTop=s.offset().top,o.tbodyTop=(i?a:d).offset().top,o.tbodyHeight=(i?a:d).height("outer"),o.theadHeight=s.height("outer"),o.theadBottom=o.theadTop+o.theadHeight,o.tfootTop=o.tbodyTop+o.tbodyHeight,t.count()?(o.tfootBottom=o.tfootTop+t.height("outer"),o.tfootHeight=t.height("outer")):(o.tfootBottom=o.tfootTop,o.tfootHeight=0)}_scroll(t=!1){var e,o,i,s,d,a,r,l,h,f,n,c,p,g,m,u;this.s.dt.settings()[0].destroying||(e=this._scrollEnabled(),i=(o=Dom.s(this.s.dt.table().node()).parent()).offset(),c=o.height("outer"),s=Dom.w.scrollLeft(),d=Dom.w.scrollTop(),a=Dom.w.height()+d,p=this.s.position,u=e?i.top:p.tbodyTop,l=(e?i:p).left,c=e?i.top+c:p.tfootTop,h=e?o.width("outer"):p.tbodyWidth,this.c.header&&(!this.s.enable||!p.visible||d+this.s.headerOffset+p.theadHeight<=u?f="in-place":d+this.s.headerOffset+p.theadHeight>u&&d+this.s.headerOffset+p.theadHeight<c?(f="in",d+this.s.headerOffset+p.theadHeight>c||void 0===this.dom.header.floatingParent?t=!0:0===(n=this.dom.header.floatingParent.css({top:this.s.headerOffset+"px",position:"fixed"}).children().eq(0)).find(this.dom.header.floating).count()&&n.append(this.dom.header.floating)):f="below",!t&&f===this.s.headerMode||this._modeChange(f,"header",t),this._horizontal("header",s)),g={offset:{top:0},height:0},m={offset:{top:0},height:0},this.c.footer&&this.dom.tfoot.count()&&this.dom.tfoot.find("th, td").count()&&(!this.s.enable||!p.visible||p.tfootBottom+this.s.footerOffset<=a?r="in-place":c+p.tfootHeight+this.s.footerOffset>a&&u+this.s.footerOffset<a?(r="in",t=!0):r="above",!t&&r===this.s.footerMode||this._modeChange(r,"footer",t),this._horizontal("footer",s),n=function(t){return{offset:t.offset(),height:t.height("outer")}},g=this.dom.header.floating?n(this.dom.header.floating):n(this.dom.thead),m=this.dom.footer.floating?n(this.dom.footer.floating):n(this.dom.tfoot),e)&&m.offset.top>d&&(p=a+((c=d-i.top)>-g.height?c:0)-(g.offset.top+(c<-g.height?g.height:0)+m.height),o.height(p=p<0?0:p),Math.round(o.height("outer"))>=Math.round(p)?this.dom.tfoot.parent().classAdd("fixedHeader-floating"):this.dom.tfoot.parent().classRemove("fixedHeader-floating")),this.dom.header.floating&&this.dom.header.floatingParent.css("left",l-s+"px"),this.dom.footer.floating&&this.dom.footer.floatingParent.css("left",l-s+"px"),void 0!==this.s.dt.settings()[0]._fixedColumns&&(this.dom.header.rightBlocker=(u=function(t,e,o){var i;return null!==(o=void 0===o?0===(i=Dom.s("div.dtfc-"+t+"-"+e+"-blocker")).count()?null:i.clone().css("z-index","1"):o)&&("in"===f||"below"===f?o.appendTo("body").css({top:("top"===e?g:m).offset.top+"px",left:("right"===t?l+h-o.width():l)+"px"}):o.detach()),o})("right","top",this.dom.header.rightBlocker),this.dom.header.leftBlocker=u("left","top",this.dom.header.leftBlocker),this.dom.footer.rightBlocker=u("right","bottom",this.dom.footer.rightBlocker),this.dom.footer.leftBlocker=u("left","bottom",this.dom.footer.leftBlocker)))}_scrollEnabled(){var t=this.s.dt.settings()[0].scroll;return""!==t.y||""!==t.x}_widths(t){if(t&&t.placeholder)for(var e=Dom.s(this.s.dt.table().node()),o=e.parent(),i=(t.floatingParent.css("width",o.get(0).offsetWidth+"px"),t.floating.css("width",e.get(0).offsetWidth+"px"),t.floating.find("colgroup").remove(),t.placeholder.parent().find("colgroup").clone(!0).appendTo(t.floating).find("col")),s=this.s.dt.columns(":visible").widths(),d=0;d<s.length;d++)i.eq(d).css("width",s[d]+"px")}}if(FixedHeader.defaults={header:!0,footer:!1,headerOffset:0,footerOffset:0},FixedHeader.version="5.0.0",!DataTable||!DataTable.versionCheck("3"))throw"Warning: FixedHeader requires DataTables 3 or newer";DataTable.FixedHeader=FixedHeader,Dom.s(document).on("init.dt.dtfh",function(t,e){var o,i;"dt"===t.namespace&&(t=e.init.fixedHeader,o=DataTable.defaults.fixedHeader,t||o)&&!e._fixedHeader&&(i={},util.is.plainObject(o)&&util.object.assign(i,o),util.is.plainObject(t)&&util.object.assign(i,t),!1!==t)&&new FixedHeader(e,i)}),DataTable.Api.register("fixedHeader()",function(){}),DataTable.Api.register("fixedHeader.adjust()",function(){return this.iterator("table",function(t){t=t._fixedHeader;t&&t.update()})}),DataTable.Api.register("fixedHeader.enable()",function(e){return this.iterator("table",function(t){t=t._fixedHeader;e=void 0===e||e,t&&e!==t.enabled()&&t.enable(e)})}),DataTable.Api.register("fixedHeader.enabled()",function(){if(this.context.length){var t=this.context[0]._fixedHeader;if(t)return t.enabled()}return!1}),DataTable.Api.register("fixedHeader.disable()",function(){return this.iterator("table",function(t){t=t._fixedHeader;t&&t.enabled()&&t.enable(!1)})}),["header","footer"].forEach(function(o){DataTable.Api.register("fixedHeader."+o+"Offset()",function(e){var t=this.context;return void 0===e?t.length&&t[0]._fixedHeader?t[0]._fixedHeader[o+"Offset"]():void 0:this.iterator("table",function(t){t=t._fixedHeader;t&&t[o+"Offset"](e)})})});export default DataTable;