/* eslint-disable no-param-reassign */
import { GridSortColumn } from '@vaadin/grid/vaadin-grid-sort-column';

export class GridTextColumnClass extends GridSortColumn {
  get sortable() {
    return this.getAttribute('sortable') === 'true';
  }

  _defaultRenderer(cell, _col, model) {
    const data = model.item[this.path] || '';
    const content = Array.isArray(data) ? data.join(', ') : data;

    this.__setTextContent(cell, content);
    cell.title = content;
  }

  _defaultHeaderRenderer(root, _column) {
    if (this.sortable) {
      super._defaultHeaderRenderer(root, _column);

      return;
    }

    this.__setTextContent(root, this.__getHeader(this.header, this.path));
  }
}
