import Component  from '../component.js'

export default class CoUxLayoutSidebarItem extends Component {
    constructor(parent) {
      let selector = 'ux-layout-sidebar-item';
      super(parent, selector);
    }
    get link() {
      let path = '/a';
      return this.currentPath + path;
    }
    get linkHref() {
      let path = '@href';
      return this.link + path;
    }
    get sidebarItemHeader() {
      let path = '//div[contains(@class,"sidebar-item__header")]';
      return this.currentPath + path;
    }
    get sidebarItemHeaderIconWrapper() {
      let path = '//div[contains(@class,"sidebar-item__header-icon-wrapper")]';
      return this.sidebarItemHeader + path;
    }
    get sidebarItemHeaderIconWrapperIconClass() {
      let path = '//span[contains(@class,"sidebar-item__header-icon-wrapper-icon")]@class';
      return this.sidebarItemHeaderIconWrapper + path;
    }
    get sidebarItemHeaderLabelWrapper() {
      let path = '//div[contains(@class,"sidebar-item__header-label-wrapper")]';
      return this.sidebarItemHeader + path;
    }

    get sidebarItemHeaderLabelWrapperLabel() {
      let path = '//div[contains(@class,"sidebar-item__header-label-wrapper-label")]';
      return this.sidebarItemHeaderLabelWrapper + path;
    }

    get sidebarItemHeaderLabelWrapperSubLabel() {
      let path = '//div[contains(@class,"sidebar-item__header-label-wrapper-sub-label")]';
      return this.sidebarItemHeaderLabelWrapper + path;
    }
    get sidebarItemHeaderExpandToggle() {
      let path = '//div[contains(@class,"sidebar-item__header-expand-toggle")]';
      return this.sidebarItemHeader + path;
    }
    async hasSub() {
      return await (await $(this.sidebarItemHeaderExpandToggle)).isExisting();
    }
    get sidebarItemHeaderExpandToggleIcon() {
      let path = '//span[contains(@class,"ux-icon")]';
      return this.sidebarItemHeader + path;
    }
    async isExpanded() {
      let cl = await (await $(this.sidebarItemHeaderExpandToggleIcon)).getAttribute('class');
      if (cl.includes('ux-icon-angle-down')) {
         return true;
      } else if (cl.includes('ux-icon-angle-right')) {
         return false;
      } else {
         throw new Error('ux-layout-sidebar-item component object needs to be revised, ' +
         'SidebarItemHeaderExpandToggleIcon is missing class');
      }
    }
}


