"use client"; import { useEffect, useState } from "react"; import { Checkbox } from "@app/components/ui/checkbox"; import { FormLabel } from "@app/components/ui/form"; import { TagInput, type Tag } from "@app/components/tags/tag-input"; import { useTranslations } from "next-intl"; type VirtualApiKeyEmailSectionProps = { emailEnabled: boolean; mode: "create" | "edit"; sendEmail: boolean; onSendEmailChange: (value: boolean) => void; sendToAttributedUser: boolean; onSendToAttributedUserChange: (value: boolean) => void; hasAssociatedUser: boolean; emailTags: Tag[]; onEmailTagsChange: (tags: Tag[]) => void; }; export default function VirtualApiKeyEmailSection({ emailEnabled, mode, sendEmail, onSendEmailChange, sendToAttributedUser, onSendToAttributedUserChange, hasAssociatedUser, emailTags, onEmailTagsChange }: VirtualApiKeyEmailSectionProps) { const t = useTranslations(); const [activeEmailTagIndex, setActiveEmailTagIndex] = useState< number | null >(null); useEffect(() => { if (!hasAssociatedUser && sendToAttributedUser) { onSendToAttributedUserChange(false); } }, [hasAssociatedUser, sendToAttributedUser, onSendToAttributedUserChange]); const checkboxId = mode === "create" ? "virtual-api-key-send-email" : "edit-virtual-api-key-send-email"; const sendToUserId = mode === "create" ? "virtual-api-key-send-to-user" : "edit-virtual-api-key-send-to-user"; return (
{ if (emailEnabled) { onSendEmailChange(val === true); } }} className="mt-0.5" />

{emailEnabled ? t( mode === "create" ? "virtualApiKeysEmailOnGenerateDescription" : "virtualApiKeysEmailThisKeyDescription" ) : t("virtualApiKeysEmailSmtpRequiredDescription")}

{emailEnabled && sendEmail && (
onSendToAttributedUserChange(val === true) } className="mt-0.5" />

{hasAssociatedUser ? t( "virtualApiKeysEmailSendToUserDescription" ) : t( "virtualApiKeysEmailSendToUserDisabled" )}

{t("virtualApiKeysEmailAdditional")} { const next = typeof newTags === "function" ? newTags(emailTags) : newTags; onEmailTagsChange(next as Tag[]); }} allowDuplicates={false} sortTags validateTag={(tag) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(tag) } delimiterList={[",", "Enter"]} />
)}
); }