import Component  from '../component.js'
import CoUxAlabel from './ux-a-label.js';

export default class CoUxWidget extends Component {
    constructor(parent) {
      let selector = 'ux-widget';
      super(parent, selector);
    }
    async isTile() {
      let cl = await(await $(this.widgetHeader)).getAttribute('class');
      if (cl.includes('c-ux-widget__header--tile')) {
         return true;
      } else if (cl === 'c-ux-widget__header') {
         return false;
      } else {
         throw new Error('ux-widget component object needs to be revised, ' +
         'header is missing class');
      }
    }
    get widgetHeader() {
      let path = '//header[contains(@class,"c-ux-widget__header")]';
      return this.currentPath + path;
    }
    async widgetHeaderTileLabel() {
      let path;
      if (await this.isTile()) {
         path = '//span[contains(@class,"c-ux-widget__header-tile-label")]';
      } else {
         path = '//ux-a-label';
      }
      return this.widgetHeader + path;
    }
    get widgetHeaderLabel() {
      return new CoUxAlabel(this.widgetHeader);
    }
    get widgetHeaderRightActions() {
      return this.widgetHeader + '//div[contains(@class,"c-ux-widget__right-actions")]';
    }
    get widgetHeaderRightActionsLink() {
      return this.widgetHeaderRightActions + '//span[@class="fa fa-cog"]';
    }
    get tileWidgetHeaderIcon() {
      let path = '//span[contains(@class,"c-ux-widget__header-tile-icon")]/i';
      return this.widgetHeader + path;
    }
    get tileWidgetHeaderSubLabel() {
      let path = '//div[contains(@class,"c-ux-widget__header-tile-sublabel")]';
      return this.widgetHeader + path;
    }
    get tileWidgetHeaderRightContentCounter() {
      let path = '//span[contains(@class,"c-ux-widget__header-tile-right-content--counter")]';
      return this.widgetHeader + path;
    }
    get tileWidgetHeaderButton() {
      let path = '//span[contains(@class,"c-ux-widget__header-tile-right-content--link")]/button';
      return this.widgetHeader + path;
    }
    get noTileWidgetBodyPlaceholder() {
      let path = '//div[contains(@class,"c-ux-widget__body")]';
      return this.currentPath + path;
    }
    get noTileWidgetFooterPlaceholder() {
      let path = '/following-sibling::div';
      return this.noTileWidgetBodyPlaceholder + path;
    }
}


