import React from "react"
import { describe, expect, it, vi } from "vitest"
import { render } from "@testing-library/react"
import { MemoryRouter } from "react-router-dom"

vi.mock("@/components/layout/PageHead", () => ({
  default: ({ title }: { title: string }) => <div data-testid="page-head">{title}</div>,
}))

vi.mock("@tanstack/react-query", () => ({
  useQuery: () => ({
    data: { plan: "free", status: "active", auto_renew: true },
    isLoading: false,
    isError: false,
    refetch: vi.fn(),
  }),
  useMutation: () => ({
    mutate: vi.fn(),
    mutateAsync: vi.fn(),
    isLoading: false,
  }),
}))

vi.mock("@/components/ui", () => ({
  Button: ({ children, onClick }: any) => <button onClick={onClick}>{children}</button>,
  Modal: ({ open, children }: any) => (open ? <div role="dialog">{children}</div> : null),
}))

vi.mock("antd", () => ({
  message: { success: vi.fn(), error: vi.fn(), warning: vi.fn() },
}))

vi.mock("@/api/subscription", () => ({
  getCurrentSubscription: vi.fn().mockResolvedValue({ plan: "free", status: "active" }),
  changePlan: vi.fn().mockResolvedValue({ success: true }),
  toggleAutoRenew: vi.fn().mockResolvedValue({ success: true }),
  cancelSubscription: vi.fn().mockResolvedValue({ success: true }),
}))

vi.mock("@/pages/subscription/UpgradeSubscription.css", () => ({}))

import UpgradeSubscription from "@/pages/subscription/UpgradeSubscription"

describe("UpgradeSubscription Page", () => {
  it("should render without crashing", () => {
    const { container } = render(
      <MemoryRouter>
        <UpgradeSubscription />
      </MemoryRouter>,
    )
    expect(container.querySelector(".xx-upgrade-page")).toBeTruthy()
  })
})
