import type React from "react"; import { useEffect, useState } from "react"; import { Modal, Form, Select } from "antd"; import { useTranslation } from "react-i18next"; import GlobalFeatureStateCheck from "@/components/abp/features/state-check/global-feature-state-check"; import PermissionStateCheck from "@/components/abp/permissions/state-check/permission-state-check"; import FeatureStateCheck from "@/components/abp/features/state-check/feature-state-check"; interface SimpleStateCheckingModalProps { visible: boolean; onClose: () => void; onConfirm: (data: any) => void; record?: any; // The existing checker to edit options: { label: string; value: string; disabled: boolean }[]; } const SimpleStateCheckingModal: React.FC = ({ visible, onClose, onConfirm, record, options, }) => { const { t: $t } = useTranslation(); const [form] = Form.useForm(); const [selectedType, setSelectedType] = useState(); useEffect(() => { if (visible) { if (record) { // Map record back to form values const name = record.name; setSelectedType(name); let value = {}; switch (name) { case "F": value = { featureNames: record.featureNames, requiresAll: record.requiresAll }; break; case "G": value = { globalFeatureNames: record.globalFeatureNames, requiresAll: record.requiresAll }; break; case "P": value = { permissions: record.model?.permissions || record.permissions, requiresAll: record.requiresAll }; break; } form.setFieldsValue({ name: name, value: value, }); } else { form.resetFields(); setSelectedType(undefined); } } }, [visible, record, form]); const handleTypeChange = (val: string) => { setSelectedType(val); // Reset the value field when type changes let initialValue = {}; if (val === "F") initialValue = { featureNames: [], requiresAll: false }; if (val === "G") initialValue = { globalFeatureNames: [], requiresAll: false }; if (val === "P") initialValue = { permissions: [], requiresAll: false }; form.setFieldValue("value", initialValue); }; const handleSubmit = async () => { try { const values = await form.validateFields(); // Transform form values back to ABP simple state checker structure const result: any = { T: values.name, // T is usually the discriminator in some serializations, checking logic below }; // Mapping based on the Vue onSubmit logic: // A = RequiresAll (boolean) // T = Discriminator/Name // N = Names array const val = values.value || {}; const checkerObj: any = { name: values.name, // 'A' property seems to map to requiresAll for the checker itself requiresAll: val.requiresAll, }; // Specifically for serialization logic later // The Vue code returns: { A: boolean, T: string, N: string[] } const output: any = { A: val.requiresAll, T: values.name, }; switch (values.name) { case "F": output.N = val.featureNames; break; case "G": output.N = val.globalFeatureNames; break; case "P": output.N = val.permissions; break; } onConfirm(output); onClose(); } catch (e) { console.error(e); } }; return (