"use client";
import { Check, Loader2, Send, X } from "lucide-react";
import { useTranslation } from "react-i18next";
import { Button } from "@/components/ui/button";
import { DialogFooter, DialogPanel } from "@/components/ui/dialog";
import {
Stepper,
StepperIndicator,
StepperItem,
StepperSeparator,
StepperTitle,
} from "@/components/ui/stepper";
import type { UseWalletSync } from "./use-wallet-sync";
// Two-step header shown at the top of a dialog when the selected patient has a
// linked wallet: "Details" → "Sync to wallet". Centered so the numbered
// indicators sit inline with their labels.
export function DialogStepper({ step }: { step: "form" | "wallet" }) {
const { t } = useTranslation();
const steps = [
{ value: 1, label: t("walletSync.step1") },
{ value: 2, label: t("walletSync.step2") },
];
const activeValue = step === "form" ? 1 : 2;
return (
{steps.map(({ value, label }, i) => (
{label}
{i < steps.length - 1 && }
))}
);
}
// Step 2 body + footer: offer to push the just-saved change to the patient's
// wallet, then show the approval status. Rendered in place of the form's
// DialogPanel/DialogFooter, so it returns them as a fragment.
export function WalletSyncStep({
patientName,
summary,
sync,
onDone,
}: {
patientName: string;
summary: string;
sync: UseWalletSync;
onDone: () => void;
}) {
const { t } = useTranslation();
const { state, update, error, push } = sync;
const status = update?.status ?? "pending";
// The summary is the human-readable change the patient approves. Guard against
// an empty one (the backend 400s on empty changes) with a translated fallback.
const changeSummary = summary.trim() || t("walletSync.summaryFallback");
return (
<>
{state === "idle" || state === "error" ? (