import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { useState, useEffect, useRef } from "react";
import { useEditContext } from "../client/editContext";
import { Card } from "../../components/ui/card";
import { SettingsPanelLayout } from "./SettingsPanelLayout";
import { version, buildDate } from "../../revision";
import { Info as InfoIcon, Package, FileText, Code, Mail, CheckCircle2, Calendar, Building2, Edit, Users, KeyRound, Globe, } from "lucide-react";
import { useLicense } from "../../licensing";
import { Dialog, DialogContent, DialogTitle } from "../../components/ui/dialog";
import { EmailEntry } from "../../licensing/EmailEntry";
import { LicenseActivationForm } from "../../licensing/LicenseActivationForm";
import { LicenseCodeEntry } from "../../licensing/LicenseCodeEntry";
import { requestLicense, verifyActivationCode, storeLicense, clearLicenseCache, formatRetryTimeSimple, } from "../../licensing/licenseService";
import { setupWizardService } from "../../setup/services/setupWizardService";
const thirdPartyComponents = [
    {
        name: "React",
        license: "MIT License",
        description: "A JavaScript library for building user interfaces and DOM rendering.",
    },
    {
        name: "Vite",
        license: "MIT License",
        description: "Frontend build tooling used for the Vite application shell.",
    },
    {
        name: "TypeScript",
        license: "Apache-2.0 License",
        description: "A typed language for application-scale JavaScript development.",
    },
    {
        name: "Tailwind CSS",
        license: "MIT License",
        description: "Utility-first styling tools for building the Parhelia interface.",
    },
    {
        name: "PostCSS",
        license: "MIT License",
        description: "CSS transformation tooling used by the frontend build.",
    },
    {
        name: "Radix UI",
        license: "MIT License",
        description: "Accessible low-level React primitives for dialogs, menus, popovers, and controls.",
    },
    {
        name: "Lucide React",
        license: "ISC License",
        description: "Icon toolkit used throughout the Parhelia interface.",
    },
    {
        name: "Dagre",
        license: "MIT License",
        description: "Graph layout algorithms for JavaScript.",
    },
    {
        name: "XYFlow",
        license: "MIT License",
        description: "React library for node-based editors and interactive flow charts.",
    },
    {
        name: "GraphiQL",
        license: "MIT License",
        description: "GraphQL explorer and query interface components.",
    },
    {
        name: "GraphQL",
        license: "MIT License",
        description: "GraphQL language, schema, and query utilities.",
    },
    {
        name: "Axios",
        license: "MIT License",
        description: "Promise-based HTTP client for browsers and Node.js.",
    },
    {
        name: "follow-redirects",
        license: "MIT License",
        description: "HTTP and HTTPS helpers that follow redirects.",
    },
    {
        name: "DOMPurify",
        license: "MPL-2.0 or Apache-2.0 License",
        description: "HTML, MathML, and SVG sanitizer for browser content.",
    },
    {
        name: "html2canvas-pro",
        license: "MIT License",
        description: "Browser screenshot rendering for HTML content.",
    },
    {
        name: "Slate",
        license: "MIT License",
        description: "Customizable framework for rich text editing.",
    },
    {
        name: "UIW React Textarea Code Editor",
        license: "MIT License",
        description: "Textarea-based React code editor with syntax highlighting.",
    },
    {
        name: "React Inspector",
        license: "MIT License",
        description: "Developer-tool style inspectors rendered inside React applications.",
    },
    {
        name: "react-json-view-lite",
        license: "MIT License",
        description: "Lightweight JSON viewer component for React.",
    },
    {
        name: "react-json-pretty",
        license: "MIT License",
        description: "JSON formatting and display components for React.",
    },
    {
        name: "cmdk",
        license: "MIT License",
        description: "Composable command menu primitives for React.",
    },
    {
        name: "date-fns",
        license: "MIT License",
        description: "Modern JavaScript date utility library.",
    },
    {
        name: "react-day-picker",
        license: "MIT License",
        description: "Customizable date picker component for React.",
    },
    {
        name: "Sonner",
        license: "MIT License",
        description: "Toast notification component for React.",
    },
    {
        name: "class-variance-authority",
        license: "Apache-2.0 License",
        description: "Utilities for type-safe UI component variants.",
    },
    {
        name: "clsx",
        license: "MIT License",
        description: "Small utility for conditionally constructing className strings.",
    },
    {
        name: "diff",
        license: "BSD 3-Clause License",
        description: "JavaScript text diff implementation.",
    },
    {
        name: "html-entities",
        license: "MIT License",
        description: "HTML entity encoding and decoding utilities.",
    },
    {
        name: "morphdom",
        license: "MIT License",
        description: "Fast DOM tree diffing and patching.",
    },
    {
        name: "tailwind-merge",
        license: "MIT License",
        description: "Tailwind CSS class merging without style conflicts.",
    },
    {
        name: "tw-animate-css",
        license: "MIT License",
        description: "Animation utilities compatible with Tailwind CSS.",
    },
    {
        name: "Universal Cookie",
        license: "MIT License",
        description: "Universal cookie helpers for JavaScript applications.",
    },
    {
        name: "use-debounce",
        license: "MIT License",
        description: "React hooks for debouncing values and callbacks.",
    },
    {
        name: "react-uuid",
        license: "MIT License",
        description: "Unique identifier helper for React applications.",
    },
];
export function About() {
    const editContext = useEditContext();
    const license = useLicense();
    const editLicenseButtonRef = useRef(null);
    const [showLicenseDialog, setShowLicenseDialog] = useState(false);
    const [dialogState, setDialogState] = useState("email_entry");
    const [dialogError, setDialogError] = useState();
    const [dialogEmail, setDialogEmail] = useState("");
    const [dialogRetryAfterSeconds, setDialogRetryAfterSeconds] = useState();
    const [editLicenseHighlight, setEditLicenseHighlight] = useState(false);
    // Refresh license status when About is shown and poll while open so active user count stays current
    const refreshLicenseStatus = license.refreshLicenseStatus;
    useEffect(() => {
        refreshLicenseStatus();
        const intervalMs = 45_000; // 45 seconds
        const interval = setInterval(refreshLicenseStatus, intervalMs);
        return () => clearInterval(interval);
    }, [refreshLicenseStatus]);
    // When navigated from status warning (hash #edit-license), scroll to and highlight the Edit license button
    useEffect(() => {
        if (typeof window === "undefined")
            return;
        const run = () => {
            const hash = window.location.hash?.replace(/^#/, "") || "";
            if (hash !== "edit-license")
                return;
            editLicenseButtonRef.current?.scrollIntoView({
                behavior: "smooth",
                block: "center",
            });
            setEditLicenseHighlight(true);
            const t = setTimeout(() => setEditLicenseHighlight(false), 2500);
            return t;
        };
        let t;
        t = run();
        const onHashChange = () => {
            if (t)
                clearTimeout(t);
            t = run();
        };
        window.addEventListener("hashchange", onHashChange);
        return () => {
            window.removeEventListener("hashchange", onHashChange);
            if (t)
                clearTimeout(t);
        };
    }, []);
    // Handle email check (determines if trial or code is needed)
    const handleEmailCheck = async (email) => {
        setDialogState("loading");
        setDialogError(undefined);
        setDialogEmail(email);
        setDialogRetryAfterSeconds(undefined);
        try {
            // Submit email with placeholder name/company to check license availability
            const response = await requestLicense({
                email,
                name: "Temporary", // Placeholder - will be replaced when trial form is submitted
                companyName: "Temporary", // Placeholder - will be replaced when trial form is submitted
                parheliaBuildDate: license.licenseStatus?.buildDate || "",
            });
            switch (response.status) {
                case "trial": {
                    const complete = response.license && response.requiresProfileCompletion === false;
                    if (complete) {
                        try {
                            const settingsExist = await setupWizardService.getSettingsExists();
                            if (!settingsExist) {
                                await setupWizardService.createSettingsItem();
                            }
                            const storeResult = await storeLicense(response.license, response.signature);
                            if (storeResult.success) {
                                try {
                                    await clearLicenseCache();
                                }
                                catch (err) {
                                    console.warn("Failed to clear license cache:", err);
                                }
                                await new Promise((resolve) => setTimeout(resolve, 100));
                                await license.refreshLicenseStatus();
                                setDialogRetryAfterSeconds(undefined);
                                setDialogState("welcome_back");
                                setTimeout(() => {
                                    setShowLicenseDialog(false);
                                    setDialogState("email_entry");
                                }, 2000);
                            }
                            else {
                                setDialogError(storeResult.message || "Failed to store license");
                                setDialogState("trial_form");
                            }
                        }
                        catch (e) {
                            console.error("Welcome-back license store failed:", e);
                            setDialogError("Failed to store license");
                            setDialogState("email_entry");
                        }
                    }
                    else {
                        setDialogState("trial_form");
                    }
                    break;
                }
                case "code_sent":
                    // One-time code sent, show code entry form
                    setDialogRetryAfterSeconds(undefined);
                    setDialogState("code");
                    break;
                case "trial_expired":
                    setDialogError("Your trial period has ended. Please contact sales to purchase a license.");
                    setDialogState("email_entry");
                    break;
                case "rate_limited":
                    setDialogRetryAfterSeconds(response.retryAfterSeconds || 60);
                    setDialogError(`Too many requests for sending a new code. If you already have a code, enter it now. Otherwise try again in ${formatRetryTimeSimple(response.retryAfterSeconds || 60)}.`);
                    setDialogState("code");
                    break;
                case "error":
                    setDialogRetryAfterSeconds(undefined);
                    setDialogError(response.message || "An error occurred");
                    setDialogState("email_entry");
                    break;
            }
        }
        catch (error) {
            console.error("Email check failed:", error);
            setDialogRetryAfterSeconds(undefined);
            setDialogError("Failed to contact license server");
            setDialogState("email_entry");
        }
    };
    // Handle license request submission
    const handleLicenseRequest = async (email, name, companyName) => {
        setDialogState("loading");
        setDialogError(undefined);
        setDialogEmail(email);
        setDialogRetryAfterSeconds(undefined);
        try {
            const response = await requestLicense({
                email,
                name,
                companyName,
                parheliaBuildDate: license.licenseStatus?.buildDate || "",
            });
            switch (response.status) {
                case "trial":
                    // Got a trial license, store it
                    if (response.license) {
                        const settingsExist = await setupWizardService.getSettingsExists();
                        if (!settingsExist) {
                            await setupWizardService.createSettingsItem();
                        }
                        const storeResult = await storeLicense(response.license, response.signature);
                        if (storeResult.success) {
                            // Clear the backend cache and refresh status
                            try {
                                await clearLicenseCache();
                            }
                            catch (err) {
                                console.warn("Failed to clear license cache:", err);
                            }
                            // Wait a bit for the backend to process
                            await new Promise((resolve) => setTimeout(resolve, 100));
                            await license.refreshLicenseStatus();
                            setDialogRetryAfterSeconds(undefined);
                            setDialogState("success");
                            setTimeout(() => {
                                setShowLicenseDialog(false);
                                setDialogState("email_entry");
                            }, 2000);
                        }
                        else {
                            setDialogError(storeResult.message || "Failed to store license");
                            setDialogState("trial_form");
                        }
                    }
                    break;
                case "code_sent":
                    // One-time code sent, show code entry form
                    setDialogRetryAfterSeconds(undefined);
                    setDialogState("code");
                    break;
                case "trial_expired":
                    setDialogError("Your trial period has ended. Please contact sales to purchase a license.");
                    setDialogState("trial_form");
                    break;
                case "rate_limited":
                    setDialogRetryAfterSeconds(response.retryAfterSeconds || 60);
                    setDialogError(`Too many requests. Please try again in ${response.retryAfterSeconds || 60} seconds.`);
                    setDialogState("trial_form");
                    break;
                case "error":
                    setDialogRetryAfterSeconds(undefined);
                    setDialogError(response.message || "An error occurred");
                    setDialogState("trial_form");
                    break;
            }
        }
        catch (error) {
            console.error("License request failed:", error);
            setDialogRetryAfterSeconds(undefined);
            setDialogError("Failed to contact license server");
            setDialogState("trial_form");
        }
    };
    // Handle activation code submission
    const handleActivationCode = async (code) => {
        setDialogState("loading");
        setDialogError(undefined);
        setDialogRetryAfterSeconds(undefined);
        try {
            const response = await verifyActivationCode({
                email: dialogEmail,
                code,
            });
            switch (response.status) {
                case "purchased":
                    // Got a purchased license, store it
                    if (response.license) {
                        const settingsExist = await setupWizardService.getSettingsExists();
                        if (!settingsExist) {
                            await setupWizardService.createSettingsItem();
                        }
                        const storeResult = await storeLicense(response.license, response.signature);
                        if (storeResult.success) {
                            // Clear the backend cache and refresh status
                            try {
                                await clearLicenseCache();
                            }
                            catch (err) {
                                console.warn("Failed to clear license cache:", err);
                            }
                            // Wait a bit for the backend to process
                            await new Promise((resolve) => setTimeout(resolve, 100));
                            await license.refreshLicenseStatus();
                            setDialogRetryAfterSeconds(undefined);
                            setDialogState("success");
                            setTimeout(() => {
                                setShowLicenseDialog(false);
                                setDialogState("email_entry");
                            }, 2000);
                        }
                        else {
                            setDialogError(storeResult.message || "Failed to store license");
                            setDialogState("code");
                        }
                    }
                    break;
                case "invalid_code":
                    setDialogRetryAfterSeconds(undefined);
                    setDialogError(response.message || "Invalid activation code");
                    setDialogState("code");
                    break;
                case "rate_limited":
                    setDialogRetryAfterSeconds(response.retryAfterSeconds || 60);
                    setDialogError(response.message ||
                        `Too many incorrect activation code attempts. Try again in ${formatRetryTimeSimple(response.retryAfterSeconds || 60)}.`);
                    setDialogState("code");
                    break;
                case "error":
                    setDialogRetryAfterSeconds(undefined);
                    setDialogError(response.message || "An error occurred");
                    setDialogState("code");
                    break;
            }
        }
        catch (error) {
            console.error("Activation code verification failed:", error);
            setDialogRetryAfterSeconds(undefined);
            setDialogError("Failed to verify activation code");
            setDialogState("code");
        }
    };
    // Helper to check if dialog can be closed (only when there's a valid license)
    const canCloseDialog = () => {
        return (license?.isLicensed &&
            license?.licenseStatus?.status !== "invalid" &&
            license?.licenseStatus?.status !== "no_license");
    };
    return (_jsxs(SettingsPanelLayout, { contentClassName: "flex flex-col gap-4", children: [_jsx(Card, { icon: _jsx(Package, { strokeWidth: 1, className: "h-5 w-5" }), title: "Version information", description: "The installed Parhelia build and release date.", children: _jsxs("div", { className: "grid grid-cols-1 gap-6 md:grid-cols-2", children: [_jsxs("div", { className: "space-y-1.5", children: [_jsxs("div", { className: "text-neutral-grey-50 flex items-center gap-2 text-sm font-medium", children: [_jsx(InfoIcon, { className: "h-4 w-4", strokeWidth: 1.5 }), _jsx("span", { children: "Version" })] }), _jsx("p", { className: "text-neutral-grey-100 text-base", children: version })] }), _jsxs("div", { className: "space-y-1.5", children: [_jsxs("div", { className: "text-neutral-grey-50 flex items-center gap-2 text-sm font-medium", children: [_jsx(Code, { className: "h-4 w-4", strokeWidth: 1.5 }), _jsx("span", { children: "Build Date" })] }), _jsx("p", { className: "text-neutral-grey-100 text-base", children: buildDate })] })] }) }), !license?.licenseStatus?.licensingDisabled && (_jsx(Card, { icon: _jsx(FileText, { strokeWidth: 1, className: "h-5 w-5" }), title: "License information", description: "Your current Parhelia license and its limits.", children: _jsxs("div", { className: "space-y-6", children: [_jsxs("div", { className: "space-y-1.5", children: [_jsxs("div", { className: "text-neutral-grey-50 flex items-center gap-2 text-sm font-medium", children: [_jsx(FileText, { className: "h-4 w-4", strokeWidth: 1.5 }), _jsx("span", { children: "Copyright" })] }), _jsxs("p", { className: "text-neutral-grey-100 text-base", children: ["\u00A9 ", new Date().getFullYear(), " Canvas Reply GmbH"] })] }), license?.isLicensed ? (_jsxs(_Fragment, { children: [_jsxs("div", { className: "space-y-1.5", children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsxs("div", { className: "text-neutral-grey-50 flex items-center gap-2 text-sm font-medium", children: [_jsx(CheckCircle2, { className: "h-4 w-4", strokeWidth: 1.5 }), _jsx("span", { children: "License Status" })] }), _jsxs("button", { id: "edit-license", ref: editLicenseButtonRef, onClick: () => {
                                                        setDialogState("email_entry");
                                                        setDialogError(undefined);
                                                        setDialogEmail("");
                                                        setShowLicenseDialog(true);
                                                    }, className: `flex items-center gap-1.5 rounded-md px-2 py-1.5 text-sm font-medium transition-colors ${editLicenseHighlight
                                                        ? "ring-feedback-orange bg-feedback-orange-light text-feedback-orange ring-2 ring-offset-2"
                                                        : "text-neutral-grey-100 hover:bg-neutral-grey-5"}`, title: "Change license", children: [_jsx(Edit, { className: "h-3.5 w-3.5", strokeWidth: 1.5 }), _jsx("span", { children: "Edit" })] })] }), _jsx("div", { className: "flex items-center gap-2", children: _jsx("p", { className: "text-neutral-grey-100 text-base capitalize", children: license.licenseType === "trial"
                                                    ? "Trial License"
                                                    : license.licenseType === "purchased"
                                                        ? "Purchased License"
                                                        : "License" }) }), !license?.isLicensed && license?.licenseStatus?.message && (_jsx("p", { className: "text-feedback-orange mt-1 text-sm", children: license.licenseStatus.message }))] }), license.licenseStatus?.companyName && (_jsxs("div", { className: "space-y-1.5", children: [_jsxs("div", { className: "text-neutral-grey-50 flex items-center gap-2 text-sm font-medium", children: [_jsx(Building2, { className: "h-4 w-4", strokeWidth: 1.5 }), _jsx("span", { children: "Company" })] }), _jsx("p", { className: "text-neutral-grey-100 text-base", children: license.licenseStatus.companyName })] })), _jsxs("div", { className: "space-y-1.5", children: [_jsxs("div", { className: "text-neutral-grey-50 flex items-center gap-2 text-sm font-medium", children: [_jsx(Calendar, { className: "h-4 w-4", strokeWidth: 1.5 }), _jsx("span", { children: "Expires" })] }), _jsx("p", { className: "text-neutral-grey-100 text-base", children: license.expiresAt ? (_jsxs(_Fragment, { children: [license.expiresAt.toLocaleDateString(), license.daysRemaining !== undefined &&
                                                        license.daysRemaining !== null && (_jsxs("span", { className: `ml-2 text-sm ${license.daysRemaining <= 0
                                                            ? "text-feedback-red font-medium"
                                                            : license.daysRemaining <= 7
                                                                ? "text-feedback-orange"
                                                                : "text-neutral-grey-50"}`, children: ["(", license.daysRemaining === 0
                                                                ? "Expired"
                                                                : license.daysRemaining < 0
                                                                    ? `${Math.abs(license.daysRemaining)} days ago`
                                                                    : `${license.daysRemaining} ${license.daysRemaining === 1 ? "day" : "days"} remaining`, ")"] }))] })) : ("Unlimited") })] }), license.features && license.features.length > 0 && (_jsxs("div", { className: "space-y-1.5", children: [_jsxs("div", { className: "text-neutral-grey-50 flex items-center gap-2 text-sm font-medium", children: [_jsx(Package, { className: "h-4 w-4", strokeWidth: 1.5 }), _jsx("span", { children: "Features" })] }), _jsx("div", { className: "flex flex-wrap gap-2", children: license.features.map((feature) => (_jsx("span", { className: "bg-feedback-blue-light badge-pad text-feedback-blue inline-flex items-center rounded-md text-sm font-medium", children: feature }, feature))) })] })), _jsxs("div", { className: "space-y-1.5", children: [_jsxs("div", { className: "text-neutral-grey-50 flex items-center gap-2 text-sm font-medium", children: [_jsx(Users, { className: "h-4 w-4", strokeWidth: 1.5 }), _jsx("span", { children: "Max Concurrent Users" })] }), _jsx("p", { className: "text-neutral-grey-100 text-base", children: license.licenseStatus?.maxConcurrentUsers !== undefined &&
                                                license.licenseStatus.maxConcurrentUsers !== null
                                                ? license.licenseStatus.maxConcurrentUsers
                                                : "Unlimited" })] }), _jsxs("div", { className: "space-y-1.5", children: [_jsxs("div", { className: "text-neutral-grey-50 flex items-center gap-2 text-sm font-medium", children: [_jsx(Users, { className: "h-4 w-4", strokeWidth: 1.5 }), _jsx("span", { children: license.licenseStatus?.maxConcurrentUsers !==
                                                        undefined &&
                                                        license.licenseStatus?.maxConcurrentUsers !== null
                                                        ? "Currently active"
                                                        : "Active users" })] }), _jsx("p", { className: "text-neutral-grey-100 text-base", children: license.licenseStatus?.maxConcurrentUsers !== undefined &&
                                                license.licenseStatus?.maxConcurrentUsers !== null
                                                ? `${license.licenseStatus?.currentLicenseUserCount ?? 0} of ${license.licenseStatus.maxConcurrentUsers}`
                                                : (license.licenseStatus?.currentLicenseUserCount ?? 0) })] })] })) : (
                        /* No license - show generic message */
                        _jsxs("div", { className: "space-y-1.5", children: [_jsxs("div", { className: "text-neutral-grey-50 flex items-center gap-2 text-sm font-medium", children: [_jsx(FileText, { className: "h-4 w-4", strokeWidth: 1.5 }), _jsx("span", { children: "License" })] }), _jsx("p", { className: "text-neutral-grey-100 text-base", children: "All rights reserved. Please contact Canvas Reply GmbH for licensing information." })] }))] }) })), _jsx(Card, { icon: _jsx(Code, { strokeWidth: 1, className: "h-5 w-5" }), title: "Third-party components", description: "Open-source libraries bundled with Parhelia and their licenses.", children: _jsx("div", { className: "max-h-96 space-y-3 overflow-y-auto", children: thirdPartyComponents.map((component) => (_jsxs("div", { className: "bg-neutral-grey-5 rounded-lg p-3", children: [_jsxs("div", { className: "mb-2 flex items-center justify-between gap-3", children: [_jsx("h4", { className: "text-neutral-grey-100 text-sm font-medium", children: component.name }), _jsx("span", { className: "text-neutral-grey-50 shrink-0 text-xs", children: component.license })] }), _jsx("p", { className: "text-neutral-grey-50 text-xs", children: component.description })] }, component.name))) }) }), _jsx(Card, { icon: _jsx(Mail, { strokeWidth: 1, className: "h-5 w-5" }), title: "Contact & support", description: "How to reach Canvas Reply for help and licensing.", children: _jsxs("div", { className: "space-y-6", children: [_jsxs("div", { className: "space-y-1.5", children: [_jsxs("div", { className: "text-neutral-grey-50 flex items-center gap-2 text-sm font-medium", children: [_jsx(Building2, { className: "h-4 w-4", strokeWidth: 1.5 }), _jsx("span", { children: "Company" })] }), _jsx("p", { className: "text-neutral-grey-100 text-base", children: "Canvas Reply GmbH" })] }), _jsxs("div", { className: "space-y-1.5", children: [_jsxs("div", { className: "text-neutral-grey-50 flex items-center gap-2 text-sm font-medium", children: [_jsx(Globe, { className: "h-4 w-4", strokeWidth: 1.5 }), _jsx("span", { children: "Parhelia" })] }), _jsx("p", { className: "text-neutral-grey-100 text-base", children: _jsx("a", { href: "https://parhelia.ai/", target: "_blank", rel: "noopener noreferrer", className: "text-feedback-blue hover:text-feedback-blue underline", children: "parhelia.ai" }) })] }), _jsxs("div", { className: "space-y-1.5", children: [_jsxs("div", { className: "text-neutral-grey-50 flex items-center gap-2 text-sm font-medium", children: [_jsx(FileText, { className: "h-4 w-4", strokeWidth: 1.5 }), _jsx("span", { children: "Website" })] }), _jsx("p", { className: "text-neutral-grey-100 text-base", children: _jsx("a", { href: "https://canvasreply.de/", target: "_blank", rel: "noopener noreferrer", className: "text-feedback-blue hover:text-feedback-blue underline", children: "canvasreply.de" }) })] })] }) }), _jsx(Dialog, { open: showLicenseDialog, onOpenChange: (open) => {
                    // Only allow closing if there's a valid license
                    if (!open && !canCloseDialog()) {
                        // Don't allow closing when there's no license or invalid license
                        return;
                    }
                    setShowLicenseDialog(open);
                    if (!open) {
                        setDialogState("email_entry");
                        setDialogError(undefined);
                        setDialogEmail("");
                        setDialogRetryAfterSeconds(undefined);
                    }
                }, children: _jsxs(DialogContent, { className: "w-full max-w-2xl overflow-hidden rounded-2xl border-none bg-white p-0 shadow-2xl", overlayClassName: "bg-neutral-grey-100/40 backdrop-blur-sm", showCloseButton: canCloseDialog(), onInteractOutside: (e) => {
                        // Prevent closing when clicking outside if there's no license or invalid license
                        if (!canCloseDialog()) {
                            e.preventDefault();
                        }
                    }, onPointerDownOutside: (e) => {
                        // Prevent closing when clicking outside if there's no license or invalid license
                        if (!canCloseDialog()) {
                            e.preventDefault();
                        }
                    }, children: [_jsx("div", { className: "bg-neutral-grey-5 h-1 w-full", children: _jsx("div", { className: "bg-feedback-blue h-full w-full" }) }), _jsxs("div", { className: "flex min-h-[520px] flex-col items-center justify-center p-12", children: [_jsx(DialogTitle, { className: "sr-only", children: "Change License" }), (dialogState === "email_entry" ||
                                    dialogState === "trial_form" ||
                                    dialogState === "code" ||
                                    dialogState === "loading") && (_jsx("div", { className: "bg-feedback-blue-light ring-feedback-blue mb-8 rounded-2xl p-6 ring-1", children: _jsx(KeyRound, { className: "text-feedback-blue h-16 w-12", strokeWidth: 1.5 }) })), dialogState === "email_entry" && (_jsx(EmailEntry, { onSubmit: handleEmailCheck, error: dialogError })), dialogState === "trial_form" && (_jsx(LicenseActivationForm, { email: dialogEmail, onSubmit: handleLicenseRequest, onBack: () => {
                                        setDialogState("email_entry");
                                        setDialogError(undefined);
                                        setDialogRetryAfterSeconds(undefined);
                                    }, error: dialogError })), dialogState === "code" && (_jsx(LicenseCodeEntry, { email: dialogEmail, onSubmit: handleActivationCode, onBack: () => {
                                        setDialogState("email_entry");
                                        setDialogError(undefined);
                                        setDialogRetryAfterSeconds(undefined);
                                    }, error: dialogError, retryAfterSeconds: dialogRetryAfterSeconds })), dialogState === "loading" && (_jsxs("div", { className: "text-neutral-grey-50 flex flex-col items-center gap-3", children: [_jsx("div", { className: "border-feedback-blue h-12 w-12 animate-spin rounded-full border-4 border-t-transparent" }), _jsx("p", { className: "text-sm font-medium", children: "Processing..." })] })), dialogState === "welcome_back" && (_jsxs("div", { className: "text-feedback-green animate-in fade-in zoom-in flex flex-col items-center gap-3 duration-500", children: [_jsx("div", { className: "bg-feedback-green-light rounded-full p-3", children: _jsx(CheckCircle2, { className: "h-10 w-10", strokeWidth: 2 }) }), _jsx("h2", { className: "text-neutral-grey-100 text-xl font-semibold", children: "Welcome back" }), _jsx("p", { className: "text-neutral-grey-50 text-center", children: "Your trial is active again on this environment." })] })), dialogState === "success" && (_jsxs("div", { className: "text-feedback-green animate-in fade-in zoom-in flex flex-col items-center gap-3 duration-500", children: [_jsx("div", { className: "bg-feedback-green-light rounded-full p-3", children: _jsx(CheckCircle2, { className: "h-10 w-10", strokeWidth: 2 }) }), _jsx("h2", { className: "text-neutral-grey-100 text-xl font-semibold", children: "License Activated" }), _jsx("p", { className: "text-neutral-grey-50 text-center", children: "Your license has been successfully updated." })] }))] })] }) })] }));
}
//# sourceMappingURL=About.js.map