import Component from '../../component.js'
import { elementAttributeContains } from '../../../core/utils.js'
import CoUxButton from './ux-button.js'
import CoUxTreeNodeBadge from './ux-tree-node-badge.js'

export default class CoUxTreeNode extends Component {

    constructor(parent) {
      let selector = 'ux-tree-node';
      super(parent, selector);
      //https://citnet.tech.ec.europa.eu/CITnet/stash/projects/CSDR/repos/eui/browse/packages/components/src/lib/ux-components/ux-tree/ux-tree.component.html
    }

    get dataE2E() {
      return this.currentPath + '//li[@data-e2e="ux-tree-node"]';
    }
    async isFirst() {
      return await elementAttributeContains(this.dataE2E, 'class', 'first-child');
    }
    async isLast() {
      return await elementAttributeContains(this.dataE2E, 'class', 'last-child');
    }
    async isNodeExpandable() {
      return await elementAttributeContains(this.dataE2E, 'class', 'ux-tree__node--expandable');
    }
    get treeNodeWrapper() {
      let path = '//div[contains(@class,"ux-tree__node-wrapper")]';
      return this.dataE2E + path;
    }
    async isSelected() {
      return await elementAttributeContains(this.treeNodeWrapper, 'class', 'ux-tree__node--selected');
    }
    get nodeToggleButtonCO() {
      return new CoUxButton(this.treeNodeWrapper);
    }
    get multiselectSpan () {
      let path = '//span';
      return this.treeNodeWrapper + path;
    }
    get multiselectCheckbox() {
      let path = '//input[contains(@class,"ux-input__checkbox")]';
      return this.multiselectSpan + path;
    }
    async isMultiselect() {
      return await (await $(this.multiselectCheckbox)).isExisting();
    }
    get multiselectCheckboxLabel () {
      let path = '//label[contains(@class,"ux-tree__node-checkbox-label")]';
      return this.multiselectSpan + path;
    }
    get customContent() {
      let path = '//div[contains(@class,"ux-tree__custom-content")]';
      return this.treeNodeWrapper + path;
    }
    async hasCustomContent() {
      return await (await $(this.customContent)).isExisting();
    }
    get typeLabel() {
      let path = '//span[contains(@class,"ux-tree__node-type")]';
      return this.treeNodeWrapper + path;
    }
    async hasTypeLabel() {
      return await (await $(this.typeLabel)).isExisting();
    }
    async isNodeTypeParent() {
      return await elementAttributeContains(this.typeLabel, 'class', 'ux-tree__node-type-parent');
    }
    get nodeIcon() {
      let path = '//span[contains(@class,"ux-tree__node-icon")]';
      return this.treeNodeWrapper + path;
    }
    get nodeIconSpan() {
      let path = '//span';
      return this.nodeIcon + path;
    }
    get nodeLabelWrapped() {
      let path = '//div[contains(@class,"ux-tree__node-label-wrapped")]';
      return this.treeNodeWrapper + path;
    }
    get nodeLabelWrappedSpan() {
      let path = '//span';
      return this.nodeLabelWrapped + path;
    }
    get nodeLabelWrappedSpanLabel() {
      let path = '//span';
      return this.nodeLabelWrappedSpan + path;
    }
    get nodeLabelWrappedSpanUrlExternal() {
      let path = '//span[contains(@class,"eui-u-text-link-external")]';
      return this.nodeLabelWrappedSpan + path;
    }
    get nodeLabelSpan() {
      let path = '//span[contains(@class,"ux-tree__node-label")]';
      return this.treeNodeWrapper + path;
    }
    async isNodeLabelParent() {
      return await (await $(this.nodeLabelSpan + '/self::span[contains(@class,"ux-tree__node-type-parent")]')).isExisting();
    }
    async isNodeHighlighted() {
      return await (await $(this.treeNodeWrapper + '//span[contains(@class,"ux-tree__node-label--highlighted")]')).isExisting();
    }
    async isNodeDisabled() {
      return await (await $(this.treeNodeWrapper + '//span[contains(@class,"text-muted")]')).isExisting();
    }
    get nodeLabelSpanLabel() {
      let path = '//span';
      return this.nodeLabelSpan + path;
    }
    get nodeLabelUrlExternal() {
      let path = '//span[contains(@class,"eui-u-text-link-external")]';
      return this.nodeLabelSpan + path;
    }
    get NodeBadges() {
      let path = '//div[contains(@class,"ml-auto")]';
      return this.treeNodeWrapper + path;
    }
    async hasBadges() {
      return await (await $(this.NodeBadges)).isExisting();
    }
    get nodeBadgeCO() {
      return new CoUxTreeNodeBadge(this.NodeBadges);
    }
    get nodeWrapperMetacontentToggle() {
      let path = '//span[contains(@class,"ux-tree__node-metacontent-toggle")]';
      return this.treeNodeWrapper + path;
    }
    async hasNodeWrappedMetadata() {
      return await (await $(this.nodeWrapperMetacontentToggle)).isExisting();
    }
    get nodeMetacontentToggleIcon() {
      let path = '//span[contains(@class,"eui-icon")]';
      return this.nodeWrapperMetacontentToggle + path;
    }
    async hasChildren() {
      return await this.isNodeExpandable();
    }
    get treeNodesList() {
      let path = '//ul[contains(@class,"ux-tree__nodes")]';
      return this.dataE2E + path;
    }
    async isNodeExpanded() {
      return await (await $(this.treeNodesList)).isExisting();
    }
    get coUxTreeNode() {
      return new CoUxTreeNode(this.treeNodesList);
    }
    async hasNodeMetadata() {
      return await (await $(this.nodeWrapperMetacontentToggle)).isExisting();
    }
    get treeNodesMetacontent() {
      let path = '//div[contains(@class,"ux-tree__node-metacontent")]';
      return this.treeNodeWrapper + path;
    }
}


