import { timingSafeEqual } from "crypto";

export interface IGridRowParams {
    y: number;
    rowIndex: number;
    zIndexRow: number;
    height: number;
    // hidden: boolean;
  }
  
  export interface IGridRowDataset {
    y: number;
    row: number;
    zIndexRow: number;
    height: number;
  }
  
  export interface IGridRow {
    params: IGridRowParams;
    dataset: IGridRowDataset;
    rowEl: HTMLDivElement;
    hidden: boolean;
    row: number;
    setHeight(size: number): void;
    setOffet(offset: number): void;
    setPosition(offset: number, move?: boolean): void;
    setIndex(row: number, y: number, zIndex: number): void;
    setHover(n: boolean): void;
  }
  
  export class GridRow implements IGridRow {
    public dataset: IGridRowDataset;
    public rowEl: HTMLDivElement;
    public hidden: boolean = false;
    public row: number = 0;
    constructor(public params: IGridRowParams) {
      let dataset: any = {
        y: params.y,
        row: params.rowIndex,
        zIndexRow: params.zIndexRow,
        height: params.height
      };
      // this.hidden = params.hidden;
      this.dataset = dataset;
      this.row = params.rowIndex;
  
      this.rowEl = document.createElement('div');
      this.rowEl.className = 'grid-row';
      this.rowEl.style.setProperty('transform', `translateY(${params.y}px)`);
      this.rowEl.style.setProperty('z-index', `${params.zIndexRow}`);
      this.rowEl.dataset.row = params.rowIndex.toString();
      // this.rowEl.dataset.height = params.height.toString();
    }
    public setHeight(size: number): void {
      this.dataset.height = size;
    }
    public setOffet(offset: number): void {
      this.rowEl.style.setProperty('transform', `translateY(${this.dataset.y + offset}px)`);
    }
    public setPosition(offset: number, move?: boolean): void {
      this.dataset.y += offset;
      if (!move) return;
      this.rowEl.style.setProperty('transform', `translateY(${this.dataset.y}px)`);
      // this.dataset.height += offset;
    }
    public setIndex(row: number, y: number, zIndex: number): void {
      this.dataset.row = row;
      this.dataset.y = y;
      this.dataset.zIndexRow = zIndex;
      this.rowEl.style.setProperty('transform', `translateY(${this.dataset.y}px)`);
      this.rowEl.style.setProperty('z-index', `${zIndex}`);
      this.rowEl.dataset.row = row.toString();
    }
    public setHover(n: boolean): void {
      if (n) {
        this.rowEl.classList.add('hover')
      } else {
        this.rowEl.classList.remove('hover')
      }
    }
  }
  