import BasePage from "./BasePage";

class HomePage extends BasePage {
  // Selectors
  get loadingSpinner() {
    return $(".animate-spin");
  }

  get browseLibrariesButton() {
    return $("button*=Browse all libraries");
  }

  get offlineBanner() {
    return $(".bg-amber-600\\/90");
  }

  // Carousel sections
  get heroSection() {
    return $("div"); // Hero banner would need specific selector
  }

  // Actions
  async waitForHomePageLoad(timeout: number = 15000) {
    // Wait for loading spinner to disappear
    try {
      await this.loadingSpinner.waitForDisplayed({ timeout: 5000 });
      await this.loadingSpinner.waitForDisplayed({ timeout, reverse: true });
    } catch {
      // Spinner might not appear if page loads quickly
    }
  }

  async isOffline(): Promise<boolean> {
    try {
      return await this.offlineBanner.isDisplayed();
    } catch {
      return false;
    }
  }

  async clickBrowseLibraries() {
    await this.browseLibrariesButton.click();
  }

  async hasContent(): Promise<boolean> {
    // Check if browse button exists (indicates loaded state)
    try {
      return await this.browseLibrariesButton.isExisting();
    } catch {
      return false;
    }
  }
}

export default new HomePage();
