import Component  from '../component.js'
import CoEuiList from './eui-list.js'
import { elementAttributeContains } from '../../core/utils.js'
import CoEuiButton from './eui-button.js'
import CoEuiIcon from './eui-icon.js'
import CoEuiLabel from './eui-label.js'
import CoEuiIconSvg from './eui-icon-svg.js'

export default class CoEuiListItem extends Component {
    constructor(parent) {
      let selector = '*[self::eui-list-item or @euilistitem]';
      super(parent, selector);
      //https://citnet.tech.ec.europa.eu/CITnet/stash/projects/CSDR/repos/eui/browse/packages/components/eui-list/eui-list-item/eui-list-item.component.html
    }
    get itemContainer() {
      return this.currentPath + '//div[contains(@class, "eui-list-item__container")]'; 
    }
    async hasSubmenu() {
      return await elementAttributeContains(this.itemContainer, 'class', 'eui-list-item--has-submenu');
    }
    //Content
    get itemContent() {
      return this.itemContainer + '//div[contains(@class, "eui-list-item__content")]';
    }
    get itemContentIcon() {
      return this.itemContent + '//div[contains(@class, "eui-list-item__content-icon")]';
    }
    get itemIconCO(){
      return new CoEuiIcon(this.itemContentIcon);
    }
    get itemContentText() {
      return this.itemContent + '//div[contains(@class, "eui-list-item__content-text")]';
    }
    get itemLabelCO() {
      return new CoEuiLabel(this.itemContentText);
    }
    async isDisabled() {
      return await elementAttributeContains(this.currentPath, 'class', 'eui-list-item--disabled');
    }
    get itemToggleCO() {
      return new CoEuiButton(this.itemContent).byAttributeContains('class','eui-list-item__content-toggle');
    }
    async isCollapsible() {
      return await (await this.itemToggleCO.element()).isExisting();
    }
    async isCollapsed(){
      return !await (await this.itemToggleCO.byAttributeContains('class', 'eui-list-item__content-toggle--expanded').element()).isExisting();
    }
    get itemToggleIconCO(){
      return new CoEuiIconSvg(this.itemToggleCO);
    }
    get itemSubList() {
      return this.itemContainer + '//div[contains(@class, "eui-list-item__sub-list")]';
    }
    get euiSubListCO() {
      return new CoEuiList(this.itemSubList);
    }
   
    async itemSeverity() {
      let cl = await (await $(this.currentPath)).getAttribute('class');
      if (cl.includes('primary')) {
        return 'primary';
      } else if(cl.includes('secondary')) {
        return 'secondary';
      } else if(cl.includes('info')) {
        return 'info';
      } else if(cl.includes('success')) {
        return 'success';
      } else if(cl.includes('warning')) {
        return 'warning';
      } else if(cl.includes('danger')) {
        return 'danger';
      } else if(cl.includes('accent')) {
        return 'accent';
      } else {
        throw new Error('Button does\'t have severity export default class or CO needs to be revised');
      }
    }
}


