'use client';

import { c as _c } from "react/compiler-runtime";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { RenderFields, useFormSubmitted } from '@payloadcms/ui';
import React, { createContext, useMemo } from 'react';
const BlockComponentContext = /*#__PURE__*/createContext({
  initialState: false
});
export const useBlockComponentContext = () => {
  return React.useContext(BlockComponentContext);
};
/**
 * The actual content of the Block. This should be INSIDE a Form component,
 * scoped to the block. All format operations in here are thus scoped to the block's form, and
 * not the whole document.
 */
export const BlockContent = props => {
  const $ = _c(13);
  const {
    BlockDrawer,
    Collapsible,
    CustomBlock,
    EditButton,
    errorCount,
    formSchema,
    initialState,
    nodeKey,
    RemoveButton
  } = props;
  const hasSubmitted = useFormSubmitted();
  const fieldHasErrors = hasSubmitted && errorCount > 0;
  let t0;
  let t1;
  if ($[0] !== Collapsible || $[1] !== errorCount || $[2] !== fieldHasErrors) {
    t1 = props_0 => _jsx(Collapsible, {
      editButton: props_0.editButton,
      errorCount,
      fieldHasErrors,
      Label: props_0.Label,
      removeButton: props_0.removeButton,
      children: props_0.children
    });
    $[0] = Collapsible;
    $[1] = errorCount;
    $[2] = fieldHasErrors;
    $[3] = t1;
  } else {
    t1 = $[3];
  }
  t0 = t1;
  const CollapsibleWithErrorProps = t0;
  let t2;
  if ($[4] !== BlockDrawer || $[5] !== CollapsibleWithErrorProps || $[6] !== CustomBlock || $[7] !== EditButton || $[8] !== RemoveButton || $[9] !== formSchema || $[10] !== initialState || $[11] !== nodeKey) {
    t2 = CustomBlock ? _jsxs(BlockComponentContext.Provider, {
      value: {
        BlockCollapsible: CollapsibleWithErrorProps,
        EditButton,
        initialState,
        nodeKey,
        RemoveButton
      },
      children: [CustomBlock, _jsx(BlockDrawer, {})]
    }) : _jsx(CollapsibleWithErrorProps, {
      children: _jsx(RenderFields, {
        fields: formSchema,
        forceRender: true,
        parentIndexPath: "",
        parentPath: "",
        parentSchemaPath: "",
        permissions: true
      })
    });
    $[4] = BlockDrawer;
    $[5] = CollapsibleWithErrorProps;
    $[6] = CustomBlock;
    $[7] = EditButton;
    $[8] = RemoveButton;
    $[9] = formSchema;
    $[10] = initialState;
    $[11] = nodeKey;
    $[12] = t2;
  } else {
    t2 = $[12];
  }
  return t2;
};
//# sourceMappingURL=BlockContent.js.map