describe('App Loading', () => {
  it('loads the home page with header and nav', () => {
    cy.visit('/')
    cy.get('.app-header').should('be.visible')
    cy.contains('doTERRA 配方计算器').should('be.visible')
    cy.get('.nav-tabs').should('be.visible')
    cy.get('.nav-tab').should('have.length.gte', 4)
  })

  it('shows the search section by default', () => {
    cy.visit('/')
    cy.get('.nav-tab').first().should('have.class', 'active')
    cy.get('input[placeholder*="搜索"]', { timeout: 8000 }).should('be.visible')
  })

  it('navigates between public tabs without login', () => {
    cy.visit('/')
    cy.get('.nav-tab').contains('精油价目').click()
    cy.url().should('include', '/oils')
    cy.contains('精油价目').should('be.visible')

    cy.get('.nav-tab').contains('配方查询').click()
    cy.url().should('not.include', '/oils')
  })

  it('prompts login when accessing protected tabs', () => {
    cy.visit('/')
    cy.get('.nav-tab').contains('管理配方').click()
    // Should show login modal or dialog
    cy.get('[class*="overlay"], [class*="login"], [class*="modal"], [class*="dialog"]', { timeout: 3000 }).should('exist')
  })
})
