"use client";
import { useState } from "react";
import { IconGitCommit, IconLoader2, IconCheck } from "@tabler/icons-react";
import { Button } from "@kandev/ui/button";
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
DialogFooter,
DialogClose,
} from "@kandev/ui/dialog";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "@kandev/ui/alert-dialog";
import { Label } from "@kandev/ui/label";
import { Input } from "@kandev/ui/input";
import { Textarea } from "@kandev/ui/textarea";
import { RadioGroup, RadioGroupItem } from "@kandev/ui/radio-group";
import { Trans, useTranslation } from "react-i18next";
// --- Discard Confirmation Dialog ---
type DiscardDialogProps = {
open: boolean;
onOpenChange: (open: boolean) => void;
fileToDiscard: string | null;
filesToDiscard: string[] | null;
onConfirm: () => void;
};
export function DiscardDialog({
open,
onOpenChange,
fileToDiscard,
filesToDiscard,
onConfirm,
}: DiscardDialogProps) {
const { t } = useTranslation();
const isBulk = filesToDiscard && filesToDiscard.length > 1;
const displayFile = fileToDiscard ?? (filesToDiscard?.length === 1 ? filesToDiscard[0] : null);
const description = isBulk
? t("task:discardAllChangesToFiles", { count: filesToDiscard.length })
: null;
return (
{t("task:discardChanges")}
{description ?? (
This will permanently discard all changes to{" "}
{displayFile}. This
action cannot be undone.
)}
{t("common:cancel")}
{t("task:discard")}
);
}
// --- Amend Commit Message Dialog ---
type AmendDialogProps = {
open: boolean;
onOpenChange: (open: boolean) => void;
amendMessage: string;
onAmendMessageChange: (value: string) => void;
onAmend: () => void;
isLoading: boolean;
};
export function AmendDialog({
open,
onOpenChange,
amendMessage,
onAmendMessageChange,
onAmend,
isLoading,
}: AmendDialogProps) {
const { t } = useTranslation();
return (
);
}
// --- Reset to Commit Dialog ---
type ResetDialogProps = {
open: boolean;
onOpenChange: (open: boolean) => void;
commitSha: string | null;
onReset: (mode: "soft" | "hard") => void;
isLoading: boolean;
};
/** Type-to-confirm field for a hard reset. The SHA is never translated — the
* user must type it verbatim and it is compared with `===`. */
function HardResetConfirmField({
shortSha,
confirmation,
onConfirmationChange,
}: {
shortSha: string;
confirmation: string;
onConfirmationChange: (value: string) => void;
}) {
return (
);
}
export function ResetDialog({
open,
onOpenChange,
commitSha,
onReset,
isLoading,
}: ResetDialogProps) {
const { t } = useTranslation();
const shortSha = commitSha?.slice(0, 7) ?? "";
const [mode, setMode] = useState<"soft" | "hard">("soft");
const [confirmation, setConfirmation] = useState("");
const isHardResetConfirmed = mode === "hard" && confirmation === shortSha;
const canReset = !!commitSha && (mode === "soft" || isHardResetConfirmed);
const handleOpenChange = (newOpen: boolean) => {
if (!newOpen) {
// Reset state when closing
setMode("soft");
setConfirmation("");
}
onOpenChange(newOpen);
};
const handleReset = () => {
if (canReset) {
onReset(mode);
}
};
return (
);
}