import Component  from '../component.js'
import CoEuiDropdown from './eui-dropdown.js'
import CoEuiButton from './eui-button.js'
import CdkOverlayContainer from '../cdk-overlay-container.js'
import CoEuiDropdownContent from './eui-dropdown-content.js'
import CoEuiList from './eui-list.js'
import CoEuiLabel from './eui-label.js'
import CoEuiIcon from './eui-icon.js'
import ButtonComponent from '../button.js'


export default class CoEuiTablePaginator extends Component {
  constructor(parent) {
    let selector = 'eui-table-paginator';
    super(parent, selector);
    this.overlayContainer = new CdkOverlayContainer('//body');
  //https://citnet.tech.ec.europa.eu/CITnet/stash/projects/CSDR/repos/eui/browse/packages/components/eui-table/paginator/eui-table-paginator.component.html?at=support/13.x
  }

  get paginator() {
    return this.currentPath + '//div[contains(@class,"eui-table-paginator__page")]';
  }
  async hasPaginator(){
    return await (await $(this.paginator)).isExisting();
  }
  get pageSelector() {
    return this.paginator + '//div[contains(@class, "eui-table-paginator__page-selector")]';
  }
  get dropdownCO() {
    return new CoEuiDropdown(this.pageSelector);
  }
  get euiButtonCO(){
    return new CoEuiButton(this.dropdownCO);
  }
  get labelCO() {
    return new CoEuiLabel(this.euiButtonCO);
  }
  get carretDownCO() {
    return new CoEuiIcon(this.euiButtonCO).byAttributeContains('isonclass','eui-icon-caret-down');
  }
  get dropdownContentCO() {
    return new CoEuiDropdownContent(this.overlayContainer.overlayPane);
  }
  get listCO() {
    return new CoEuiList(this.dropdownContentCO);
  }
  get pageSizeOption() {
    return new ButtonComponent(this.listCO);
  }
  get pageRange(){
    return this.paginator + '//div[contains(@class, "eui-table-paginator__page-range")]';
  }
  get navigator() {
    return this.currentPath + '//div[contains(@class, "eui-table-paginator__page-navigation")]';
  }
  async hasNavigator(){
    return await (await $(this.navigator)).isExisting();
  }
  get navigatorItem() {
    return this.navigator + '//div[contains(@class, "eui-table-paginator__page-navigation-item")]';
  }
  get navigatorItemButtonCO() {
    return new CoEuiButton(this.navigatorItem);
  }
  // arrorw buttons and icons
  get caretFirstCO() {
    return new CoEuiIcon(this.navigatorItemButtonCO).byAttributeContains('iconclass','eui-icon-caret-first');
  }
  get caretFirstButton() {
    return this.caretFirstCO.currentPath + '/ancestor-or-self::button[1]'
  }
  get caretLeftCO() {
    return new CoEuiIcon(this.navigatorItemButtonCO).byAttributeContains('iconclass','eui-icon-caret-left');
  }
  get caretLeftButton() {
    return this.caretLeftCO.currentPath + '/ancestor-or-self::button[1]';
  }
  get navigationNumbers(){
    return this.navigator + '//div[contains(@class, "eui-table-paginator__page-navigation-numbers")]';
  }
  async hasNavigatorNumbers(){
    return await (await $(this.navigationNumbers)).isExisting();
  }
  get goToPageButtonCO(){
    return new ButtonComponent(this.navigationNumbers);
  }
  get pageRangeLabel(){
    return this.navigator + '//div[contains(@class, "eui-table-paginator__page-range")]';
  }
  async hasPageRangeLabel(){
    return await (await $(this.pageRange)).isExinsting();
  }
  get caretRightCO() {
    return new CoEuiIcon(this.navigatorItemButtonCO).byAttributeContains('iconclass','eui-icon-caret-right');
  }
  get caretRightButton() {
    return this.caretRightCO.currentPath + '/ancestor-or-self::button[1]';
  }
  get caretLastCO() {
    return new CoEuiIcon(this.navigatorItemButtonCO).byAttributeContains('iconclass','eui-icon-caret-last');
  }
  get caretLastButton() {
    return this.caretLastCO.currentPath + '/ancestor-or-self::button[1]';
  }
}


