import { element, by, ElementFinder } from 'protractor';

export class LikesComponentsPage {
  createButton = element(by.id('jh-create-entity'));
  deleteButtons = element.all(by.css('jhi-likes div table .btn-danger'));
  title = element.all(by.css('jhi-likes div h2#page-heading span')).first();
  noResult = element(by.id('no-result'));
  entities = element(by.id('entities'));

  async clickOnCreateButton(): Promise<void> {
    await this.createButton.click();
  }

  async clickOnLastDeleteButton(): Promise<void> {
    await this.deleteButtons.last().click();
  }

  async countDeleteButtons(): Promise<number> {
    return this.deleteButtons.count();
  }

  async getTitle(): Promise<string> {
    return this.title.getAttribute('jhiTranslate');
  }
}

export class LikesUpdatePage {
  pageTitle = element(by.id('jhi-likes-heading'));
  saveButton = element(by.id('save-entity'));
  cancelButton = element(by.id('cancel-save'));

  dateInput = element(by.id('field_date'));
  userIDInput = element(by.id('field_userID'));
  projectIDInput = element(by.id('field_projectID'));

  async getPageTitle(): Promise<string> {
    return this.pageTitle.getAttribute('jhiTranslate');
  }

  async setDateInput(date: string): Promise<void> {
    await this.dateInput.sendKeys(date);
  }

  async getDateInput(): Promise<string> {
    return await this.dateInput.getAttribute('value');
  }

  async setUserIDInput(userID: string): Promise<void> {
    await this.userIDInput.sendKeys(userID);
  }

  async getUserIDInput(): Promise<string> {
    return await this.userIDInput.getAttribute('value');
  }

  async setProjectIDInput(projectID: string): Promise<void> {
    await this.projectIDInput.sendKeys(projectID);
  }

  async getProjectIDInput(): Promise<string> {
    return await this.projectIDInput.getAttribute('value');
  }

  async save(): Promise<void> {
    await this.saveButton.click();
  }

  async cancel(): Promise<void> {
    await this.cancelButton.click();
  }

  getSaveButton(): ElementFinder {
    return this.saveButton;
  }
}

export class LikesDeleteDialog {
  private dialogTitle = element(by.id('jhi-delete-likes-heading'));
  private confirmButton = element(by.id('jhi-confirm-delete-likes'));

  async getDialogTitle(): Promise<string> {
    return this.dialogTitle.getAttribute('jhiTranslate');
  }

  async clickOnConfirmButton(): Promise<void> {
    await this.confirmButton.click();
  }
}