import { agentDesktopSelectors } from '@travelxen-lib/selectors/flex';
import { getLastMessageInView } from '@travelxen-lib/utils';
import { Timeouts } from '@utility-lib/constants';

export class FlexAgentDesktop {
  static sendMessageFromAgent(msg: string) {
    cy.allure().logStep('Send message from agent');

    cy.get(agentDesktopSelectors.messageField).type(msg);
    cy.get(agentDesktopSelectors.sendButton).click();

    getLastMessageInView().should('contain.text', msg);
  }

  static acceptTaskForUser(userName = '') {
    cy.contains(userName)
      .parent()
      .parent()
      .parent()
      .find('button[data-testid="button"]')
      .first()
      .click();
  }

  static changeAgentActivity(activityName = 'Available') {
    cy.get(agentDesktopSelectors.profileToggle).click();
    cy.get(agentDesktopSelectors.profileDropdown).contains(activityName).click();
  }

  static wrapUpConversation() {
    cy.get('button[data-tip="Wrap up"]').click();

    cy.wait(Timeouts.SHORT_TIMEOUT_5_SEC.timeout);

    cy.get('a[data-disposition-select="true"]').click();

    cy.wait(Timeouts.SHORT_TIMEOUT_1_SEC.timeout);

    cy.get('a[data-disposition-option="true"]').eq(3).click({ force: true });

    cy.wait(Timeouts.SHORT_TIMEOUT_1_SEC.timeout);

    cy.get('a[data-disposition-option="true"]').eq(2).click({ force: true });

    cy.wait(Timeouts.SHORT_TIMEOUT_1_SEC.timeout);

    cy.contains('Booking ID is not available').click();

    cy.wait(Timeouts.SHORT_TIMEOUT_1_SEC.timeout);

    cy.get('button[data-disposition-submit="true"]').last().click();
  }
}
