import { useTranslation } from "react-i18next"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, } from "@/components/ui/dialog"; import { Label } from "@/components/ui/label"; import { Button } from "@/components/ui/button"; import { Save, Wand2 } from "lucide-react"; import { toast } from "sonner"; import { formatJSON } from "@/utils/formatters"; interface CommonConfigEditorProps { value: string; onChange: (value: string) => void; useCommonConfig: boolean; onCommonConfigToggle: (checked: boolean) => void; commonConfigSnippet: string; onCommonConfigSnippetChange: (value: string) => void; commonConfigError: string; onEditClick: () => void; isModalOpen: boolean; onModalClose: () => void; } export function CommonConfigEditor({ value, onChange, useCommonConfig, onCommonConfigToggle, commonConfigSnippet, onCommonConfigSnippetChange, commonConfigError, onEditClick, isModalOpen, onModalClose, }: CommonConfigEditorProps) { const { t } = useTranslation(); const handleFormatMain = () => { if (!value.trim()) return; try { const formatted = formatJSON(value); onChange(formatted); toast.success(t("common.formatSuccess", { defaultValue: "格式化成功" })); } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); toast.error( t("common.formatError", { defaultValue: "格式化失败:{{error}}", error: errorMessage, }), ); } }; const handleFormatModal = () => { if (!commonConfigSnippet.trim()) return; try { const formatted = formatJSON(commonConfigSnippet); onCommonConfigSnippetChange(formatted); toast.success(t("common.formatSuccess", { defaultValue: "格式化成功" })); } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); toast.error( t("common.formatError", { defaultValue: "格式化失败:{{error}}", error: errorMessage, }), ); } }; return ( <>
{commonConfigError}
)}