import Component  from '../component.js'
import CoUxButton from '../7x/ux-button.js'

export default class CoUxDynamicModal extends Component {

    constructor(parent) {
      let selector = 'ux-dynamic-modal';
      super(parent, selector);
    }
    async isMessageBox() {
      let cl = await (await this.element()).getAttribute('class');
      if (cl.includes('flipInY')) {
         return true;
      } else if (cl.includes('slideInDown')) {
         return false;
      } else {
         throw new Error('Ux Dynamic Modal component object needs to be revised, ' +
            'root is missing a class');
      }
    }
    /**
    * @type WebdriverIO.Element
    */
    get modalDialog() {
      let path = '//div[contains(@class,"ux-modal__dialog")]';
      return this.currentPath + path;
    }
    /**
    * @type WebdriverIO.Element
    */
    get modalContent() {
      let path = '//div[contains(@class,"ux-modal__content")]';
      return this.modalDialog + path;
    }
    /**
    * @type WebdriverIO.Element
    */
    get modalHeader() {
      let path = '//div[contains(@class,"ux-modal__header")]';
      return this.modalContent + path;
    }
    /**
    * @type WebdriverIO.Element
    */
    get modalHeaderTitle() {
      let path = '//*[contains(@class,"ux-modal__header-title")]';
      return this.modalHeader + path;
    }
    /**
    * @type WebdriverIO.Element
    */
    get closeButton() {
      let path = '//button[contains(@class,"ux-modal__header-close")]';
      return this.modalHeader + path;
    }
    /**
    * @type WebdriverIO.Element
    */
    get modalBody() {
      let path = '//div[contains(@class,"ux-modal__body")]';
      return this.modalContent + path;
    }
    /**
    * @type WebdriverIO.Element
    */
    get modalBoxBody() {
      let path = '//div[contains(@class,"ux-message-box__body")]';
      return this.modalBody + path;
    }
    /**
    * @type WebdriverIO.Element
    */
    get modalBoxBodyIcon() {
      let path = '//div[contains(@class,"ux-message-box__body-icon")]';
      return this.modalBoxBody + path;
    }
    /**
    * @type WebdriverIO.Element
    */
    get modalBoxBodyContent() {
      let path = '//div[contains(@class,"ux-message-box__body-content")]';
      return this.modalBoxBody + path;
    }
    /**
    * @type WebdriverIO.Element
    */
    get modalFooter() {
      let path = '//div[contains(@class,"ux-modal__footer")]';
      return this.modalContent + path;
    }
    /**
    * @type WebdriverIO.Element
    */
    get modalFooterLayoutHorizontalCO() {
      return new CoUxLayoutHorizontal(this.modalFooter);
    }
    /**
    * @type CoUxButton
    */
    modalFooterLeftButtonCO(text) {
      return new CoUxButton(this.modalFooterLayoutHorizontalCO.layoutHorizontalLeft).componentByText(text);
    }
    /**
    * @type CoUxButton
    */
    modalFooterRightButtonCO(text) {
      return new CoUxButton(this.modalFooterLayoutHorizontalCO.layoutHorizontalRight).componentByText(text);
    }
    /**
    * @type WebdriverIO.Element
    */
    get footerPrimaryBtn() {
      let path = '//button[contains(@class,"btn-primary")]';
      return this.modalFooter + path;
    }
    /**
    * @type WebdriverIO.Element
    */
    get footerSecondaryBtn() {
      let path = '//button[contains(@class,"btn-secondary")]';
      return this.modalFooter + path;
    }
    /**
    * @type WebdriverIO.Element
    */
    get modalBackdrop() {
      let path = '/ancestor::ux-dynamic-modal[1]//div[contains(@class,"modal-backdrop")]';
      return this.currentPath + path;
    }

    byId(id)  {
      this.currentPath = this.parent + '//' + this.selector + '//div[@data-e2e="ux-dynamic-modal" and @id="' + id + '"]/ancestor::' + this.selector + '[1]';
      return this;
    }
}


