import Component from '../../component.js'
import { elementAttributeContains } from '../../../core/utils.js'
import ButtonComponent from '../../button.js'

export default class CoUxModal extends Component {
    constructor(parent) {
      let selector = 'ux-modal';
      super(parent, selector);
           // https://citnet.tech.ec.europa.eu/CITnet/stash/projects/CSDR/repos/eui/browse/packages/components/src/lib/ux-components/ux-modal/ux-modal.component.ts
    }
    get dataE2E() {
      let path = '//div[@data-e2e="ux-modal"]';
      return this.currentPath + path;
    }
    async isModalOpen() {
      return await elementAttributeContains(this.dataE2E, 'class', 'show');
    }
    async isMessageBox() {
      return await (await elementAttributeContains(this.dataE2E, 'class', 'eui-u-anim--medium') || await elementAttributeContains(this.dataE2E, 'class', 'eui-u-anim--flipInY'));
    }
    async isSizeFullHeight() {
      return await elementAttributeContains(this.dataE2E, 'class', 'ux-modal--full-height');
    }
    async isSizeMediumHeight() {
      return await elementAttributeContains(this.dataE2E, 'class', 'ux-modal--medium-height');
    }
    async isDraggable() {
      return await elementAttributeContains(this.dataE2E, 'class', 'ux-modal--draggable');
    }
    async isModalHidden() {
      return await (await $(this.dataE2E)).getAttribute('aria-hidden');
    }
    get dialog() {
      let path = '//div[contains(@class,"ux-modal__dialog")]';
      return this.dataE2E + path;
    }
    get content() {
      let path = '//div[contains(@class,"ux-modal__content")]';
      return this.dialog + path;
    }
    get header() {
      let path = '//div[contains(@class,"ux-modal__header")]';
      return this.content + path;
    }
    get headerPlaceholder() {
      let path = '//uxmodalheader';
      return this.header + path;
    }
    get headerTitle() {
      let path = '//div[contains(@class,"ux-modal__header-title")]';
      return this.header + path;
    }
    async titleLabel() {
      return await (await $(this.headerTitle)).getText();
    }
    get closeBtn() {
      return new ButtonComponent(this.header).byAttributeContains('class','ux-modal__header-close').currentPath;
    }
    get showCloseButton() {
      return new ButtonComponent(this.header).byAttributeContains('class','disabled').currentPath;
    }
    async isShowCloseButton() {
      return !(await (await $(this.showCloseButton)).isExisting());
    }
    get body() {
      let path = '//div[contains(@class,"ux-modal__body")]';
      return this.content + path;
    }
    get bodyPlaceholder() {
      let path = '//uxmodalbody';
      return this.body + path;
    }
    get noPadding() {
      let path = '/self::div[contains(@class,"ux-modal--no-padding")]';
      return this.body + path;
    }
    get overflowVisible() {
      let path = '/self::div[contains(@class,"ux-u-overflow-visible")]';
      return this.body + path;
    }
    async hasNoBodyPadding() {
      return  await (await $(this.noPadding)).isExisting();
    }
    async isOverflowVisible() {
      return  await (await $(this.overflowVisible)).isExisting();
    }
    async isFooterVisible() {
      return  await (await $(this.footer)).isExisting();
    }
    get footer() {
      let path = '//div[contains(@class, "ux-modal__footer")]';
      return this.content + path;
    }
    get footerCustomAlignment() {
      let path = '//div[contains(@class, "ux-modal__footer--custom-alignment")]';
      return this.content + path;
    }
    async isFooterCustomAlignment() {
      return await (await $(this.footerCustomAlignment)).isExisting();
    }
    get footerContentPlaceholder() {
      let path = '//uxmodalfooter';
      return this.content + path;
    }
    get secondaryButtonCO() {
      return new ButtonComponent(this.footer).byAttributeContains('class','ux-button--secondary');
    }
    get footerDismissActionBtn() {
      return this.secondaryButtonCO.currentPath;
    }
    async isDismissActionVisible() {
      return await (await $(this.footerDismissActionBtn)).isExisting();
    }
    get primaryButtonCO() {
      return new ButtonComponent(this.footer).byAttributeContains('class','ux-button--primary');
    }
    get footerAcceptActionBtn() {
      return this.primaryButtonCO.currentPath;
    }
    async isAcceptActionVisible() {
      return await(await $(this.footerAcceptActionBtn)).isExisting();
    }
    get buttonWithLabel() {
      return new ButtonComponent(this.footer).byAttributeContains('class','ux-button--with-label').currentPath;
    }
    async isShowActionIcons() {
      return await (await $(this.buttonWithLabel)).isExisting();
    }
    async isDismissActionDisabled() {
      return await (await $(this.footerDismissActionBtn)).getAttribute('disabled');
    }
    async isAcceptActionDisabled() {
      return await (await $(this.footerAcceptActionBtn)).getAttribute('disabled');
    }
    get buttonIcon() {
      let path = '//button/span[contains(@class, "ux-button__icon")]';
      return this.footer + path;
    }
    get modalBackdrop() {
      let path = '//div[contains(@class, "modal-backdrop")]';
      return this.currentPath + path;
    }
    async isModalOpenModalBackdrop() {
      return await elementAttributeContains(this.modalBackdrop, 'class', 'show');
    }
    async dismissActionLabel() {
      return await (await $(this.currentPath)).getAttribute('dismissactionlabel');
    }
    async acceptActionLabel() {
      return await (await $(this.currentPath)).getAttribute('acceptactionlabel');
    }
    async isSizeSmall() {
      return await elementAttributeContains(this.dataE2E, 'class', 'ux-modal--small');
    }
    async isSizeLarge() {
      return await elementAttributeContains(this.dataE2E, 'class', 'ux-modal--large');
    }
    async isFullScreen() {
      return await elementAttributeContains(this.dataE2E, 'class', 'ux-modal--full-screen');
    }
}


