"use client"; import React, { useEffect, useState } from "react"; import { Input, Button, AccordionItem, Accordion, Switch, } from "@nextui-org/react"; import { WechatConfig } from "@/types/payment"; import { useTranslation } from "@/shared/lib/useTranslation"; interface WechatConfigFormProps { config: WechatConfig; onSave: (config: WechatConfig) => void; onEnable: (channelId: string) => Promise; onDisable: (channelId: string) => Promise; isLoading?: boolean; } export const WechatConfigForm: React.FC = ({ config, onSave, onEnable, onDisable, isLoading = false, }) => { const { t } = useTranslation(); const [formData, setFormData] = useState(config); useEffect(() => { setFormData(config); }, [config]); const handleInputChange = ( field: keyof WechatConfig, value: string | boolean ) => { setFormData((prev) => ({ ...prev, [field]: value, })); }; const handleEnableDisable = async (value: boolean) => { let result: boolean | null = null; if (value) { result = await onEnable("wechat"); } else { result = await onDisable("wechat"); } if (result) { setFormData((prev) => ({ ...prev, is_enabled: value, })); } }; const handleSave = () => { onSave(formData); }; const isFormValid = formData.app_id.trim() !== "" && formData.mch_id.trim() !== ""; return (

{t("WeChat Configuration")}

{t("Configure WeChat payment interface")}

} >
{/* App ID */} handleInputChange("app_id", e.target.value)} isRequired autoComplete="off" isDisabled={!formData.is_enabled} /> {/* Merchant ID */} handleInputChange("mch_id", e.target.value)} isRequired autoComplete="off" isDisabled={!formData.is_enabled} />
{/* Action Buttons */} {formData.is_enabled && (
)}
); };