import { useState } from "react" import { Trash2 } from "lucide-react" import { toast } from "sonner" import { deleteSubscriptionPlan } from "../../../api/subscription-plans.api" import { Button } from "../../../components/ui/button" import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "../../../components/ui/dialog" import { formatPlanPrice } from "../../../lib/subscriptionPlans" import type { SubscriptionPlan } from "../../../types/subscription.types" type DeleteSubscriptionPlanDialogProps = { plan: SubscriptionPlan | null open: boolean onOpenChange: (open: boolean) => void onDeleted: (id: number) => void } export function DeleteSubscriptionPlanDialog({ plan, open, onOpenChange, onDeleted, }: DeleteSubscriptionPlanDialogProps) { const [deleting, setDeleting] = useState(false) const handleOpenChange = (next: boolean) => { if (!next && !deleting) onOpenChange(false) } const handleConfirm = async () => { if (!plan) return setDeleting(true) try { const res = await deleteSubscriptionPlan(plan.id) toast.success(res.message || "Subscription plan deleted successfully") onDeleted(plan.id) onOpenChange(false) } catch (e: unknown) { console.error(e) const msg = (e as { response?: { data?: { message?: string } } })?.response?.data?.message ?? "Failed to delete subscription plan" toast.error(msg) } finally { setDeleting(false) } } return ( Delete subscription package? This permanently removes the package from the catalog. Learners will no longer be able to purchase it. This action cannot be undone. {plan ? (

{plan.name}

#{plan.id} · {formatPlanPrice(plan)}

) : null}
) }