import { LoginPage } from '@admin-lib/index';
import { FlightInterceptApis, FlightItinerary, Flights } from '@flight-lib/index';
import { HotelInterceptApis } from '@hotel-lib/api-intercept';
import { User_Type } from '@support-onboard/index';
import { HomePage } from '../lib/home-page';
import { EventsWorkflow, TeamEventsInterceptApis } from '@group-events-lib/index';
import { ProfileInterceptApis } from '@profile-lib/api-intercept';
import { FlightBookingUtility } from '@flight-modal/flight_booking_utility';

describe('Trips: Rebranded home page tests', () => {
  beforeEach(() => {
    LoginPage.createNewCompanyAndLoginWithUserByType({ users: [User_Type.ADMIN] });
    FlightInterceptApis.interceptFlightsApis();
    HotelInterceptApis.interceptHotelApis();
    ProfileInterceptApis.interceptProfileApis();
    TeamEventsInterceptApis.teamEventIntercept();
  });

  it(
    'C2808882: Search field expands after clicking location input field',
    { tags: ['@tier1'] },
    () => {
      HomePage.verifyMinimizedSearch();
      HomePage.expandSearchForm();
    }
  );

  it('C2980465: Validate Travel-only user experience', { tags: ['@tier2'] }, () => {
    HomePage.verifyTravelOnly();
  });

  it(
    'C2808887: Special Trip card only appears if there is an upcoming or current trip',
    { tags: ['@tier3'] },
    () => {
      FlightBookingUtility.bookOneWayFlight('Business');
      Flights.checkUpcomingTrip();
      FlightItinerary.verifyFlightItineraryPage();
      Flights.SpecialTripCardDisappearOnClickNotNow();
    }
  );

  it(
    'C2808889: Special Trip card dismisses after clicking "Not now"',
    { tags: ['@tier2'] },
    () => {
      FlightBookingUtility.bookOneWayFlight('Business');
      HomePage.visitHomePage();
      HomePage.dismissSpecialTripCard();
      HomePage.verifyNoSpecialTripCard();
    }
  );

  it(
    'C3591193: Special Trip card does not appear for a trip after the trip is cancelled or completed',
    { tags: ['@tier2'] },
    () => {
      FlightBookingUtility.bookOneWayFlight('Business');
      HomePage.visitHomePage();
      HomePage.verifySpecialTripSuggestions();
      Flights.checkUpcomingTrip();
      FlightItinerary.verifyFlightItineraryPage();
      FlightItinerary.cancelFlight();
      HomePage.visitHomePage();
      HomePage.verifyNoSpecialTripCard();
    }
  );

  it(
    'C2808891 C2808890 C2808888: Special Trip card displays relevant booking suggestions',
    { tags: ['@tier2'] },
    () => {
      FlightBookingUtility.bookOneWayFlight('Business');
      HomePage.visitHomePage();
      HomePage.verifySpecialTripSuggestions();
      HomePage.bookHotelSuggestion(1);
      HomePage.visitHomePage();
      HomePage.verifyNoSpecialTripCard();
      HomePage.verifyUpcomingTripCardBookings();
    }
  );

  it(
    'C365929 C2808881 C2808883 C2808885: Home page search field appears minimized initially',
    { tags: ['@tier2'] },
    () => {
      HomePage.verifyMinimizedSearch();
      HomePage.expandSearchForm();
      HomePage.toggleBusinessPersonalSearch();
      FlightBookingUtility.bookOneWayFlight('Business');
      HomePage.verifySearchHistory();
      HomePage.clearSearchHistory();
    }
  );

  it(
    'C2808892: Validate upcoming trips shows pending invites drafts',
    { tags: ['@tier2'] },
    () => {
      HomePage.visitHomePage();
      EventsWorkflow.createDraftEvent('Zurich', 'Zurich event');
      HomePage.visitHomePage();
      HomePage.verifyUpcomingEventDraftCard();
      HomePage.openUpcomingEventDraftCard();
      HomePage.inviteSelfToEvent();
      HomePage.verifyUpcomingEventInviteCard();
    }
  );
});
