"use client";

import Link from "next/link";

import {
  Dialog,
  DialogContent,
  DialogDescription,
  DialogFooter,
  DialogHeader,
  DialogTitle,
} from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
import type { GateResult } from "@/lib/gates";

interface UpgradeDialogProps {
  open: boolean;
  onOpenChange: (v: boolean) => void;
  gate: GateResult | null;
}

export function UpgradeDialog({ open, onOpenChange, gate }: UpgradeDialogProps) {
  if (!gate) return null;
  return (
    <Dialog open={open} onOpenChange={onOpenChange}>
      <DialogContent>
        <DialogHeader>
          <DialogTitle>Upgrade required</DialogTitle>
          <DialogDescription>{gate.reason}</DialogDescription>
        </DialogHeader>
        <p className="text-muted-foreground text-sm">
          Using {gate.current} of {gate.limit} included in your current plan.
        </p>
        <DialogFooter>
          <Button variant="ghost" onClick={() => onOpenChange(false)}>
            Cancel
          </Button>
          <Button asChild>
            <Link href="/portal/pricing">View plans</Link>
          </Button>
        </DialogFooter>
      </DialogContent>
    </Dialog>
  );
}
