import Component  from '../component.js'
import { elementAttributeContains } from '../../core/utils.js'

export default class CoEuiTabItem extends Component {
    constructor(parent) {
      let selector = 'div[contains(@class, "eui-tab-item") and contains(@role, "tab") and not(contains(@class, "eui-tab-item__label"))]' ;
      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=support/13.x
    }
    async isClosable() {
      return await elementAttributeContains(this.currentPath, 'class', 'eui-tab-item--closable');
    }
    async isActive() {
      return await elementAttributeContains(this.currentPath, 'class', 'eui-tab-item--active');
    }
    async isDisabled() {
      return await elementAttributeContains(this.currentPath, 'class', 'eui-tab-item--disabled');
    }
    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 hasBackgroundFilled() {
      return await elementAttributeContains(this.currentPath, 'class', 'eui-tab-item--background-filled');
    }
    get label() {
      let path = '//div[contains(@class, "eui-tab-item__label")]';
      return this.currentPath + path;
    }
    get closeIcon() {
      let path = '//span[contains(@class, "eui-tab__close-icon")]';
      return this.currentPath + path;
    }
    async hasCloseIcon() {
      return await (await $(this.closeIcon)).isExisting();
    }
}


