import Component from '../../component.js'
import { elementAttributeContains } from '../../../core/utils.js'
import CoUxLayoutHorizontal from './ux-layout-horizontal.js'
import CoUxButton from './ux-button.js'
import ButtonComponent from '../../button.js'

export default class CoUxDynamicModal extends Component {
    constructor(parent) {
      let selector = 'ux-dynamic-modal';
      super(parent, selector);
      //https://citnet.tech.ec.europa.eu/CITnet/stash/projects/CSDR/repos/eui/browse/packages/components/src/lib/ux-components/ux-dynamic-modal/ux-dynamic-modal.component.html
    }
    get dataE2E() {
      let path = '//div[@data-e2e="ux-dynamic-modal"]';
      return this.currentPath + path;
    }
    async isSlideInDown() {
      return await elementAttributeContains(this.dataE2E, 'class', 'eui-u-anim--slideInDown');
    }
    async isMessageBox() {
      return 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');
    }
    get modalDialog() {
      let path = '//div[contains(@class,"ux-modal__dialog")]';
      return this.dataE2E + path;
    }
    get modalContent() {
      let path = '//div[contains(@class,"ux-modal__content")]';
      return this.modalDialog + path;
    }
    //There is isOverflowVisible() also in body
    async isOverflowVisibleContent() {
      return await elementAttributeContains(this.modalContent, 'class', 'ux-u-overflow-visible');
    }
    get modalHeader() {
      let path = '//div[contains(@class,"ux-modal__header")]';
      return this.modalContent + path;
    }
    async isCustomHeaderContent() {
      return await (await $(this.customModalHeaderPlaceholder)).isExisting();
    }
    get customModalHeaderPlaceholder() {
      let path = '//uxModalHeader';
      return this.modalHeader + path;
    }
    get modalHeaderTitle() {
      let path = '//h5[contains(@class,"ux-modal__header-title")]';
      return this.modalHeader + path;
    }
    get closeButton() {
      return new ButtonComponent(this.modalHeader).currentPath + '[contains(@class,"ux-modal__header-close")]';
    }
    get closeIcon() {
      let path = '//span[contains(@class,"eui-icon-close-m")]';
      return this.closeButton + path;
    }
    get modalBody() {
      let path = '//div[contains(@class,"ux-modal__body")]';
      return this.modalContent + path;
    }
    async hasNoBodyPadding() {
      return await elementAttributeContains(this.modalBody, 'class', 'ux-modal--no-padding');
    }
    async isBodyOverflowVisible() {
      return await elementAttributeContains(this.modalBody, 'class', 'ux-u-overflow-visible');
    }
    get modalBodyContent() {
      let path = '//span';
      return this.modalBody + path;
    }
    get messageBoxBody() {
      let path = '//div[contains(@class,"ux-message-box__body")]';
      return this.modalBody + path;
    }
    async isMessageBox() {
      return await (await $(this.messageBoxBody)).isExisting();
    }
    get messageBoxBodyIcon() {
      let path = '//div[contains(@class,"ux-message-box__body-icon")]';
      return this.messageBoxBody + path;
    }
    get messageBoxBodyContent() {
      let path = '//div[contains(@class,"ux-message-box__body-content")]';
      return this.messageBoxBody + path;
    }
    get messageBoxBodyContentSpan() {
      let path = '//span';
      return this.messageBoxBodyContent + path;
    }
    get modalFooter() {
      let path = '//div[contains(@class,"ux-modal__footer")]';
      return this.modalContent + path;
    }
    async isFooterVisible() {
      return await (await $(this.modalFooter)).isExisting();
    }
    async hasCustomFooterContent() {
      return await elementAttributeContains(this.modalFooter, 'class', 'ux-modal__footer--custom-alignment');
    }
    async isDynamicModalFooter() {
      return await (await $(this.dynamicModalFooter)).isExisting();
    }
    get dynamicModalFooter() {
      let path = '//uxDynamicModalFooter';
      return this.modalContent + path;
    }
    get modalFooterLayoutHorizontalCO() {
      return new CoUxLayoutHorizontal(this.dynamicModalFooter);
    }
    async hasCustomLeftBtn() {
      return await (await $(this.modalFooterLeftButtonCO.currentPath)).isExisting();
    }
    get modalFooterLeftButtonCO() {
      return new CoUxButton(this.modalFooterLayoutHorizontalCO.layoutHorizontalLeft);
    }
    async hasCustomRightBtn() {
      return await (await $(this.modalFooterRightButtonCO.currentPath)).isExisting();
    }
    get modalFooterRightButtonCO() {
      return new CoUxButton(this.modalFooterLayoutHorizontalCO.layoutHorizontalRight);
    }
    async isDynamicMessageBoxFooter() {
      return await (await $(this.dynamicMessageBoxFooter)).isExisting();
    }
    get dynamicMessageBoxFooter() {
      let path = '//uxDynamicMessageBoxFooter';
      return this.modalContent + path;
    }
    get messageBoxFooterLayoutHorizontalCO() {
      return new CoUxLayoutHorizontal(this.dynamicMessageBoxFooter);
    }
    async hasCustomMessageFooterContentLeft() {
      return await (await $(this.messageBoxFooterLeftButtonCO)).isExisting();
    }
    // ux-button used if customFooterContent
    get messageBoxFooterLeftButtonCO() {
      return new CoUxButton(this.messageBoxFooterLayoutHorizontalCO.layoutHorizontalLeft);
    }
    async hasCustomMessageFooterContentRight() {
      return await (await $(this.messageBoxFooterRightButtonCO)).isExisting();
    }
    // ux-button used if customFooterContent
    get messageBoxFooterRightButtonCO() {
      return new CoUxButton(this.messageBoxFooterLayoutHorizontalCO.layoutHorizontalRight);
    }
    // button used if !customFooterContent
    get footerSecondaryButtonCO() {
      return new ButtonComponent(this.modalFooter).byAttributeContains('class','ux-button--secondary');
    }
    async isShowActionIconsSecondaryButton() {
      return await elementAttributeContains(this.footerSecondaryButtonCO, 'class', 'ux-button--with-label');
    }
    async isDismissActionDisabled(){
      return await (await $(this.footerSecondaryButtonCO)).getAttribute('disabled');
    }
    get footerSecondaryButtonIcon() {
      return this.footerSecondaryButtonCO().buttonIcon;
    }
    // button used if !customFooterContent
    get footerPrimaryButtonCO() {
      return new ButtonComponent(this.modalFooter).byAttributeContains('class','ux-button--primary');
    }
    async isShowActionIconsPrimaryButton() {
      return await elementAttributeContains(this.footerPrimaryButtonCO, 'class', 'ux-button--with-label');
    }
    get acceptActionDisabled(){
      return this.footerPrimaryButtonCO().buttonDisabled;
    }
    get footerPrimaryButtonIcon() {
      return this.footerPrimaryButtonCO().buttonIcon;
    }
    get modalBackdrop() {
      let path = '//div[contains(@class,"modal-backdrop show")]';
      return this.currentPath + path;
    }
}


