'use strict';

var env = require('../../lib/env');
var User = require('../../lib/user');

function AnnotatingUser(opts) {
    User.call(this, opts);
}
AnnotatingUser.prototype = new User();
AnnotatingUser.prototype.goToAnnotationPage = function() {
    var self=this;
    return this.goTo('/reviews').then(function() {
        return self.wait(5);
    });
};
AnnotatingUser.prototype.chooseProductToAnalyzeByIndex = function(index) {
    return element(by.css('.w-toggle-product-list-to-analyze')).click()
        .then(function() {
            return element.all(by.css('.w-product-name-to-analyze')).get(index).click();
        });
};
AnnotatingUser.prototype.countAutomaticAnnotations=function(){
        var self=this;
        return element
            .all(by.css('.annotation-list-item .fa-cogs'))
            // .map(function(e){
            //     return self.waitForVisibleElement(e)
            //         .then(function(){
            //             return e;
            //         });
            // })
            .filter(function(e){
                return e.isDisplayed();
            })
            .count();
};
AnnotatingUser.prototype.createAnnotation = function() {
    var selectedText = 'It';
    var listItem;
    var self = this;

    var paragraph = element(by.css('.BVRRReviewTextFirstParagraph'));
    return browser.actions().mouseMove(paragraph, {
            x: 0,
            y: 0
        }).doubleClick().perform().then(function() {
            return browser.sleep(5000);
        }).then(function() {
            return self.takeScreenshot('selected-text');
        }).then(function() {
            return element(by.id('w-list-view-tab')).click();
        }).then(function() {
            return browser.sleep(2 * 1000);
        }).then(function() {
            listItem = element(by.css('.tag-list-view-item'));
            return browser.actions().mouseMove(listItem, {
                x: 10,
                y: 10
            }).perform();
        }).then(function() {
            browser.sleep(1000);
            return listItem.element(by.css('.add-sentiment-list .positive-sentiment')).click();
        }).then(function() {
            return browser.sleep(2000);
        }).then(function() {
            element(by.css('.w-aspect-expression')).sendKeys(selectedText);
            return browser.sleep(2000);
        })
        .then(function() {
            return self.takeScreenshot('after-adding-text-to-aspect');
        })
        .then(function() {
            return listItem.element(by.css('.w-add-synonym-button')).click();
        });
};
module.exports = AnnotatingUser;