import Component  from '../component.js'
import CoUxAlabel from '../7x/ux-a-label.js'
import CoUxAtag from '../7x/ux-a-tag.js'
import { elementAttributeContains } from '../../core/utils.js'
import ButtonComponent from '../button.js'

export default class CoUxPanel extends Component {
    constructor(parent) {
      let selector = 'ux-panel';
      super(parent, selector);
      // 7x https://webgate.ec.europa.eu/CITnet/stash/projects/CSDR/repos/eui/browse/packages/core/src/lib/commons/ux-components/ux-panel/ux-panel.component.html
    }
    get dataE2E() {
      let path = '//div[@data-e2e = "ux-panel"]';
      return this.currentPath + path;
    }
    async isCollapsible() {
      return await elementAttributeContains(this.dataE2E, 'class', 'ux-panel--is-collapsible');
    }
    get toggleButton() {
      let path = '//div[contains(@class,"ux-panel__collapsible-button")]';
      return this.dataE2E + path;
    }
    async isCollapsed() {
      return await elementAttributeContains(this.toggleButton, 'class', 'ux-panel__collapsible-button--collapsed');
    }
     get toggleButtonIcon() {
      let path = '//*[contains(@class,"ux-icon")]';
      return this.toggleButton + path;
    }
    get panelItem() {
      let path = '//div[contains(@class,"ux-panel-item")]';
      return this.dataE2E + path;
    }
    async isVisible() {
      return await (await $(this.panelItem)).isExisting();
    }
    get statusIndicatorWrapper() {
      let path = '//div[contains(@class,"ux-panel-item__status-indicator-icon-wrapper")]';
      return this.panelItem + path;
    }
    get statusIndicatorIconWrapper() {
      let path = '//div[contains(@class,"ux-panel-item__status-indicator-icon-wrapper-icon")]';
      return this.panelItem + path;
    }
    async hasStatusIndicator() {
      return await (await $(this.statusIndicatorWrapper)).isExisting();
    }
    async hasStatusIndicatorHeaderIcon() {
      return await (await $(this.statusIndicatorIconWrapper)).isExisting();
    }
    get panelHeader() {
      let path = '//div[contains(@class,"ux-panel-header")]';
      return this.panelItem + path;
    }
    get panelHeaderPlaceholder() {
      let path = '//uxPanelHeader';
      return this.panelItem + path;
    }
    async hasCustonPanelHeader() {
      return await (await $(this.panelHeaderPlaceholder)).isExisting();
    }
    // used for paneleHeader, customPanelHeader and panelHeaderWithDescendants
    async isAccordionExpanded() {
      return await elementAttributeContains(this.panelHeader, 'class', 'ux-panel-header--accordion-expanded');
    }
    async isExpandable() {
      return await elementAttributeContains(this.panelHeader, 'class', 'ux-panel-header--expandable');
    }
    get panelHeaderExpandToggleIcon() {
      let path = '//div[contains(@class,"ux-panel-header__expand-toggle ux-icon")]';
      return this.panelHeaderPlaceholder + path;
    }
    async isExpanded() {
      return await elementAttributeContains(this.panelHeader, 'aria-expanded', 'true');
    }
    get panelHeaderWithDescendantsPlaceholder() {
      let path = '//uxPanelHeaderWithDescendants';
      return this.panelItem + path;
    }
    async hasCustonPanelHeaderWithDescendants() {
      return await (await $(this.panelHeaderWithDescendantsPlaceholder)).isExisting();
    }
    async hasPanelHeader() {
      return await (await $(this.panelHeader)).isExisting();
    }
    get labelCO(){
      return  new CoUxAlabel(this.panelHeader);
    }
    get panelRightContentPlaceholder() {
      let path = '//*[contains(@class,"ux-panel-header__right-content")]';
      return this.panelHeader + path;
    }
    get panelRightContentPlaceholder() {
      let path = '//uxPanelHeaderRightContent';
      return this.panelHeader + path;
    }
    async hasCustomPanelHeaderRightContent() {
      return await (await $(this.panelRightContentPlaceholder)).isExisting();
    }
    get panelRightContentWithDescendantsPlaceholder() {
      let path = '//uxPanelHeaderRightContentWithDescendants';
      return this.panelHeader + path;
    }
    async hasCustomPanelHeaderRightContentWithDescendants() {
      return await (await $(this.panelRightContentWithDescendantsPlaceholder)).isExisting();
    }
    get tagCO(){
      return  new CoUxAtag(this.panelHeaderRightContent);
    }
    async hasTag() {
      return await (await $(this.tagCO.currentPath)).isExisting();
    }
    get panelHeaderRightContentExpandToggleIcon() {
      let path = '//span[contains(@class,"ux-panel-header__expand-toggle ux-icon")]';
      return this.panelHeaderRightContent + path;
    }
    async isExpandedRightContentExpandToggleIcon() {
      return await (await $(this.panelHeaderRightContentExpandToggleIcon + '/self::span[contains(@class, "ux-icon-angle-down")]')).isExisting();
    }
    get panelSubHeaderPlaceholder() {
      let path = '//div[contains(@class,"ux-panel-header__sub-header")]';
      return this.panelItem + path;
    }
    async hasCustomSubHeaderContent() {
      return await (await $(this.panelSubHeaderPlaceholder)).isExisting();
    }
    get indicatorWrapperPlaceholder() {
      let path = '//div[contains(@class,"ux-panel-header__status-indicator-wrapper")]';
      return this.panelItem + path;
    }
    async hasStatusIndicator() {
      return await (await $(this.indicatorWrapperPlaceholder)).isExisting();
    }
    get indicatorWrapperLabelPlaceholder() {
      let path = '//span[contains(@class,"ux-panel-header__status-indicator-wrapper-label")]';
      return this.indicatorWrapperPlaceholder + path;
    }
    get indicatorWrapperToggle() {
      let path = '//a[contains(@class,"ux-panel-header__status-indicator-wrapper-toggle")]';
      return this.indicatorWrapperPlaceholder + path;
    }
    async isTogglableStatusIndicatorContent() {
      return await (await $(this.indicatorWrapperToggle)).isExisting();
    }
    get indicatorWrapperIcon() {
      let path = '//span[contains(@class,"ux-icon")]';
      return this.indicatorWrapperToggle + path;
    }
    get indicatorContentPlaceholder() {
      let path = '//*[contains(@class,"ux-panel-header__status-indicator-content")]';
      return this.dataE2E + path;
    }
    async isStatusIndicatorContentExpanded() {
      return await (await $(this.indicatorContentPlaceholder)).isExisting();
    }
    get panelContent() {
      let path = '//div[contains(@class,"ux-panel-content")]';
      return this.panelItem + path;
    }
    async isHidden() {
      return await (await $(this.panelContent + '/self::div[@hidden]')).isExisting();
    }
    get contentBlockedOverlay() {
      let path = '//div[contains(@class,"ux-panel-content__blocked-overlay")]';
      return this.panelContent + path;
    }
    async isBlocked() {
      return await (await $(this.contentBlockedOverlay)).isExisting();
    }
    get customPanelFooterPlaceholder() {
      let path = '//uxPanelFooter';
      return this.dataE2E + path;
    }
    async hasCustomPanelFooter() {
      return await (await $(this.customPanelFooterPlaceholder)).isExisting();
    }
    get panelFooterDiv() {
      let path = '//div[contains(@class,"ux-panel-footer")]';
      return this.dataE2E + path;
    }
    // used for customPanelFooter and customPanelFooterWithDescendantsPlaceholder
    async isLargeFooter() {
      return await elementAttributeContains(this.panelFooterDiv, 'class', 'ux-panel-footer--large');
    }
    get customPanelFooterWithDescendantsPlaceholder() {
      let path = '//uxPanelFooterWithDescendants';
      return this.dataE2E + path;
    }
    async hasCustomPanelFooterWithDescendants() {
      return await (await $(this.customPanelFooterWithDescendantsPlaceholder)).isExisting();
    }
    get footerContentCenter() {
      let path = '//div[contains(@class,"ux-panel-footer")]';
      return this.dataE2E + path;
    }
    get footerButtonCO() {
      return new ButtonComponent(this.footerContentCenter).byAttributeContains('class','ux-button--secondary');
    }
    async footerButtonSpan() {
      return await this.footerButtonCO.span();
    }
    async isActualMaxHeightNone() {
      return await (await $(this.footerButtonSpan + '/self::span[contains(text(),"show less")]')).isExisting();
    }
    async primaryFooterButtonCO() {
      return new ButtonComponent(this.footerContentCenter).byAttributeContains('class','ux-button--primary');
    }
}


