/**
 * @jest-environment jsdom
 * @jest-environment-options {"url": "https://myamsoil.com/"}
 *
 * Production-host path for ApexAnalytics: on a real apex host the GA4 tag
 * mounts. The jsdom URL is pinned to a production apex via the docblock
 * above (jsdom's window.location is otherwise non-configurable). next/script
 * defers afterInteractive scripts to Next's runtime, so it is stubbed to a
 * plain <script> to make the inline GA config assertable.
 */
import type { ReactNode } from 'react';
import { render } from '@testing-library/react';

jest.mock('next/script', () => ({
  __esModule: true,
  default: ({ id, src, children }: { id?: string; src?: string; children?: ReactNode }) => (
    // eslint-disable-next-line @next/next/no-sync-scripts -- test stub for next/script
    <script id={id} src={src}>
      {children}
    </script>
  ),
}));

import { ApexAnalytics } from '../ApexAnalytics';

describe('ApexAnalytics on a production host', () => {
  it('loads the GA4 tag (config inline script present)', () => {
    const { container } = render(<ApexAnalytics />);
    const init = container.querySelector('#ga4-init');
    expect(init?.textContent).toContain('G-NR1G252PS2');
    expect(container.querySelector('script[src*="googletagmanager.com/gtag/js"]')).not.toBeNull();
  });
});
