import { jsx as _jsx } from "react/jsx-runtime";
import { renderField } from '@payloadcms/ui/forms/renderField';
import React from 'react';
// eslint-disable-next-line payload/no-imports-from-exports-dir
import { RichTextField } from '../exports/client/index.js';
import { buildInitialState } from '../utilities/buildInitialState.js';
import { initLexicalFeatures } from '../utilities/initLexicalFeatures.js';
export const RscEntryLexicalField = async args => {
  const field = args.field;
  const path = args.path ?? args.clientField.name;
  const schemaPath = args.schemaPath ?? path;
  const {
    clientFeatures,
    featureClientSchemaMap
  } = initLexicalFeatures({
    clientFieldSchemaMap: args.clientFieldSchemaMap,
    fieldSchemaMap: args.fieldSchemaMap,
    i18n: args.i18n,
    path,
    payload: args.payload,
    sanitizedEditorConfig: args.sanitizedEditorConfig,
    schemaPath
  });
  let initialLexicalFormState = {};
  if (args.data?.[field.name]?.root?.children?.length) {
    initialLexicalFormState = await buildInitialState({
      context: {
        id: args.id,
        clientFieldSchemaMap: args.clientFieldSchemaMap,
        collectionSlug: args.collectionSlug,
        field,
        fieldSchemaMap: args.fieldSchemaMap,
        lexicalFieldSchemaPath: schemaPath,
        operation: args.operation,
        permissions: args.permissions,
        preferences: args.preferences,
        renderFieldFn: renderField,
        req: args.req
      },
      nodeData: args.data?.[field.name]?.root?.children
    });
  }
  const props = {
    admin: args.admin,
    clientFeatures,
    featureClientSchemaMap,
    field: args.clientField,
    forceRender: args.forceRender,
    initialLexicalFormState,
    lexicalEditorConfig: args.sanitizedEditorConfig.lexical,
    path,
    permissions: args.permissions,
    readOnly: args.readOnly,
    renderedBlocks: args.renderedBlocks,
    schemaPath
  };
  for (const key in props) {
    if (props[key] === undefined) {
      delete props[key];
    }
  }
  return /*#__PURE__*/_jsx(RichTextField, {
    ...props
  });
};
//# sourceMappingURL=rscEntry.js.map