import React from 'react'
import { render, fireEvent, waitFor } from '@testing-library/react-native'
import { AuthForm } from '../AuthForm'
import { storage } from '@/lib/storage'

// Mock entire UI module to avoid complex dependencies
jest.mock('@/components/ui', () => {
  const mockReact = require('react')
  const mockRN = require('react-native')

  const Block = ({ children, onClick, ...props }: any) => {
    if (onClick) {
      return mockReact.createElement(mockRN.Pressable, { onPress: onClick, ...props }, children)
    }
    return mockReact.createElement(mockRN.View, props, children)
  }

  const Text = ({ children, onClick, ...props }: any) => {
    if (onClick) {
      return mockReact.createElement(mockRN.Pressable, { onPress: onClick },
        mockReact.createElement(mockRN.Text, props, children)
      )
    }
    return mockReact.createElement(mockRN.Text, props, children)
  }

  return {
    Block,
    Text,
  }
})

// Mock button component separately since it's imported from a different path
jest.mock('../../ui/button', () => {
  const mockReact = require('react')
  const mockRN = require('react-native')

  const Button = ({ children, onPress, disabled, ...props }: any) => (
    mockReact.createElement(mockRN.Pressable, { onPress, disabled, ...props }, children)
  )

  return {
    Button,
  }
})

// Mock ModalPortal to avoid react-native-css-interop issues
jest.mock('@/components/ui/ModalPortal', () => ({
  __esModule: true,
  default: ({ children }: any) => children,
}))

// Mock storage
jest.mock('@/lib/storage', () => ({
  storage: {
    getItem: jest.fn(),
    setItem: jest.fn(),
    removeItem: jest.fn(),
  },
}))

// Mock auth client
jest.mock('@/lib/auth', () => ({
  authClient: {
    signIn: {
      username: jest.fn(),
    },
    signUp: {
      email: jest.fn(),
    },
  },
  setAuthToken: jest.fn(),
  useSession: jest.fn(() => ({ data: null, isPending: false })),
}))

// Mock react-i18next
jest.mock('react-i18next', () => ({
  useTranslation: () => ({
    t: (key: string) => key,
  }),
}))

describe('AuthForm - Remember Password', () => {
  beforeEach(() => {
    jest.clearAllMocks()
  })

  test('renders remember password checkbox', () => {
    const { getByText } = render(<AuthForm />)
    expect(getByText('authForm.rememberPassword')).toBeTruthy()
  })
})
