import Component from '../component.js';
import DivComponent from '../div.js';
import CoEuiIconSvg from './eui-icon-svg.js';
import CoEuiButton from './eui-button.js';

export default class CoEuiTabsItem extends Component {
    constructor(parent) {
      let selector = 'div[contains(@class, "eui-tab-item")][@tabindex]';
      super(parent, selector);
      //https://citnet.tech.ec.europa.eu/CITnet/stash/projects/CSDR/repos/eui/browse/packages/components/eui-tabs/eui-tabs.component.html?at=master
    }
    async isClosable() {
      return await (await $(this.currentPath + '/self::*[contains(@class,"eui-tab-item--closable")]')).isExisting();
    }
    async isActive() {
      return await (await $(this.currentPath + '/self::*[contains(@class,"eui-tab-item--active")]')).isExisting();
    }
    async isDisabled() {
      return await (await $(this.currentPath + '/self::*[contains(@class,"eui-tab-item--disabled")]')).isExisting();
    }
    async severity() {
      let cl = await (await $(this.currentPath)).getAttribute('class');
      if(await cl.includes('eui-tab-item--secondary')) {
        return 'secondary';
      } else if(await cl.includes('eui-tab-item--primary')) {
        return 'primary';
      } else if(await cl.includes('eui-tab-item--info')) {
        return 'info';
      } else if(await cl.includes('eui-tab-item--success')) {
        return 'success';
      } else if(await cl.includes('eui-tab-item--warning')) {
        return 'warning';
      } else if(await cl.includes('eui-tab-item--danger')) {
        return 'danger';
      } else if(await cl.includes('eui-tab-item--accent')) {
        return 'accent';
      } else {
        return 'Tab item doesn\'t have any sevevrity or component needs to be revised';
      }
    }
    async isBackgroundFilled() {
      return await (await $(this.currentPath + '/self::*[contains(@class,"eui-tab-item--background-filled")]')).isExisting();
    }
    get labelCO() {
      return new DivComponent(this.currentPath).addPredicateClassContains('eui-tab-item__label');
    }
    get closeButtonCO() {
      return new CoEuiButton(this.currentPath).byClassContains('eui-u-ml-s');
    }
    get closeIconCO() {
      return new CoEuiIconSvg(this.closeButtonCO).byClassContains('eui-tab__close-icon');
    }
}

