import useTranslation from "next-translate/useTranslation";
import { useRouter } from "next/router";
import {
CheckBoxfield,
DateFieldPicker,
DecimalField,
FieldArrayForm,
FileUploadField,
MultiLinefield,
NumericField,
PickList,
Radiofield,
ReadOnlyfield,
RichMultiLinefield,
Textfield,
YesNofield
} from "../elements";
export default function BuildField(props) {
const { t } = useTranslation();
const { locale } = useRouter();
// Destructure frequently used props for clarity
const {
fieldType,
label,
datafieldname,
picklistData,
validation,
hint,
maxFieldLength,
dateStart,
dateEnd,
documentTypeCode,
uploadCount,
setUploadCount,
setFileCount,
parentField,
parentFieldShowOnValue,
requiredDocumentValue,
requiredDocumentLabel,
setDocumentsList,
documentList,
maxSubField,
datafieldcontent
} = props;
// Extract deeply nested props for convenience (avoid props.props.props all over)
// Defensive checks in case nested props don't exist
const sectionProps = props?.props?.props || {};
const pageProps = sectionProps?.props || {};
const appealType = sectionProps.appealType || {};
const form = sectionProps.form || {};
const formProps = pageProps.form || sectionProps.form || {};
const setFilesForAppeal = sectionProps.setFilesForAppeal;
const accountDetails =
sectionProps.accountDetails || pageProps.accountDetails || {};
const ticketnumber = appealType.caseReference?.ticketnumber || "";
const fileList = appealType.fileList || {};
const containerID =
accountDetails.containerID || sectionProps.containerID || "";
// Mapping fieldType to components
const fieldTypeMap = {
"{270BD3DB-D9AF-4782-9025-509E298DEC0A}": (