'use strict';

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

function SentimentMemoryAnnotationsUser(opts) {
    opts = opts || {};
    User.call(this, opts);
}

SentimentMemoryAnnotationsUser.prototype = new User();

SentimentMemoryAnnotationsUser.prototype.goToSentimentMemoryAnnotations = 
    function () {
	return this.goTo('/sentiment-memory-annotations')
	    .then(function () {
		return browser.sleep(1 * 1000);
	    });
    };

SentimentMemoryAnnotationsUser.prototype.countNumberOfAnnotations = 
    function () {
	return this.browser.element
	    .all(by.css('.w-term'))
	    .filter(function(element){
		return element.isDisplayed();
	    })
	    .count();
    };

SentimentMemoryAnnotationsUser.prototype.clickOnNextPage = function() {
    return this.browser.element(by.css('.w-go-to-next-page')).click();
};

SentimentMemoryAnnotationsUser.prototype.clickOnNumberReviews = function () {
    return this.browser.element(by.css('.w-reviews')).click();
};

SentimentMemoryAnnotationsUser.prototype.seeStatusAnnotations = function () {
    return this.browser.element
	.all(by.css('.w-active'))
	.map(function (element) {
	    return element.getAttribute('class').then(function (attrClass) {
		var value = "";

		if (attrClass.indexOf('w-new') > -1) {
		    value = 'w-new';
		} else if (attrClass.indexOf('w-archived') > -1) {
		    value = 'w-archived';
		} else {
		    value = 'w-accepted';
		}

		return value;
	    });
	});
};

SentimentMemoryAnnotationsUser.prototype.selectStatus = function (status) {
    return this.browser.element(by.css('.w-sel-' + status)).click();
};

SentimentMemoryAnnotationsUser.prototype.openCategory = function () {
    return this.browser
	.element(by.css('.w-open-product-filter-component-ui'))
	.click();
};

SentimentMemoryAnnotationsUser.prototype.selectFirstCategory = function () {
    return this.browser
	.element(by.css('.w-product-human-id a'))
	.click();
};

SentimentMemoryAnnotationsUser.prototype.readCategorySelected = function () {
    return this.browser
	.element(by.css('.w-selected-product'))
	.getText().then(function (text) {
	    return text.toLowerCase();
	});
};

SentimentMemoryAnnotationsUser.prototype.seeCategoriesAnnotation = function () {
    return this.browser.element
	.all(by.css('.w-category'))
	.map(function (element) {
	    return element.getText().then(function (text) {
		return text.toLowerCase();
	    });
	});
};

SentimentMemoryAnnotationsUser.prototype.showScreen = function () {
    return this.takeScreenshot();
};

SentimentMemoryAnnotationsUser.prototype.whereIAm = function () {
    return this.browser.getCurrentUrl();
};

module.exports = SentimentMemoryAnnotationsUser;

