describe('Price Display Regression', () => {
  it('recipe cards show non-zero prices', () => {
    cy.visit('/')
    cy.get('.recipe-card', { timeout: 10000 }).should('have.length.gte', 1)
    cy.wait(2000) // wait for oils store to load and re-render

    // Check via .recipe-card-price elements which hold the formatted cost
    cy.get('.recipe-card-price').first().invoke('text').then(text => {
      const match = text.match(/¥\s*(\d+\.?\d*)/)
      expect(match, 'Card price should contain ¥').to.not.be.null
      expect(parseFloat(match[1]), 'Price should be > 0').to.be.gt(0)
    })
  })

  it('oil reference page shows non-zero prices', () => {
    cy.visit('/oils')
    cy.get('.oil-card', { timeout: 10000 }).should('have.length.gte', 1)
    cy.wait(500)

    cy.get('.oil-card').first().invoke('text').then(text => {
      const match = text.match(/¥\s*(\d+\.?\d*)/)
      expect(match, 'Oil card should contain a price').to.not.be.null
      expect(parseFloat(match[1])).to.be.gt(0)
    })
  })

  it('recipe detail shows non-zero total cost', () => {
    cy.visit('/')
    cy.get('.recipe-card', { timeout: 10000 }).first().click()
    cy.wait(1000)

    // Look for any ¥ amount > 0 in the detail overlay
    cy.get('[class*="overlay"], [class*="detail"]').invoke('text').then(text => {
      const prices = [...text.matchAll(/¥\s*(\d+\.?\d*)/g)].map(m => parseFloat(m[1]))
      const nonZero = prices.filter(p => p > 0)
      expect(nonZero.length, 'Detail should show at least one non-zero price').to.be.gte(1)
    })
  })
})
