(function(o,p){typeof exports=="object"&&typeof module<"u"?p(exports,require("../../core/plugin/base-plugin")):typeof define=="function"&&define.amd?define(["exports","../../core/plugin/base-plugin"],p):(o=typeof globalThis<"u"?globalThis:o||self,p(o.TbwGridPlugin_print={},o.TbwGrid))})(this,(function(o,p){"use strict";const h="tbw-print-isolation-style";function u(n,e){const t=document.createElement("style");return t.id=h,t.textContent=`
    /* Print isolation: hide everything except the target grid */
    @media print {
      /* Hide all body children by default */
      body > *:not(#${n}) {
        display: none !important;
      }

      /* But show the grid and ensure it's not hidden by ancestor rules */
      #${n} {
        display: block !important;
        position: static !important;
        visibility: visible !important;
        opacity: 1 !important;
        overflow: visible !important;
        height: auto !important;
        width: 100% !important;
        max-height: none !important;
        margin: 0 !important;
        padding: 0 !important;
        transform: none !important;
      }

      /* If grid is nested, we need to show its ancestors too */
      #${n},
      #${n} * {
        visibility: visible !important;
      }

      /* Walk up the DOM and show all ancestors of the grid */
      body *:has(> #${n}),
      body *:has(#${n}) {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        overflow: visible !important;
        height: auto !important;
        position: static !important;
        transform: none !important;
        background: transparent !important;
        border: none !important;
        padding: 0 !important;
        margin: 0 !important;
      }

      /* Hide siblings of ancestors (everything that's not in the path to the grid) */
      body *:has(#${n}) > *:not(:has(#${n})):not(#${n}) {
        display: none !important;
      }

      /* Page settings */
      @page {
        size: ${e};
        margin: 1cm;
      }

      /* Ensure proper print styling */
      body {
        margin: 0 !important;
        padding: 0 !important;
        background: white !important;
        color-scheme: light !important;
      }
    }

    /* Screen: also apply isolation for print preview */
    @media screen {
      /* When this stylesheet is active, we're about to print */
      /* No screen-specific rules needed - isolation only applies to print */
    }
  `,t}async function c(n,e={}){const{orientation:t="landscape"}=e,i=n.id;document.querySelectorAll(`#${CSS.escape(i)}`).length>1&&console.warn(`[tbw-grid:print] Multiple elements found with id="${i}". Print isolation may not work correctly. Ensure each grid has a unique ID.`),document.getElementById(h)?.remove();const a=u(i,t);return document.head.appendChild(a),new Promise(l=>{const d=()=>{window.removeEventListener("afterprint",d),document.getElementById(h)?.remove(),l()};window.addEventListener("afterprint",d),window.print(),setTimeout(()=>{window.removeEventListener("afterprint",d),document.getElementById(h)?.remove(),l()},5e3)})}const g=".tbw-print-header,.tbw-print-footer{display:none}@media print{tbw-grid{overflow:visible!important;height:auto!important;border:none!important;border-radius:0!important;color-scheme:light only;-webkit-print-color-adjust:exact;print-color-adjust:exact}tbw-grid .tbw-grid-content{overflow:visible!important;height:auto!important;max-height:none!important}tbw-grid .tbw-scroll-area{overflow:visible!important;height:auto!important;max-height:none!important}tbw-grid .rows-body{overflow:visible!important;height:auto!important;max-height:none!important}tbw-grid .rows-container,tbw-grid .rows-viewport,tbw-grid .rows{overflow:visible!important;height:auto!important;max-height:none!important;transform:none!important}tbw-grid .rows-viewport .rows{position:static!important}tbw-grid .resize-handle,tbw-grid [part=sort-indicator],tbw-grid .tbw-filter-btn,tbw-grid .tool-panel,tbw-grid .tool-panel-content,tbw-grid .tbw-shell-header,tbw-grid .shell-toolbar,tbw-grid .tool-panel-toggle,tbw-grid [data-print-hide],tbw-grid .expander-cell,tbw-grid .tree-toggle,tbw-grid .context-menu,tbw-grid .faux-vscroll{display:none!important}tbw-grid .tbw-print-header{display:flex;justify-content:space-between;align-items:baseline;padding:var(--tbw-spacing-md, .5em) 0;margin-bottom:var(--tbw-spacing-md, .5em);border-bottom:2px solid var(--tbw-print-border, var(--tbw-color-border-strong));font-family:inherit}.tbw-print-header-title{font-size:1.25em;font-weight:700}.tbw-print-header-timestamp{font-size:var(--tbw-font-size-sm, .875em);color:var(--tbw-print-muted, var(--tbw-color-fg-muted))}tbw-grid .tbw-print-footer{display:block;margin-top:var(--tbw-spacing-md, .5em);padding-top:var(--tbw-spacing-md, .5em);border-top:1px solid var(--tbw-print-border, var(--tbw-color-border));font-size:var(--tbw-font-size-xs, .75em);color:var(--tbw-print-muted, var(--tbw-color-fg-muted));text-align:right}tbw-grid .data-grid-row{break-inside:avoid;page-break-inside:avoid}tbw-grid .cell{border:1px solid var(--tbw-print-cell-border, var(--tbw-color-border))!important}tbw-grid .header-row,tbw-grid .data-grid-row{padding-right:1px}tbw-grid .data-grid-row:hover,tbw-grid .cell:hover{background:inherit!important}@page{margin:1cm}@page{tbw-grid.print-landscape{size:landscape}}@page{tbw-grid.print-portrait{size:portrait}}}",b={button:!1,orientation:"landscape",warnThreshold:500,maxRows:0,includeTitle:!0,includeTimestamp:!0,title:"",isolate:!1};class f extends p.BaseGridPlugin{name="print";version="1.0.0";styles=g;#n=!1;#e=null;#r=null;#o=null;#t=null;#i=null;#a=null;get#s(){return this.grid}isPrinting(){return this.#n}async print(e){if(this.#n){console.warn("[PrintPlugin] Print already in progress");return}const t=this.gridElement;if(!t){console.warn("[PrintPlugin] Grid not available");return}const i={...b,...this.config,...e},a=this.rows.length;let l=a,d=!1;if(i.warnThreshold>0&&a>i.warnThreshold){const m=i.maxRows>0?`

Note: Output will be limited to ${i.maxRows.toLocaleString()} rows.`:"";if(!confirm(`This grid has ${a.toLocaleString()} rows. Printing large datasets may cause performance issues or browser slowdowns.${m}

Click OK to continue, or Cancel to abort.`))return}i.maxRows>0&&a>i.maxRows&&(l=i.maxRows,d=!0),this.#n=!0;const w=performance.now();this.emit("print-start",{rowCount:l,limitApplied:d,originalRowCount:a});try{const m=this.#s;this.#r={bypassThreshold:m._virtualization?.bypassThreshold??24},this.#c(),d&&(this.#o=this.sourceRows,this.grid.rows=this.sourceRows.slice(0,l),await new Promise(r=>setTimeout(r,50))),(i.includeTitle||i.includeTimestamp)&&this.#d(i),await this.#p(),await new Promise(r=>requestAnimationFrame(r)),await new Promise(r=>requestAnimationFrame(r)),t.classList.add(`print-${i.orientation}`),await new Promise(r=>requestAnimationFrame(r)),await new Promise(r=>requestAnimationFrame(r)),i.isolate?await this.#h(i):await this.#m(),this.emit("print-complete",{success:!0,rowCount:l,duration:Math.round(performance.now()-w)})}catch(m){console.error("[PrintPlugin] Print failed:",m),this.emit("print-complete",{success:!1,rowCount:0,duration:Math.round(performance.now()-w)})}finally{this.#u(),this.#n=!1}}#d(e){const t=this.gridElement;if(t){if(this.#t=document.createElement("div"),this.#t.className="tbw-print-header",e.includeTitle){const i=e.title||this.grid.effectiveConfig?.shell?.header?.title||"Grid Data",s=document.createElement("div");s.className="tbw-print-header-title",s.textContent=i,this.#t.appendChild(s)}if(e.includeTimestamp){const i=document.createElement("div");i.className="tbw-print-header-timestamp",i.textContent=`Printed: ${new Date().toLocaleString()}`,this.#t.appendChild(i)}t.insertBefore(this.#t,t.firstChild),this.#i=document.createElement("div"),this.#i.className="tbw-print-footer",this.#i.textContent=`Page generated from ${window.location.hostname}`,t.appendChild(this.#i)}}async#p(){const e=this.#s;if(!e._virtualization)return;const t=this.rows.length;e._virtualization.bypassThreshold=t+100,e.refreshVirtualWindow(!0),await new Promise(i=>setTimeout(i,100))}async#m(){return new Promise(e=>{const t=()=>{window.removeEventListener("afterprint",t),e()};window.addEventListener("afterprint",t),window.print(),setTimeout(()=>{typeof window<"u"&&window.removeEventListener("afterprint",t),e()},1e3)})}async#h(e){const t=this.gridElement;t&&await c(t,{orientation:e.orientation})}#c(){const e=this.columns;if(e){this.#e=new Map;for(const t of e)t.printHidden&&t.field&&(this.#e.set(t.field,!t.hidden),this.grid.setColumnVisible(t.field,!1))}}#w(){if(this.#e){for(const[e,t]of this.#e)this.grid.setColumnVisible(e,t);this.#e=null}}#u(){const e=this.gridElement;if(!e)return;this.#w(),e.classList.remove("print-portrait","print-landscape"),this.#a!==null&&(e.style.transform="",e.style.transformOrigin="",e.style.width="",this.#a=null),this.#t&&(this.#t.remove(),this.#t=null),this.#i&&(this.#i.remove(),this.#i=null);const t=this.#s;this.#r&&t._virtualization&&(t._virtualization.bypassThreshold=this.#r.bypassThreshold,t.refreshVirtualWindow(!0),this.#r=null),this.#o!==null&&(this.grid.rows=this.#o,this.#o=null)}afterRender(){this.config?.button&&!this.#l&&(this.#g(),this.#l=!0)}#l=!1;#g(){this.#s.registerToolbarContent?.({id:"print-button",order:900,render:t=>{const i=document.createElement("button");i.className="tbw-toolbar-btn tbw-print-btn",i.title="Print grid",i.type="button";const s=this.resolveIcon("print")||"🖨️";this.setIcon(i,s),i.addEventListener("click",()=>{this.print()},{signal:this.disconnectSignal}),t.appendChild(i)}})}}o.PrintPlugin=f,o.printGridIsolated=c,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})}));
//# sourceMappingURL=print.umd.js.map
