import { render, screen, renderHook } from '@testing-library/react';
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { GoogleMapsProvider, useGoogleMapsLoader } from './google-maps-loader';
import React from 'react';

describe('GoogleMapsLoader', () => {
  beforeEach(() => {
    vi.clearAllMocks();
    global.google = {
      maps: {
        importLibrary: vi.fn().mockResolvedValue({}),
      },
    } as any;
  });

  it('provides loading state', () => {
    const wrapper = ({ children }: { children: React.ReactNode }) => (
      <GoogleMapsProvider apiKey="test-key">{children}</GoogleMapsProvider>
    );

    const { result } = renderHook(() => useGoogleMapsLoader(), { wrapper });

    expect(result.current).toBeDefined();
    expect(typeof result.current.isLoaded).toBe('boolean');
  });

  it('renders children', () => {
    render(
      <GoogleMapsProvider apiKey="test-key">
        <div data-testid="child">Child</div>
      </GoogleMapsProvider>
    );
    expect(screen.getByTestId('child')).toBeInTheDocument();
  });
});
