/*! FixedHeader 4.0.0
 * © SpryMedia Ltd - datatables.net/license
 */
import jQuery from"jquery";import DataTable from"datatables.net";let $=jQuery;var _instCounter=0,FixedHeader=function(t,e){if(!DataTable.versionCheck("2"))throw"Warning: FixedHeader requires DataTables 2 or newer";if(!(this instanceof FixedHeader))throw"FixedHeader must be initialised with the 'new' keyword.";!0===e&&(e={}),t=new DataTable.Api(t),this.c=$.extend(!0,{},FixedHeader.defaults,e),this.s={dt:t,position:{theadTop:0,tbodyTop:0,tfootTop:0,tfootBottom:0,width:0,left:0,tfootHeight:0,theadHeight:0,windowHeight:$(window).height(),visible:!0},headerMode:null,footerMode:null,autoWidth:t.settings()[0].oFeatures.bAutoWidth,namespace:".dtfc"+_instCounter++,scrollLeft:{header:-1,footer:-1},enable:!0,autoDisable:!1},this.dom={floatingHeader:null,thead:$(t.table().header()),tbody:$(t.table().body()),tfoot:$(t.table().footer()),header:{host:null,floating:null,floatingParent:$('<div class="dtfh-floatingparent"><div></div></div>'),placeholder:null},footer:{host:null,floating:null,floatingParent:$('<div class="dtfh-floatingparent"><div></div></div>'),placeholder:null}},this.dom.header.host=this.dom.thead.parent(),this.dom.footer.host=this.dom.tfoot.parent();e=t.settings()[0];if(e._fixedHeader)throw"FixedHeader already initialised on table "+e.nTable.id;(e._fixedHeader=this)._constructor()};$.extend(FixedHeader.prototype,{destroy:function(){var t=this.dom;this.s.dt.off(".dtfc"),$(window).off(this.s.namespace),t.header.rightBlocker&&t.header.rightBlocker.remove(),t.header.leftBlocker&&t.header.leftBlocker.remove(),t.footer.rightBlocker&&t.footer.rightBlocker.remove(),t.footer.leftBlocker&&t.footer.leftBlocker.remove(),this.c.header&&this._modeChange("in-place","header",!0),this.c.footer&&t.tfoot.length&&this._modeChange("in-place","footer",!0)},enable:function(t,e,o){this.s.enable=t,this.s.enableType=o,!e&&void 0!==e||(this._positions(),this._scroll(!0))},enabled:function(){return this.s.enable},headerOffset:function(t){return void 0!==t&&(this.c.headerOffset=t,this.update()),this.c.headerOffset},footerOffset:function(t){return void 0!==t&&(this.c.footerOffset=t,this.update()),this.c.footerOffset},update:function(t){var e=this.s.dt.table().node();(this.s.enable||this.s.autoDisable)&&($(e).is(":visible")?(this.s.autoDisable=!1,this.enable(!0,!1)):(this.s.autoDisable=!0,this.enable(!1,!1)),0!==$(e).children("thead").length)&&(this._positions(),this._scroll(void 0===t||t))},_constructor:function(){var o=this,i=this.s.dt,t=($(window).on("scroll"+this.s.namespace,function(){o._scroll()}).on("resize"+this.s.namespace,DataTable.util.throttle(function(){o.s.position.windowHeight=$(window).height(),o.update()},50)),$(".fh-fixedHeader")),t=(!this.c.headerOffset&&t.length&&(this.c.headerOffset=t.outerHeight()),$(".fh-fixedFooter"));!this.c.footerOffset&&t.length&&(this.c.footerOffset=t.outerHeight()),i.on("column-reorder.dt.dtfc column-visibility.dt.dtfc column-sizing.dt.dtfc responsive-display.dt.dtfc",function(t,e){o.update()}).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:function(t,e){var o=this,i=this.s.dt,s=this.dom[t],a="header"===t?this.dom.thead:this.dom.tfoot;if("footer"!==t||!this._scrollEnabled())if(!e&&s.floating)s.floating.removeClass("fixedHeader-floating fixedHeader-locked");else{s.floating&&(null!==s.placeholder&&s.placeholder.remove(),s.floating.children().detach(),s.floating.remove());function d(){var t=r.scrollLeft();o.s.scrollLeft={footer:t,header:t},s.floatingParent.scrollLeft(o.s.scrollLeft.header)}for(var e=$(i.table().node()),r=$(e.parent()),n=this._scrollEnabled(),n=(s.floating=$(i.table().node().cloneNode(!1)).attr("aria-hidden","true").css({top:0,left:0}).removeAttr("id"),s.floatingParent.css({width:r[0].offsetWidth,overflow:"hidden",height:"fit-content",position:"fixed",left:n?e.offset().left+r.scrollLeft():0}).css("header"===t?{top:this.c.headerOffset,bottom:""}:{top:"",bottom:this.c.footerOffset}).addClass("footer"===t?"dtfh-floatingparent-foot":"dtfh-floatingparent-head").appendTo("body").children().eq(0).append(s.floating),this._stickyPosition(s.floating,"-"),d(),r.off("scroll.dtfh").on("scroll.dtfh",d),s.floatingParent.children().css({width:"fit-content",paddingRight:o.s.dt.settings()[0].oBrowser.barWidth}),$("footer"===t?"div.dtfc-bottom-blocker":"div.dtfc-top-blocker",i.table().container())),l=(n.length&&n.clone().appendTo(s.floatingParent).css({position:"fixed",right:n.width()}),s.placeholder=a.clone(!1),s.placeholder.find("*[id]").removeAttr("id"),s.host.prepend(s.placeholder),s.floating.append(a),s.placeholder.parent().find("colgroup").clone().appendTo(s.floating).find("col")),f=this.s.dt.columns({visible:!0}).widths(),h=0;h<f.length;h++)l.eq(h).css("width",f[h])}},_stickyPosition:function(t,e){var i;this._scrollEnabled()&&(i="rtl"===$(this.s.dt.table().node()).css("direction"),t.find("th").each(function(){var t,e,o;"sticky"===$(this).css("position")&&(t=$(this).css("right"),e=$(this).css("left"),"auto"===t||i?"auto"!==e&&i&&(o=+e.replace(/px/g,""),$(this).css("left",0<o?o:0)):(o=+t.replace(/px/g,""),$(this).css("right",0<o?o:0)))}))},_horizontal:function(t,e){var o,i=this.dom[t],s=this.s.scrollLeft;i.floating&&s[t]!==e&&(this._scrollEnabled()&&(o=$($(this.s.dt.table().node()).parent()).scrollLeft(),i.floating.scrollLeft(o),i.floatingParent.scrollLeft(o)),s[t]=e)},_modeChange:function(t,e,o){var i,s,a,d,r,n,l,f=this.dom[e],h=this.s.position,c=this._scrollEnabled();"footer"===e&&c||(i=function(t){f.floating[0].style.setProperty("width",t+"px","important"),c||f.floatingParent[0].style.setProperty("width",t+"px","important")},d=this.dom["footer"===e?"tfoot":"thead"],s=$.contains(d[0],document.activeElement)?document.activeElement:null,r=$($(this.s.dt.table().node()).parent()),"in-place"===t?(f.placeholder&&(f.placeholder.remove(),f.placeholder=null),"header"===e?f.host.prepend(d):f.host.append(d),f.floating&&(f.floating.remove(),f.floating=null,this._stickyPosition(f.host,"+")),f.floatingParent&&(f.floatingParent.find("div.dtfc-top-blocker").remove(),f.floatingParent.remove()),$($(f.host.parent()).parent()).scrollLeft(r.scrollLeft())):"in"===t?(this._clone(e,o),d=r.offset(),l=(a=$(document).scrollTop())+$(window).height(),n=c?d.top:h.tbodyTop,d=c?d.top+r.outerHeight():h.tfootTop,r="footer"===e?l<n?h.tfootHeight:n+h.tfootHeight-l:a+this.c.headerOffset+h.theadHeight-d,n="header"===e?"top":"bottom",l=this.c[e+"Offset"]-(0<r?r:0),f.floating.addClass("fixedHeader-floating"),f.floatingParent.css(n,l).css({left:h.left,"z-index":3}),i(h.width),"footer"===e&&f.floating.css("top","")):"below"===t?(this._clone(e,o),f.floating.addClass("fixedHeader-locked"),f.floatingParent.css({position:"absolute",top:h.tfootTop-h.theadHeight,left:h.left+"px"}),i(h.width)):"above"===t&&(this._clone(e,o),f.floating.addClass("fixedHeader-locked"),f.floatingParent.css({position:"absolute",top:h.tbodyTop,left:h.left+"px"}),i(h.width)),s&&s!==document.activeElement&&setTimeout(function(){s.focus()},10),this.s.scrollLeft.header=-1,this.s.scrollLeft.footer=-1,this.s[e+"Mode"]=t)},_positions:function(){var t=this.s.dt,e=t.table(),o=this.s.position,i=this.dom,e=$(e.node()),s=this._scrollEnabled(),a=$(t.table().header()),t=$(t.table().footer()),i=i.tbody,d=e.parent();o.visible=e.is(":visible"),o.width=e.outerWidth(),o.left=e.offset().left,o.theadTop=a.offset().top,o.tbodyTop=(s?d:i).offset().top,o.tbodyHeight=(s?d:i).outerHeight(),o.theadHeight=a.outerHeight(),o.theadBottom=o.theadTop+o.theadHeight,o.tfootTop=o.tbodyTop+o.tbodyHeight,t.length?(o.tfootBottom=o.tfootTop+t.outerHeight(),o.tfootHeight=t.outerHeight()):(o.tfootBottom=o.tfootTop,o.tfootHeight=0)},_scroll:function(t){var e,o,i,s,a,d,r,n,l,f,h,c,p,g,u;this.s.dt.settings()[0].bDestroying||(e=this._scrollEnabled(),i=(o=$(this.s.dt.table().node()).parent()).offset(),f=o.outerHeight(),s=$(document).scrollLeft(),a=$(document).scrollTop(),d=$(window).height()+a,h=this.s.position,c=e?i.top:h.tbodyTop,n=(e?i:h).left,f=e?i.top+f:h.tfootTop,l=e?o.outerWidth():h.tbodyWidth,this.c.header&&(!this.s.enable||!h.visible||a+this.c.headerOffset+h.theadHeight<=c?r="in-place":a+this.c.headerOffset+h.theadHeight>c&&a+this.c.headerOffset+h.theadHeight<f?(r="in",a+this.c.headerOffset+h.theadHeight>f||void 0===this.dom.header.floatingParent?t=!0:this.dom.header.floatingParent.css({top:this.c.headerOffset,position:"fixed"}).children().eq(0).append(this.dom.header.floating)):r="below",!t&&r===this.s.headerMode||this._modeChange(r,"header",t),this._horizontal("header",s)),p={offset:{top:0,left:0},height:0},g={offset:{top:0,left:0},height:0},this.c.footer&&this.dom.tfoot.length&&this.dom.tfoot.find("th, td").length&&(!this.s.enable||!h.visible||h.tfootBottom+this.c.footerOffset<=d?u="in-place":f+h.tfootHeight+this.c.footerOffset>d&&c+this.c.footerOffset<d?(u="in",t=!0):u="above",!t&&u===this.s.footerMode||this._modeChange(u,"footer",t),this._horizontal("footer",s),f=function(t){return{offset:t.offset(),height:t.outerHeight()}},p=this.dom.header.floating?f(this.dom.header.floating):f(this.dom.thead),g=this.dom.footer.floating?f(this.dom.footer.floating):f(this.dom.tfoot),e)&&g.offset.top>a&&(c=d+((h=a-i.top)>-p.height?h:0)-(p.offset.top+(h<-p.height?p.height:0)+g.height),o.outerHeight(c=c<0?0:c),Math.round(o.outerHeight())>=Math.round(c)?$(this.dom.tfoot.parent()).addClass("fixedHeader-floating"):$(this.dom.tfoot.parent()).removeClass("fixedHeader-floating")),this.dom.header.floating&&this.dom.header.floatingParent.css("left",n-s),this.dom.footer.floating&&this.dom.footer.floatingParent.css("left",n-s),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=$("div.dtfc-"+t+"-"+e+"-blocker")).length?null:i.clone().css("z-index",1):o)&&("in"===r||"below"===r?o.appendTo("body").css({top:("top"===e?p:g).offset.top,left:"right"===t?n+l-o.width():n}):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:function(){var t=this.s.dt.settings()[0].oScroll;return""!==t.sY||""!==t.sX}}),FixedHeader.version="4.0.0",FixedHeader.defaults={header:!0,footer:!1,headerOffset:0,footerOffset:0},$.fn.dataTable.FixedHeader=FixedHeader,$.fn.DataTable.FixedHeader=FixedHeader,$(document).on("init.dt.dtfh",function(t,e,o){var i;"dt"===t.namespace&&(t=e.oInit.fixedHeader,i=DataTable.defaults.fixedHeader,t||i)&&!e._fixedHeader&&(i=$.extend({},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)})}),$.each(["header","footer"],function(t,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;