import React from 'react';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { cleanup, render, screen } from '@testing-library/react';
import { CheckoutWizardProvider } from '../WizardContext';
import { PaymentStep } from '../steps/PaymentStep';

vi.mock('@/hooks/useAnalytics', () => ({
  useAnalytics: () => ({ trackEvent: vi.fn() }),
}));

const basePackage = {
  id: 1,
  price: 49,
  paddle_price_id: 'pri_test_123',
};

describe('PaymentStep', () => {
  beforeEach(() => {
    localStorage.clear();
    window.Paddle = {
      Environment: { set: vi.fn() },
      Checkout: { open: vi.fn() },
    };
  });

  afterEach(() => {
    cleanup();
    delete window.Paddle;
  });

  it('renders the payment experience without crashing', async () => {
    render(
      <CheckoutWizardProvider initialPackage={basePackage} packageOptions={[basePackage]}>
        <PaymentStep />
      </CheckoutWizardProvider>,
    );

    expect(await screen.findByText('checkout.payment_step.guided_title')).toBeInTheDocument();
    expect(screen.queryByText('checkout.legal.checkbox_digital_content_label')).not.toBeInTheDocument();
  });
});
