import { useTranslation } from "react-i18next";
import { useCollectionRecord } from "../../../data-source/collection-record/CollectionRecordProvider.mjs";
import { useParentCollection } from "../../../data-source/collection/AssociationProvider.mjs";
import { useFlag } from "../../../flag-provider/hooks/useFlag.mjs";
import { useBaseVariable } from "./useBaseVariable.mjs";
const useParentRecordVariable = (props)=>{
    const { t } = useTranslation();
    const currentRecordVariable = useBaseVariable({
        collectionField: props.collectionField,
        uiSchema: props.schema,
        name: '$nParentRecord',
        title: t('Parent record'),
        maxDepth: 5,
        collectionName: props.collectionName,
        noDisabled: props.noDisabled,
        targetFieldSchema: props.targetFieldSchema
    });
    return currentRecordVariable;
};
const useCurrentParentRecordVariable = function() {
    let props = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
    var _record_parentRecord, _record_parentRecord1;
    const { t } = useTranslation();
    const record = useCollectionRecord();
    const { name: parentCollectionName } = useParentCollection() || {};
    const { isInSubForm, isInSubTable } = useFlag() || {};
    const currentParentRecordSettings = useBaseVariable({
        collectionField: props.collectionField,
        uiSchema: props.schema,
        name: '$nParentRecord',
        title: t('Parent record'),
        collectionName: parentCollectionName,
        noDisabled: props.noDisabled,
        targetFieldSchema: props.targetFieldSchema
    });
    return {
        currentParentRecordSettings,
        currentParentRecordCtx: null == record ? void 0 : null == (_record_parentRecord = record.parentRecord) ? void 0 : _record_parentRecord.data,
        shouldDisplayCurrentParentRecord: !!(null == record ? void 0 : null == (_record_parentRecord1 = record.parentRecord) ? void 0 : _record_parentRecord1.data) && !isInSubForm && !isInSubTable,
        collectionName: parentCollectionName
    };
};
export { useCurrentParentRecordVariable, useParentRecordVariable };
