import { Locator, Page } from '@playwright/test'

export class ActivitySelectPage {
  readonly page: Page

  // 页面元素定位器
  readonly title: Locator
  readonly routeInfo: Locator
  readonly departureActivitiesTab: Locator
  readonly returnActivitiesTab: Locator
  readonly activityCards: Locator
  readonly noActivitiesText: Locator

  constructor(page: Page) {
    this.page = page

    // 初始化定位器
    this.title = page.locator('text=选择观看活动')
    this.routeInfo = page.locator('text=北京市 → 上海市')
    this.departureActivitiesTab = page.locator('text=去程活动')
    this.returnActivitiesTab = page.locator('text=返程活动')
    this.activityCards = page.locator('text=上海音乐节')
    this.noActivitiesText = page.locator('text=暂无相关活动')
  }

  // 页面操作方法
  async waitForPageLoad() {
    await this.page.waitForURL(/\/pages\/select-activity\/ActivitySelectPage/)
  }

  async selectActivity(activityName: string) {
    await this.page.click(`text=${activityName}`)
  }

  async switchToDepartureActivities() {
    await this.departureActivitiesTab.click()
  }

  async switchToReturnActivities() {
    await this.returnActivitiesTab.click()
  }

  async getActivityCount(): Promise<number> {
    return await this.activityCards.count()
  }

  async hasActivities(): Promise<boolean> {
    return await this.activityCards.first().isVisible()
  }

  async getRouteInfo(): Promise<string> {
    return await this.routeInfo.textContent() || ''
  }
}