import DivComponent from '../../components/div.js';
import LabelComponent from '../../components/label.js';
import EcasBasePage from './ecas-base.js';

export default class EcasLoginPage extends EcasBasePage {
    /**
    * @type WebdriverIO.Element
    */
    get userInput() {
        return this.inputById(this.root, 'username');
    }
    /**
    * @type WebdriverIO.Element
    */
    get passwordInput() {
        return this.inputById(this.root, 'password');
    }
    /**
    * @type WebdriverIO.Element
    */
    get userSubmit() {
        let path = '//*[@name = "whoamiSubmit"]';
        return this.root + path
    }
    /**
    * @type WebdriverIO.Element
    */
    get passwordSubmit() {
        return this.inputByName(this.root, '_submit');
    }
    /**
    * @type WebdriverIO.Element
    */
    get signWithAnotherUserLink() {
        let path = '//form[@id="loginForm"]//a[@class="user-logout-link"]';
        return this.root + path;
    }
    /**
    * @type WebdriverIO.Element
    */
    get redirectProgressImage() {
        let path = '//img[starts-with(@src, "/cas/images/progressbar")]';
        return this.root + path;
    }
    /**
    * @type WebdriverIO.Element
    */
    get redirectFallbackLink() {
        let path = '//a[@id="fallbackLink"]';
        return this.root + path;
    }

    get informationMessage() {
        let path = '//p[contains(@id,"informationMessage")]';
        return this.root + path;
    }
    get login (){
        let path = '//a[contains(@href,"https://ecas.acceptance.ec.europa.eu/cas/login")]';
        return this.root + path;
    }

    get logout(){
        let path = '//a[contains(@href,"https://ecas.acceptance.ec.europa.eu/cas/logout")]';
        return this.root + path;
    }
    
    get chooseVerificationMethodCO() {
        return new LabelComponent(this.root).byTextContains('Choose your verification method');
    }
    get verificationMethodCO(){
        return new DivComponent(this.root).addPredicateAttributeContains('id', 'verif-method-dd-id');
    }
    get verificationMethodOpenCO(){
        return this.verificationMethodCO.addPredicateClassContains('open');
    }
    get verificationMethodTitleCO(){
        return new DivComponent(this.verificationMethodCO).addPredicateClassContains('verif-method-dd-placeholder__title');
    }
    verificationMethodTitleByTextCO(text){
        return this.verificationMethodTitleCO.byTextContains(text);
    }
    get verificationMethodPasswordCO(){
        return this.verificationMethodTitleByTextCO('Password');
    }
    get verificationMethodMobileCO(){
        return this.verificationMethodTitleByTextCO('Mobile');
    }
    verificationOptionByTextCO(option){
        return new DivComponent(this.verificationMethodCO).addPredicateClassContains('verif-method-dd-option__title').byTextContains(option);
    }
}


