import Component  from '../component.js'
import TdComponent from '../td.js'
import TrComponent from '../tr.js'
import { elementAttributeContains } from '../../core/utils.js';
import TheadComponent from '../thead.js';
import TbodyComponent from '../tbody.js';
import TfootComponent from '../tfoot.js';
import TableComponent from '../table.js';

export default class CoEuiTable extends Component {
    constructor(parent) {
      let selector = '*[self::eui-table or self::table[@euiTable]]';
      super(parent, selector);
      //https://citnet.tech.ec.europa.eu/CITnet/stash/projects/CSDR/repos/eui/browse/packages/components/eui-table/eui-table.component.html?at=support/13.x
    }
    get theadCO() {
      return new TheadComponent(this.currentPath);
    }
    async hasHeader() {
      return await (await $(this.theadCO.currentPath)).isExisting();
    }
    get tbodyCO() {
      return new TbodyComponent(this.currentPath);
    }
    async hasBody() {
      return await (await $(this.tbodyCO.currentPath)).isExisting();
    }
    async tbodyIsLoading() {
      return await elementAttributeContains(this.tbodyCO.currentPath, 'class', 'eui-table__loading');
    }
    get bodyRowCO() {
      return new TrComponent(this.tbodyCO);
    }
    get bodyCellCO() {
      return new TdComponent(this.tbodyCO);
    }
    get tfootCO() {
      return new TfootComponent(this.currentPath);
    }
    async hasFooter() {
      return await (await $(this.tfootCO.currentPath)).isExisting();
    }
    get footerRowCO() {
      return new TrComponent(this.tfootCO);
    }
    get footerCellCO() {
      return new TdComponent(this.tfootCO);
    }
    get stickyHeaderContainer() {
      return this.currentPath + '//div[contains(@class, "eui-table__sticky-header-container")]';
    }
    get stickyHeaderTableCO() {
      return new TableComponent(this.stickyHeader).byAttributeContains('class','eui-table');
    }
    get stickyHeaderTableTheadCO() {
      return new TheadComponent(this.stickyHeaderTableCO);
    }
    async hasStickyHeader() {
      return await elementAttributeContains(this.currentPath, 'class', 'eui-table--sticky-header');
    }
    async euiTableDraggable() {
      return await elementAttributeContains(this.currentPath, 'class', 'eui-table--draggable');
    }
    async euiTableCompact() {
      return await elementAttributeContains(this.currentPath, 'class', 'eui-table--compact');
    }
    async euiTableBordered() {
      return await elementAttributeContains(this.currentPath, 'class', 'eui-table--bordered');
    }
    async euiTableFixedLayout() {
      return await elementAttributeContains(this.currentPath, 'class', 'eui-table--fixed-layout');
    }
    async euiTableResponsive() {
      return await elementAttributeContains(this.currentPath, 'class', 'eui-table--responsive');
    }


}


