/**
 * @license
 * Copyright 2021 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */
import{dim1 as t,dim2 as i}from"./shared/BaseLayout.js";import{GridBaseLayout as s}from"./shared/GridBaseLayout.js";export const grid=t=>Object.assign({type:GridLayout},t);export class GridLayout extends s{get _delta(){return this._metrics.itemSize1+this._metrics.gap1}_getItemSize(t){return{[this._sizeDim]:this._metrics.itemSize1,[this._secondarySizeDim]:this._metrics.itemSize2}}_getActiveItems(){const t=this._metrics,{rolumns:i}=t;if(0===i)this._first=-1,this._last=-1,this._physicalMin=0,this._physicalMax=0;else{const{padding1:s}=t,e=Math.max(0,this._scrollPosition-this._overhang),h=Math.min(this._scrollSize,this._scrollPosition+this._viewDim1+this._overhang),a=Math.max(0,Math.floor((e-s.start)/this._delta)),r=Math.max(0,Math.ceil((h-s.start)/this._delta));this._first=a*i,this._last=Math.min(r*i-1,this.items.length-1),this._physicalMin=s.start+this._delta*a,this._physicalMax=s.start+this._delta*r}}_getItemPosition(s){const{rolumns:e,padding1:h,positions:a,itemSize1:r,itemSize2:o}=this._metrics;return{[this._positionDim]:h.start+Math.floor(s/e)*this._delta,[this._secondaryPositionDim]:a[s%e],[t(this.direction)]:r,[i(this.direction)]:o}}_updateScrollSize(){const{rolumns:t,gap1:i,padding1:s,itemSize1:e}=this._metrics;let h=1;if(t>0){const a=Math.ceil(this.items.length/t);h=s.start+a*e+(a-1)*i+s.end}this._scrollSize=h}}