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