import { Timeouts } from '@utility-lib/index';
import { AdminInterceptsApis } from '@admin-lib/api-intercept';

const superAdminSelectors = {
  companies: 'a[href="companies"]',
  tools: 'a[href="tools"]',
  fromDate: '#fromDate',
  searchButton: '.text-right .button',
  toDate: '#toDate',
  transactionsText: '.col.ng-binding',
  notificationToastAlertMessage: '.ta-toastr-message',
  viewUploadedAWSS3BucketButton: '.card__content .button',
  rowNumber: '.table-outline tr td button',
  getFilename: '.table-outline tr',
  viewAmexBTATransactions: 'a[href="tools/amexBTATransactions"]',
  companySearchBar: '#search',
  companyRowItem: '.company-row',
  companyHeader: '[class="card__heading"] h3'
};

export class SuperAdmin {
  static waitForLoadSuperAdminLogin() {
    cy.allure().logStep('wait for load superAdmin to load');
    cy.wait('@waitForUserInfo');
  }

  static clickTools() {
    cy.allure().logStep('click Tools');
    AdminInterceptsApis.interceptAdminsApis();
    cy.get(superAdminSelectors.tools).should('be.visible').click();
  }
  static validateAMEXBTAXMLIsDownloaded() {
    // let filename = '';
    // cy.allure().logStep('Validate AMEX BTA XML Is Downloaded');
    // cy.get(superAdminSelectors.viewAmexBTATransactions).should('be.visible').click();
    // cy.wait('@waitForAgencies');
    // cy.clearInputAndType(superAdminSelectors.fromDate, yesterday);
    // cy.clearInputAndType(superAdminSelectors.toDate, today);
    // cy.get(superAdminSelectors.searchButton).click();
    // cy.wait('@waitForAMEXBTAEUXL');
    // cy.get(superAdminSelectors.notificationToastAlertMessage).should(
    //   'be.visible',
    //   Timeouts.MAX_TIMEOUT_120_SEC
    // );
    // cy.get(superAdminSelectors.transactionsText).should(
    //   'be.visible',
    //   Timeouts.MAX_TIMEOUT_120_SEC
    // );
    // cy.get(superAdminSelectors.viewUploadedAWSS3BucketButton)
    //   .should('be.visible')
    //   .click();
    // cy.get(superAdminSelectors.getFilename)
    //   .eq(0)
    //   .get('td')
    //   .eq(2)
    //   .invoke('text')
    //   .then((text) => {
    //     filename = text.replace('/', '_');
    //     cy.task('putDataInCache', {
    //       key: 'fileNameFromUI',
    //       data: filename
    //     });
    //   });
    // cy.log(filename);
    // cy.get(superAdminSelectors.rowNumber).eq(0).click({ force: true });
    // Invoice.verifyIfFileIsDownloaded(filename);
  }

  static clickCompanies() {
    cy.get(superAdminSelectors.companies, { timeout: 30000 }).should('be.visible').click();

    cy.get(superAdminSelectors.companyHeader).should('contain', 'Companies on TripActions');
    cy.wait(Timeouts.MEDIUM_TIMEOUT_10_SEC.timeout);
    cy.log('Companies page is loaded');
    cy.get(superAdminSelectors.companySearchBar).should('be.visible').type('cypress', { delay: 100 });
    cy.wait(Timeouts.SHORT_TIMEOUT_3_SEC.timeout);

    cy.wait('@waitForLoadCompanies');

    cy.get(superAdminSelectors.companyRowItem).eq(0).should('be.visible');
  }
}
