(function(f,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("../../core/plugin/base-plugin")):typeof define=="function"&&define.amd?define(["exports","../../core/plugin/base-plugin"],d):(f=typeof globalThis<"u"?globalThis:f||self,d(f.TbwGridPlugin_pinnedColumns={},f.TbwGrid))})(this,(function(f,d){"use strict";function g(n){return n.filter(t=>t.sticky==="left")}function p(n){return n.filter(t=>t.sticky==="right")}function u(n){return n.some(t=>t.sticky==="left"||t.sticky==="right")}function h(n,t){const i=Array.from(n.querySelectorAll(".header-row .cell"));if(!i.length)return;const s=new Map;t.forEach((l,o)=>{l.field&&s.set(l.field,o)});let c=0;for(const l of t)if(l.sticky==="left"){const o=s.get(l.field),e=i.find(r=>r.getAttribute("data-field")===l.field);e&&(e.classList.add("sticky-left"),e.style.position="sticky",e.style.left=c+"px",o!==void 0&&n.querySelectorAll(`.data-grid-row .cell[data-col="${o}"]`).forEach(r=>{r.classList.add("sticky-left"),r.style.position="sticky",r.style.left=c+"px"}),c+=e.offsetWidth)}let a=0;for(const l of[...t].reverse())if(l.sticky==="right"){const o=s.get(l.field),e=i.find(r=>r.getAttribute("data-field")===l.field);e&&(e.classList.add("sticky-right"),e.style.position="sticky",e.style.right=a+"px",o!==void 0&&n.querySelectorAll(`.data-grid-row .cell[data-col="${o}"]`).forEach(r=>{r.classList.add("sticky-right"),r.style.position="sticky",r.style.right=a+"px"}),a+=e.offsetWidth)}}function y(n){n.querySelectorAll(".sticky-left, .sticky-right").forEach(i=>{i.classList.remove("sticky-left","sticky-right"),i.style.position="",i.style.left="",i.style.right=""})}class k extends d.BaseGridPlugin{name="pinnedColumns";get defaultConfig(){return{}}isApplied=!1;leftOffsets=new Map;rightOffsets=new Map;detach(){this.leftOffsets.clear(),this.rightOffsets.clear(),this.isApplied=!1}static detect(t,i){const s=i?.columns;return Array.isArray(s)?u(s):!1}processColumns(t){return this.isApplied=u([...t]),[...t]}afterRender(){if(!this.isApplied)return;const t=this.grid,i=[...this.columns];if(!u(i)){y(t),this.isApplied=!1;return}queueMicrotask(()=>{h(t,i)})}onPluginQuery(t){switch(t.type){case d.PLUGIN_QUERIES.CAN_MOVE_COLUMN:{const i=t.context,s=i.sticky;if(s==="left"||s==="right")return!1;const c=i.meta?.sticky;return c==="left"||c==="right"?!1:void 0}default:return}}refreshStickyOffsets(){const t=[...this.columns];h(this.grid,t)}getLeftPinnedColumns(){const t=[...this.columns];return g(t)}getRightPinnedColumns(){const t=[...this.columns];return p(t)}clearStickyPositions(){y(this.grid)}getHorizontalScrollOffsets(t,i){if(!this.isApplied)return;let s=0,c=0;if(t){const l=t.querySelectorAll(".sticky-left"),o=t.querySelectorAll(".sticky-right");l.forEach(e=>{s+=e.offsetWidth}),o.forEach(e=>{c+=e.offsetWidth})}else this.grid.querySelectorAll(".header-row .cell").forEach(e=>{e.classList.contains("sticky-left")?s+=e.offsetWidth:e.classList.contains("sticky-right")&&(c+=e.offsetWidth)});const a=i?.classList.contains("sticky-left")||i?.classList.contains("sticky-right");return{left:s,right:c,skipScroll:a}}}f.PinnedColumnsPlugin=k,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})}));
//# sourceMappingURL=pinned-columns.umd.js.map
