describe('about page', () => {
  beforeEach(() => {
    cy.visit('/about')
  })

  it('renders the header and about hero', () => {
    cy.get('header.site-header').within(() => {
      cy.contains('Torah Media').should('be.visible')
      cy.contains('About').should('be.visible')
      cy.contains('Donate').should('be.visible')
      cy.contains('a', 'Contact').should('not.exist')
    })

    cy.get('[data-cy="about-hero"]').within(() => {
      cy.contains('h1', 'About Rabbi Gerzi').should('be.visible')
      cy.contains('Healthy, Integrated and Balanced Torah living')
        .should('be.visible')
      cy.get('[data-cy="about-hero-image"]')
        .should('be.visible')
        .and('have.attr', 'alt')
        .and('match', /Rabbi Yehoshua Gerzi/i)
    })
  })

  it('renders the copied biography and mission sections', () => {
    cy.get('[data-cy="about-story"]').within(() => {
      cy.contains('h2', 'About Rabbi Gerzi').should('be.visible')
      cy.contains('Pilzno Rebbe').should('be.visible')
      cy.contains('descends from an illustrious lineage')
        .should('be.visible')
      cy.contains('physical therapist, music instructor, martial artist')
        .should('be.visible')
    })

    cy.get('[data-cy="about-vision"]').within(() => {
      cy.contains('h2', "Rabbi Gerzi's Vision").should('be.visible')
      cy.contains('from vagueness to clarity').should('be.visible')
      cy.contains('weekly chaburot and various events')
        .should('be.visible')
    })

    cy.get('[data-cy="about-mission"]').within(() => {
      cy.contains('h2', 'The Mission').should('be.visible')
      cy.contains('A Clear Framework').should('be.visible')
      cy.contains('Community and Support').should('be.visible')
      cy.contains('Professional Structure').should('be.visible')
    })

    cy.get('[data-cy="about-teachers"]').within(() => {
      cy.contains('h2', "Rabbi Gerzi's Teachers").should('be.visible')
      cy.contains('Rabbi Yosef Singer').should('be.visible')
      cy.contains('Rabbi Efraim Greenblatt').should('be.visible')
      cy.contains('Rabbi Mordechai Zukerman').should('be.visible')
    })
  })

  it('renders the rabbanim section without repeated carousel copies', () => {
    const expectedRabbanim = [
      'The Biala Rebbe',
      'The Pilzno Rebbe, Rabbi Yosef Singer',
      'Dayan Gershon Lopian',
      'Rabbi Efraim Greenblatt',
      'The Sassover Rebbe',
      'The Pashkana Rebbe',
      'Rabbi Mordechai Zukerman',
      'The Radamishler Rebbe',
      'Rabbi Yoseph Leiberman',
      'The Krechnover Rebbe',
    ]

    cy.get('[data-cy="rabbanim"]').within(() => {
      cy.contains('h2', 'Rabbanim').should('be.visible')
      cy.get('[data-cy="rabbanim-card"]').should(
        'have.length',
        expectedRabbanim.length,
      )

      expectedRabbanim.forEach((rabbiName) => {
        cy.contains('[data-cy="rabbanim-card"]', rabbiName)
          .should('be.visible')
      })

      cy.contains('match the person in front of you').should('be.visible')
      cy.contains('depth and the profundity of love')
        .should('be.visible')
    })
  })

  it('renders the haskamot image gallery', () => {
    cy.get('[data-cy="haskamot"]').within(() => {
      cy.contains('h2', 'Haskamot').should('be.visible')
      cy.get('[data-cy="haskamah-image"]').should('have.length', 6)
      cy.get('[data-cy="haskamah-image"]')
        .first()
        .should('be.visible')
        .and('have.attr', 'alt', 'Haskamah letter 1')
      cy.get('[data-cy="haskamah-image"]')
        .last()
        .and('have.attr', 'alt', 'Haskamah letter 6')
    })
  })

  it('keeps the page readable on mobile', () => {
    cy.viewport(390, 900)

    cy.get('[data-cy="about-hero"]').should('be.visible')
    cy.get('[data-cy="rabbanim-card"]').first().should('be.visible')
    cy.get('[data-cy="haskamah-image"]').first().should('be.visible')
  })

  it('does not render the get involved subscription section', () => {
    cy.get('[data-cy="get-involved"]').should('not.exist')
    cy.contains('Subscribe for updates as we release new content')
      .should('not.exist')
  })

  it('renders the footer with links and copyright', () => {
    cy.get('[data-cy="footer"]').within(() => {
      cy.contains('Torah Media').should('be.visible')
      cy.contains('About').should('be.visible')
      cy.contains('Donate').should('be.visible')
      cy.contains('a', 'Contact').should('not.exist')
      cy.contains(/Rabbi Gerzi 2025/).should('be.visible')
    })
  })
})
