import { HelpCenter } from '@helpcenter-lib/helpcenter';
import { ChatApiIntercept, ChatBox, Banner } from '@chat-lib/index';
import { Timeouts } from '@utility-lib/constants';
import { getLastMessageInView, visitAgentDesktop } from '@travelxen-lib/utils';
import { stagingUsers } from '@fixtures/staging-users';
import { FlexAgentDesktop } from '@travelxen-lib/pages';
import { TravelXenInterceptApis } from '@travelxen-lib/api-intercept';
import { agentDesktopSelectors } from '@travelxen-lib/selectors/flex';

const { userChat } = stagingUsers;
const userPassword = Cypress.env('chat').CHAT_PASSWORD;

describe.skip('Chat: conversation and transfer to an agent', () => {
  beforeEach(() => {
    cy.cleanUpTasks();
  });

  afterEach(() => {
    cy.cleanUpTasks();
  });

  it.skip('C149791: Transfer and conversation with agent', { tags: ['@tier1'] }, () => {
    ChatApiIntercept.interceptChatApis();
    TravelXenInterceptApis.interceptTravelxenApis();

    HelpCenter.visitAndLogin(userChat.email, userPassword);
    ChatBox.startANewChatOrContinue();

    ChatBox.selectMsgYouWannaSendBackToAva('No, something else', 'Talk to an agent');
    ChatBox.verifyIfMsgInputDisplayed();

    const userMsg = 'Help me!';
    const agentMsg = 'Hello from the agent!';

    ChatBox.typeMsgToAva(userMsg);

    Banner.expectBannerIsVisible();

    visitAgentDesktop();

    FlexAgentDesktop.changeAgentActivity('Available');
    FlexAgentDesktop.acceptTaskForUser(userChat.name);
    FlexAgentDesktop.changeAgentActivity('Block Interactions');

    getLastMessageInView().should('contain.text', userMsg);

    FlexAgentDesktop.sendMessageFromAgent(agentMsg);
    FlexAgentDesktop.wrapUpConversation();

    cy.wait(Timeouts.SHORT_TIMEOUT_3_SEC.timeout);

    cy.get(agentDesktopSelectors.header).within(() => {
      cy.contains(userChat.name).should('not.exist');
    });
  });
});
