import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useState, useEffect, useMemo } from "react";
import { Dialog, DialogContent } from "../../components/ui/dialog";
import { StyledDialogTitle } from "../../components/ui/styled-dialog-title";
import { Button } from "../../components/ui/button";
import { Loader2, ClipboardCheck, CheckCircle2, AlertTriangle, ArrowRight, } from "lucide-react";
import { cn } from "../../lib/utils";
import { useEditContext } from "../client/editContext";
import DialogButtons from "../ui/DialogButtons";
import { CreateReviewItemsStep } from "./CreateReviewItemsStep";
import { CreateReviewReviewersStep } from "./CreateReviewReviewersStep";
import { CreateReviewLanguagesStep } from "./CreateReviewLanguagesStep";
import { CreateReviewSettingsStep } from "./CreateReviewSettingsStep";
import { CreateReviewConfirmStep } from "./CreateReviewConfirmStep";
import { CreateReviewSuccessStep } from "./CreateReviewSuccessStep";
import { suggestReviewName } from "../services/reviewsService";
const WIZARD_STEPS = [
    {
        id: "items",
        name: "Items",
        description: "Select the content items to include in this review.",
        nextButtonLabel: "Select Items",
    },
    {
        id: "reviewers",
        name: "Reviewers",
        description: "Add the people who will review and approve the content.",
        nextButtonLabel: "Add Reviewers",
    },
    {
        id: "languages",
        name: "Languages",
        description: "Choose which language versions to include in the review.",
        nextButtonLabel: "Select Languages",
    },
    {
        id: "settings",
        name: "Settings",
        description: "Configure optional expiration, approval, and security settings.",
        nextButtonLabel: "Configure Settings",
    },
    {
        id: "confirm",
        name: "Confirm",
        description: "Review the details before sending invitation emails.",
        nextButtonLabel: "Confirm Details",
    },
];
function StepIndicatorDots({ steps, currentStepIndex, }) {
    if (steps.length <= 1)
        return null;
    return (_jsx("div", { className: "pointer-events-none absolute top-full left-1/2 mt-8 flex -translate-x-1/2 justify-center gap-3", "aria-hidden": "true", "data-testid": "create-review-step-dots", children: steps.map((step, index) => (_jsx("div", { className: cn("h-1.5 rounded-full transition-all duration-300", index === currentStepIndex
                ? "w-8 bg-white"
                : "bg-neutral-grey-10 w-1.5") }, step.id))) }));
}
function getExecutionErrorMessage(result, fallback) {
    const summary = result.summary?.trim();
    const details = result.details?.trim();
    if (summary && details && summary !== details) {
        return `${summary}: ${details}`;
    }
    return summary || details || fallback;
}
export function CreateReviewDialog({ open, onOpenChange, onCreated, initialItems, }) {
    const editContext = useEditContext();
    const [stepIndex, setStepIndex] = useState(0);
    const [showSuccess, setShowSuccess] = useState(false);
    const [title, setTitle] = useState("");
    const [language, setLanguage] = useState(editContext?.currentItemDescriptor?.language || "en");
    const [languageMode, setLanguageMode] = useState("multiple");
    const [selectedLanguages, setSelectedLanguages] = useState([
        editContext?.currentItemDescriptor?.language || "en",
    ]);
    const [reviewers, setReviewers] = useState([]);
    const [newReviewer, setNewReviewer] = useState({
        name: "",
        email: "",
    });
    const [items, setItems] = useState([]);
    const [loading, setLoading] = useState(false);
    const [error, setError] = useState(null);
    const [expirationDays, setExpirationDays] = useState("");
    const [secret, setSecret] = useState("");
    const [secretConfirm, setSecretConfirm] = useState("");
    const [showSecretFields, setShowSecretFields] = useState(false);
    const [requiredApprovals, setRequiredApprovals] = useState("1");
    const [updateWorkflowOnCompletion, setUpdateWorkflowOnCompletion] = useState(false);
    const [shareCommentsAndSuggestions, setShareCommentsAndSuggestions] = useState(false);
    const [selectedInTree, setSelectedInTree] = useState([]);
    const [selectedFromList, setSelectedFromList] = useState([]);
    const [createdReviewId, setCreatedReviewId] = useState(null);
    const [sentInvitationCount, setSentInvitationCount] = useState(0);
    const [sentInvitationEmails, setSentInvitationEmails] = useState([]);
    const [isGeneratingTitle, setIsGeneratingTitle] = useState(false);
    const CONTENT_ROOT_ID = "0de95ae4-41ab-4d01-9eb0-67441b7c2450"; // /sitecore/content
    // Memoize rootItemIds to prevent unnecessary re-renders of ContentTree
    const rootItemIds = useMemo(() => [CONTENT_ROOT_ID], []);
    // Memoize itemIds to prevent unnecessary re-fetches of reviewers
    // This ensures the array reference only changes when items actually change,
    // not on every render (e.g., when typing in the Review Name field)
    const itemIds = useMemo(() => items.map((item) => item.descriptor.id), [items]);
    const currentStep = WIZARD_STEPS[stepIndex] ?? WIZARD_STEPS[0];
    const isLastStep = stepIndex === WIZARD_STEPS.length - 1;
    const nextStep = WIZARD_STEPS[stepIndex + 1];
    const requiredApprovalsValid = useMemo(() => {
        const num = requiredApprovals ? parseInt(requiredApprovals, 10) : 1;
        if (isNaN(num) || num < 1)
            return false;
        return num <= reviewers.length;
    }, [requiredApprovals, reviewers.length]);
    const stepValidity = {
        items: items.length > 0,
        reviewers: reviewers.length > 0,
        languages: languageMode === "all" ? true : selectedLanguages.length > 0,
        settings: requiredApprovalsValid && (!showSecretFields || secret === secretConfirm),
        confirm: true,
    };
    const canProceed = stepValidity[currentStep.id];
    useEffect(() => {
        if (open && editContext?.currentItemDescriptor && items.length === 0) {
            // Initialize with current page if available - but only if items haven't been set yet
            // This prevents resetting user changes (like includeSubitems toggles) when context changes
            const initializeItems = async () => {
                let currentDescriptor = editContext.currentItemDescriptor;
                // If the descriptor is missing name, display name, or path, fetch it from the server
                if ((!currentDescriptor.name ||
                    !currentDescriptor.displayName ||
                    !currentDescriptor.path) &&
                    editContext.itemsRepository) {
                    try {
                        const stubs = await editContext.itemsRepository.getItemsStubs([
                            currentDescriptor,
                        ]);
                        if (stubs.length > 0 && stubs[0]) {
                            currentDescriptor = {
                                ...currentDescriptor,
                                name: stubs[0].name || currentDescriptor.name,
                                displayName: stubs[0].displayName || currentDescriptor.displayName,
                                path: stubs[0].path || currentDescriptor.path,
                            };
                        }
                    }
                    catch (error) {
                        console.error("Failed to fetch item stub:", error);
                    }
                }
                let itemsToSet;
                if (initialItems) {
                    // Fetch missing names/display names/paths for initial items as well
                    const itemsToFetch = initialItems.filter((i) => !i.name || !i.displayName || !i.path);
                    if (itemsToFetch.length > 0 && editContext.itemsRepository) {
                        try {
                            const stubs = await editContext.itemsRepository.getItemsStubs(itemsToFetch);
                            const stubMap = new Map(stubs.map((s) => [s.id, s]));
                            itemsToSet = initialItems.map((i) => {
                                const stub = stubMap.get(i.id);
                                return {
                                    descriptor: {
                                        ...i,
                                        name: stub?.name || i.name,
                                        displayName: stub?.displayName || i.displayName,
                                        path: stub?.path || i.path,
                                    },
                                    includeSubitems: false,
                                };
                            });
                        }
                        catch (error) {
                            console.error("Failed to fetch item stubs:", error);
                            itemsToSet = initialItems.map((i) => ({
                                descriptor: i,
                                includeSubitems: false,
                            }));
                        }
                    }
                    else {
                        itemsToSet = initialItems.map((i) => ({
                            descriptor: i,
                            includeSubitems: false,
                        }));
                    }
                }
                else {
                    itemsToSet = [
                        {
                            descriptor: currentDescriptor,
                            includeSubitems: false,
                        },
                    ];
                }
                setItems(itemsToSet);
                setLanguage(currentDescriptor.language || "en");
            };
            initializeItems();
        }
    }, [
        open,
        editContext?.currentItemDescriptor,
        editContext?.itemsRepository,
        initialItems,
    ]);
    const isValidEmail = (email) => {
        const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
        return emailRegex.test(email);
    };
    const generateReviewTitleSuggestion = async () => {
        if (title.trim())
            return null;
        const itemIds = items.map((item) => item.descriptor.id).filter(Boolean);
        if (itemIds.length === 0)
            return null;
        const languages = languageMode === "all" ? ["*"] : [...selectedLanguages].sort();
        setIsGeneratingTitle(true);
        try {
            return await suggestReviewName({
                itemIds,
                languages,
                reviewerCount: reviewers.length,
                includeSubitems: items.some((x) => x.includeSubitems),
            });
        }
        catch (err) {
            console.error("Failed to generate review title suggestion:", err);
            return null;
        }
        finally {
            setIsGeneratingTitle(false);
        }
    };
    const emailAlreadyExists = (email) => {
        return reviewers.some((r) => r.email.toLowerCase() === email.toLowerCase());
    };
    const addReviewer = () => {
        if (!newReviewer.name || !newReviewer.email) {
            return;
        }
        if (!isValidEmail(newReviewer.email)) {
            return;
        }
        if (emailAlreadyExists(newReviewer.email)) {
            return;
        }
        setReviewers([...reviewers, { ...newReviewer }]);
        setNewReviewer({ name: "", email: "" });
    };
    const removeReviewer = (index) => {
        setReviewers(reviewers.filter((_, i) => i !== index));
    };
    const toggleSubitems = (index) => {
        setItems(items.map((item, i) => i === index
            ? { ...item, includeSubitems: !item.includeSubitems }
            : item));
    };
    const removeItem = (index) => {
        setItems(items.filter((_, i) => i !== index));
    };
    const resetDialogState = () => {
        setStepIndex(0);
        setShowSuccess(false);
        setTitle("");
        setReviewers([]);
        setItems([]);
        setExpirationDays("");
        setSecret("");
        setSecretConfirm("");
        setShowSecretFields(false);
        setRequiredApprovals("1");
        setUpdateWorkflowOnCompletion(false);
        setShareCommentsAndSuggestions(false);
        setError(null);
        setLanguageMode("multiple");
        setSelectedLanguages([
            editContext?.currentItemDescriptor?.language || "en",
        ]);
        setLanguage(editContext?.currentItemDescriptor?.language || "en");
        setSelectedInTree([]);
        setSelectedFromList([]);
        setNewReviewer({ name: "", email: "" });
        setCreatedReviewId(null);
        setSentInvitationCount(0);
        setSentInvitationEmails([]);
        setIsGeneratingTitle(false);
    };
    const validateForm = () => {
        if (items.length === 0) {
            return "Please select at least one page/item";
        }
        if (reviewers.length === 0) {
            return "Please add at least one reviewer";
        }
        if (languageMode === "multiple" && selectedLanguages.length === 0) {
            return "Please select at least one language";
        }
        if (showSecretFields && secret !== secretConfirm) {
            return "Secrets do not match";
        }
        const requiredApprovalsNum = requiredApprovals
            ? parseInt(requiredApprovals, 10)
            : 1;
        if (isNaN(requiredApprovalsNum) || requiredApprovalsNum < 1) {
            return "Required Approvals must be at least 1";
        }
        if (requiredApprovalsNum > reviewers.length) {
            return `Required Approvals (${requiredApprovalsNum}) cannot exceed the number of reviewers (${reviewers.length})`;
        }
        return null;
    };
    const handleNext = () => {
        if (isLastStep) {
            void handleCreate();
            return;
        }
        setError(null);
        const nextIndex = stepIndex + 1;
        setStepIndex(nextIndex);
        // Kick off the title suggestion when the user reaches the confirm step
        if (WIZARD_STEPS[nextIndex]?.id === "confirm" && !title.trim()) {
            void (async () => {
                const suggestedTitle = await generateReviewTitleSuggestion();
                if (suggestedTitle) {
                    setTitle((currentTitle) => currentTitle.trim() ? currentTitle : suggestedTitle);
                }
            })();
        }
    };
    const handlePrevious = () => {
        if (stepIndex > 0) {
            setError(null);
            setStepIndex(stepIndex - 1);
        }
    };
    const handleCreate = async () => {
        setError(null);
        const validationError = validateForm();
        if (validationError) {
            setError(validationError);
            return;
        }
        setLoading(true);
        try {
            // Calculate expiration date if specified
            let expirationUtc;
            if (expirationDays &&
                !isNaN(Number(expirationDays)) &&
                Number(expirationDays) > 0) {
                const expirationDate = new Date();
                expirationDate.setDate(expirationDate.getDate() + Number(expirationDays));
                expirationUtc = expirationDate.toISOString();
            }
            // Build languages array based on mode
            const languages = languageMode === "all" ? ["*"] : selectedLanguages;
            const requestItems = items;
            const requiredApprovalsNum = requiredApprovals
                ? parseInt(requiredApprovals, 10)
                : 1;
            const request = {
                title: title || undefined,
                languages,
                reviewers,
                items: requestItems,
                expirationUtc,
                secret: showSecretFields && secret ? secret : undefined,
                requiredApprovals: requiredApprovalsNum,
                updateWorkflowOnCompletion: updateWorkflowOnCompletion,
                shareCommentsAndSuggestions: shareCommentsAndSuggestions,
            };
            const { createReview, getReviewStatus, sendInvitations } = await import("../services/reviewsService");
            const result = await createReview(request);
            if (result.type !== "success") {
                setError(getExecutionErrorMessage(result, "Failed to create review"));
                return;
            }
            if (result.data?.reviewId) {
                setCreatedReviewId(result.data.reviewId);
                // Get assignments to send invitations
                const statusResult = await getReviewStatus(result.data.reviewId);
                if (statusResult.type !== "success") {
                    throw new Error(getExecutionErrorMessage(statusResult, "Failed to load review status"));
                }
                if (statusResult.data?.assignments) {
                    const assignmentsToInvite = statusResult.data.assignments.filter((a) => !a.invitationSentDate);
                    const assignmentIds = assignmentsToInvite.map((a) => a.assignmentId);
                    const reviewerEmails = Array.from(new Set(assignmentsToInvite.map((a) => a.reviewerEmail)));
                    if (assignmentIds.length > 0) {
                        const invitationResult = await sendInvitations(assignmentIds);
                        if (invitationResult.type !== "success") {
                            throw new Error(invitationResult.details ||
                                invitationResult.summary ||
                                "Failed to send invitation emails");
                        }
                        if (invitationResult.data &&
                            typeof invitationResult.data === "object" &&
                            "errors" in invitationResult.data &&
                            Array.isArray(invitationResult.data.errors) &&
                            invitationResult.data.errors.length > 0) {
                            const errorMessages = invitationResult.data.errors
                                .map((err) => err?.message || String(err))
                                .join("; ");
                            throw new Error(errorMessages || "Failed to send invitation emails");
                        }
                    }
                    setSentInvitationCount(assignmentIds.length);
                    setSentInvitationEmails(reviewerEmails);
                }
                else {
                    setSentInvitationCount(0);
                    setSentInvitationEmails([]);
                }
                setShowSuccess(true);
            }
            else {
                setError("Failed to create review");
            }
        }
        catch (err) {
            setError(err instanceof Error ? err.message : "Failed to create review");
        }
        finally {
            setLoading(false);
        }
    };
    const addToList = async (itemsToAdd) => {
        const newItems = [...items];
        const sourceItems = itemsToAdd ?? selectedInTree;
        const nodesToAdd = sourceItems.filter((node) => !newItems.some((x) => x.descriptor.id === node.id));
        // Fetch missing paths/names/display names if needed
        const nodesNeedingFetch = nodesToAdd.filter((node) => !node.path || !node.name || !node.displayName);
        if (nodesNeedingFetch.length > 0 && editContext?.itemsRepository) {
            try {
                const descriptorsToFetch = nodesNeedingFetch.map((node) => ({
                    id: node.id,
                    language: node.language || language,
                    version: node.version || 1,
                }));
                const stubs = await editContext.itemsRepository.getItemsStubs(descriptorsToFetch);
                const stubMap = new Map(stubs.map((s) => [s.id, s]));
                nodesToAdd.forEach((node) => {
                    const stub = stubMap.get(node.id);
                    newItems.push({
                        descriptor: {
                            id: node.id,
                            language: node.language || language,
                            version: node.version || 1,
                            name: stub?.name || node.name || "",
                            displayName: stub?.displayName || node.displayName || "",
                            path: stub?.path || node.path || node.idPath || "",
                        },
                        includeSubitems: false,
                    });
                });
            }
            catch (error) {
                console.error("Failed to fetch item stubs:", error);
                // Fallback: add items without fetching
                nodesToAdd.forEach((node) => {
                    newItems.push({
                        descriptor: {
                            id: node.id,
                            language: node.language || language,
                            version: node.version || 1,
                            name: node.name || "",
                            displayName: node.displayName || "",
                            path: node.path || node.idPath || "",
                        },
                        includeSubitems: false,
                    });
                });
            }
        }
        else {
            // No fetch needed, add directly
            nodesToAdd.forEach((node) => {
                newItems.push({
                    descriptor: {
                        id: node.id,
                        language: node.language || language,
                        version: node.version || 1,
                        name: node.name || "",
                        displayName: node.displayName || "",
                        path: node.path || node.idPath || "",
                    },
                    includeSubitems: false,
                });
            });
        }
        setItems(newItems);
        setSelectedInTree([]);
    };
    const removeFromList = () => {
        const idsToRemove = new Set(selectedFromList.map((i) => i.descriptor.id));
        setItems(items.filter((x) => !idsToRemove.has(x.descriptor.id)));
        setSelectedFromList([]);
    };
    const handleAddItem = async (item) => {
        const exists = items.some((x) => x.descriptor.id === item.id);
        if (!exists) {
            let itemDescriptor = {
                id: item.id,
                language: item.language || language,
                version: item.version || 1,
                name: item.name || "",
                displayName: item.displayName || "",
                path: item.path || item.idPath || "",
            };
            // Fetch missing path/name/display name if needed
            if ((!item.path || !item.name || !item.displayName) &&
                editContext?.itemsRepository) {
                try {
                    const stubs = await editContext.itemsRepository.getItemsStubs([
                        {
                            id: item.id,
                            language: item.language || language,
                            version: item.version || 1,
                        },
                    ]);
                    if (stubs.length > 0 && stubs[0]) {
                        itemDescriptor = {
                            ...itemDescriptor,
                            name: stubs[0].name || itemDescriptor.name || "",
                            displayName: stubs[0].displayName || itemDescriptor.displayName || "",
                            path: stubs[0].path || itemDescriptor.path || "",
                        };
                    }
                }
                catch (error) {
                    console.error("Failed to fetch item stub:", error);
                }
            }
            setItems([
                ...items,
                {
                    descriptor: itemDescriptor,
                    includeSubitems: false,
                },
            ]);
        }
    };
    const handleDialogCancel = () => {
        if (loading)
            return;
        resetDialogState();
        onOpenChange(false);
    };
    const handleDialogOpenChange = (nextOpen) => {
        if (!nextOpen) {
            handleDialogCancel();
            return;
        }
        onOpenChange(nextOpen);
    };
    const handleDone = () => {
        const reviewId = createdReviewId;
        resetDialogState();
        onCreated(reviewId);
    };
    const languageSummary = languageMode === "all"
        ? "All languages"
        : `${selectedLanguages.length} selected (${selectedLanguages.join(", ")})`;
    const renderStepContent = (stepId) => {
        switch (stepId) {
            case "items":
                return (_jsx(CreateReviewItemsStep, { items: items, language: language, rootItemIds: rootItemIds, selectedInTree: selectedInTree, setSelectedInTree: setSelectedInTree, selectedFromList: selectedFromList, setSelectedFromList: setSelectedFromList, addToList: addToList, removeFromList: removeFromList, handleAddItem: handleAddItem, removeItem: removeItem, toggleSubitems: toggleSubitems }));
            case "reviewers":
                return (_jsx(CreateReviewReviewersStep, { items: items, itemIds: itemIds, language: language, reviewers: reviewers, setReviewers: setReviewers, newReviewer: newReviewer, setNewReviewer: setNewReviewer, addReviewer: addReviewer, removeReviewer: removeReviewer, isValidEmail: isValidEmail, emailAlreadyExists: emailAlreadyExists }));
            case "languages":
                return (_jsx(CreateReviewLanguagesStep, { selectedLanguages: selectedLanguages, setSelectedLanguages: setSelectedLanguages, itemLanguages: editContext?.itemLanguages || [] }));
            case "settings":
                return (_jsx(CreateReviewSettingsStep, { reviewers: reviewers, requiredApprovals: requiredApprovals, setRequiredApprovals: setRequiredApprovals, updateWorkflowOnCompletion: updateWorkflowOnCompletion, setUpdateWorkflowOnCompletion: setUpdateWorkflowOnCompletion, shareCommentsAndSuggestions: shareCommentsAndSuggestions, setShareCommentsAndSuggestions: setShareCommentsAndSuggestions, expirationDays: expirationDays, setExpirationDays: setExpirationDays, showSecretFields: showSecretFields, setShowSecretFields: setShowSecretFields, secret: secret, setSecret: setSecret, secretConfirm: secretConfirm, setSecretConfirm: setSecretConfirm }));
            case "confirm":
                return (_jsx(CreateReviewConfirmStep, { title: title, setTitle: setTitle, isGeneratingTitle: isGeneratingTitle, languageSummary: languageSummary, reviewers: reviewers, items: items, requiredApprovals: requiredApprovals, updateWorkflowOnCompletion: updateWorkflowOnCompletion, expirationDays: expirationDays, showSecretFields: showSecretFields }));
        }
    };
    return (_jsx(Dialog, { open: open, onOpenChange: handleDialogOpenChange, children: _jsxs(DialogContent, { className: "flex max-h-[900px] min-h-0 max-w-5xl flex-col overflow-visible", "data-testid": "create-review-dialog", onPointerDownOutside: (e) => e.preventDefault(), "aria-describedby": "create-review-wizard-description", style: {
                width: "min(90vw, 1280px)",
                height: "min(85vh, 900px)",
            }, children: [_jsx(StyledDialogTitle, { icon: showSuccess ? (_jsx(CheckCircle2, { strokeWidth: 1 })) : (_jsx(ClipboardCheck, { strokeWidth: 1 })), title: showSuccess
                        ? "Review Created"
                        : `Request a review · ${currentStep.name}`, subtitle: showSuccess
                        ? "Invitation emails have been sent"
                        : currentStep.description }), _jsx("div", { id: "create-review-wizard-description", className: "sr-only", children: currentStep.description }), _jsxs("div", { className: "flex min-h-0 flex-1 flex-col", children: [_jsx("div", { className: "min-h-0 flex-1 overflow-y-auto", "data-testid": "create-review-step-content", children: showSuccess ? (_jsx(CreateReviewSuccessStep, { sentInvitationCount: sentInvitationCount, sentInvitationEmails: sentInvitationEmails })) : (_jsx("div", { className: "relative h-full", children: WIZARD_STEPS.map((step, index) => {
                                    const isActive = index === stepIndex;
                                    return (_jsx("div", { className: "h-full", style: { display: isActive ? "block" : "none" }, "aria-hidden": !isActive, "data-testid": `step-content-${step.id}`, children: renderStepContent(step.id) }, step.id));
                                }) })) }), !showSuccess && error && (_jsx("div", { className: "border-border-default shrink-0 border-t bg-white px-6 py-3", children: _jsx("div", { role: "alert", className: "border-destructive/20 bg-destructive/10 text-destructive rounded-xl border p-4 text-sm font-medium shadow-sm", children: _jsxs("div", { className: "flex gap-3", children: [_jsx(AlertTriangle, { strokeWidth: 1, className: "h-5 w-5 shrink-0" }), _jsx("p", { children: error })] }) }) })), _jsx(DialogButtons, { "data-testid": "create-review-dialog-buttons", className: "rounded-b-2xl", children: showSuccess ? (_jsx(Button, { onClick: handleDone, className: "min-w-[120px] shadow-sm", children: "Done" })) : (_jsxs(_Fragment, { children: [_jsx(Button, { variant: "ghost", onClick: handleDialogCancel, disabled: loading, className: "w-auto min-w-24 flex-none", "data-testid": "create-review-cancel-button", children: "Cancel" }), _jsxs("div", { className: "ml-auto flex min-w-0 flex-wrap items-center justify-end gap-3", children: [stepIndex > 0 && (_jsx(Button, { onClick: handlePrevious, variant: "outline", disabled: loading, className: "w-auto min-w-32 flex-none", "data-testid": "create-review-previous-button", children: "Previous" })), _jsx(Button, { onClick: handleNext, disabled: !canProceed || loading, className: "w-auto min-w-40 flex-none gap-2 shadow-sm", "data-testid": isLastStep
                                                    ? "create-review-submit-button"
                                                    : "create-review-next-button", children: isLastStep ? (loading ? (_jsxs(_Fragment, { children: [_jsx(Loader2, { strokeWidth: 1, className: "mr-2 h-4 w-4 animate-spin" }), "Creating..."] })) : ("Create & Send Emails")) : (_jsxs(_Fragment, { children: [nextStep?.nextButtonLabel ?? "Next", _jsx(ArrowRight, { className: "h-4 w-4", strokeWidth: 1 })] })) })] })] })) })] }), !showSuccess && (_jsx(StepIndicatorDots, { steps: WIZARD_STEPS, currentStepIndex: stepIndex }))] }) }));
}
//# sourceMappingURL=CreateReviewDialog.js.map