/**
@license
Copyright (c) 2017 Vaadin Ltd.
This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
*/
import{GestureEventListeners as e}from"../../../@polymer/polymer/lib/mixins/gesture-event-listeners.js";import{addListener as t}from"../../../@polymer/polymer/lib/utils/gestures.js";export const ColumnResizingMixin=r=>class ColumnResizingMixin extends(e(r)){ready(){super.ready();const e=this.$.scroller;t(e,"track",this._onHeaderTrack.bind(this)),e.addEventListener("touchmove",(t=>e.hasAttribute("column-resizing")&&t.preventDefault())),e.addEventListener("contextmenu",(e=>"resize-handle"==e.target.getAttribute("part")&&e.preventDefault())),e.addEventListener("mousedown",(e=>"resize-handle"===e.target.getAttribute("part")&&e.preventDefault()))}_onHeaderTrack(e){const t=e.target;if("resize-handle"===t.getAttribute("part")){let o=t.parentElement._column;for(this._toggleAttribute("column-resizing",!0,this.$.scroller);"vaadin-grid-column-group"===o.localName;)o=Array.prototype.slice.call(o._childColumns,0).sort((function(e,t){return e._order-t._order})).filter((function(e){return!e.hidden})).pop();const l=Array.from(this.$.header.querySelectorAll('[part~="row"]:last-child [part~="cell"]'));var r=l.filter((e=>e._column===o))[0];if(r.offsetWidth){var i=window.getComputedStyle(r),n=10+parseInt(i.paddingLeft)+parseInt(i.paddingRight)+parseInt(i.borderLeftWidth)+parseInt(i.borderRightWidth)+parseInt(i.marginLeft)+parseInt(i.marginRight);const t=r.offsetWidth+(this.__isRTL?r.getBoundingClientRect().left-e.detail.x:e.detail.x-r.getBoundingClientRect().right);o.width=Math.max(n,t)+"px",o.flexGrow=0}l.sort((function(e,t){return e._column._order-t._column._order})).forEach((function(e,t,i){t<i.indexOf(r)&&(e._column.width=e.offsetWidth+"px",e._column.flexGrow=0)})),"end"===e.detail.state&&(this._toggleAttribute("column-resizing",!1,this.$.scroller),this.dispatchEvent(new CustomEvent("column-resize",{detail:{resizedColumn:o}}))),this._resizeHandler()}}};