"use client"; import { useState, useTransition } from "react"; import { useRouter } from "next/navigation"; import { toast } from "sonner"; import { createAdminRechargeCards } from "@/actions/admin/recharge-cards"; import { BooleanToggle } from "@/components/ui/boolean-toggle"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { getErrorMessage } from "@/lib/errors"; interface PlanOption { id: string; name: string; type: "PROXY" | "STREAMING"; remainingCount: number | null; } export function RechargeCardForm({ plans }: { plans: PlanOption[] }) { const router = useRouter(); const [type, setType] = useState<"BALANCE" | "PLAN">("BALANCE"); const [planId, setPlanId] = useState(plans[0]?.id ?? ""); const [hasExpiry, setHasExpiry] = useState(false); const [pending, startTransition] = useTransition(); const selectedPlan = plans.find((plan) => plan.id === planId) ?? null; const planSoldOut = type === "PLAN" && selectedPlan?.remainingCount === 0; return (
); }