import React, { useState } from "react"; import { ArrowLeft } from "lucide-react"; import { IpcClient } from "@/ipc/ipc_client"; import { useSettings } from "@/hooks/useSettings"; import { CommunityCodeConsentDialog } from "./CommunityCodeConsentDialog"; import type { Template } from "@/shared/templates"; import { Button } from "./ui/button"; import { cn } from "@/lib/utils"; import { showWarning } from "@/lib/toast"; interface TemplateCardProps { template: Template; isSelected: boolean; onSelect: (templateId: string) => void; onCreateApp: () => void; } export const TemplateCard: React.FC = ({ template, isSelected, onSelect, onCreateApp, }) => { const { settings, updateSettings } = useSettings(); const [showConsentDialog, setShowConsentDialog] = useState(false); const handleCardClick = () => { // If it's a community template and user hasn't accepted community code yet, show dialog if (!template.isOfficial && !settings?.acceptedCommunityCode) { setShowConsentDialog(true); return; } if (template.requiresNeon && !settings?.neon?.accessToken) { showWarning("Please connect your Neon account to use this template."); return; } // Otherwise, proceed with selection onSelect(template.id); }; const handleConsentAccept = () => { // Update settings to accept community code updateSettings({ acceptedCommunityCode: true }); // Select the template onSelect(template.id); // Close dialog setShowConsentDialog(false); }; const handleConsentCancel = () => { // Just close dialog, don't update settings or select template setShowConsentDialog(false); }; const handleGithubClick = (e: React.MouseEvent) => { e.stopPropagation(); if (template.githubUrl) { IpcClient.getInstance().openExternalUrl(template.githubUrl); } }; return ( <>
{template.title} {isSelected && ( Selected )}

{template.title}

{template.isOfficial && !template.isExperimental && ( Official )} {template.isExperimental && ( Experimental )}

{template.description}

{template.githubUrl && ( View on GitHub{" "} )}
); };