'use client';
import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
import { fieldIsSidebar } from 'payload/shared';
import React, { useMemo } from 'react';
import { RenderFields } from '../../forms/RenderFields/index.js';
import { Gutter } from '../Gutter/index.js';
import { TrashBanner } from '../TrashBanner/index.js';
import './index.scss';
const baseClass = 'document-fields';
export const DocumentFields = ({ AfterFields, BeforeFields, docPermissions, fields, forceSidebarWrap, isTrashed = false, readOnly, schemaPathSegments })=>{
    const { hasSidebarFields, mainFields, sidebarFields } = useMemo(()=>{
        return fields.reduce((acc, field)=>{
            if (fieldIsSidebar(field)) {
                acc.sidebarFields.push(field);
                acc.mainFields.push(null);
                acc.hasSidebarFields = true;
            } else {
                acc.mainFields.push(field);
                acc.sidebarFields.push(null);
            }
            return acc;
        }, {
            hasSidebarFields: false,
            mainFields: [],
            sidebarFields: []
        });
    }, [
        fields
    ]);
    return /*#__PURE__*/ _jsxDEV("div", {
        className: [
            baseClass,
            hasSidebarFields ? `${baseClass}--has-sidebar` : `${baseClass}--no-sidebar`,
            forceSidebarWrap && `${baseClass}--force-sidebar-wrap`
        ].filter(Boolean).join(' '),
        children: [
            /*#__PURE__*/ _jsxDEV("div", {
                className: `${baseClass}__main`,
                children: /*#__PURE__*/ _jsxDEV(Gutter, {
                    className: `${baseClass}__edit`,
                    children: [
                        isTrashed && /*#__PURE__*/ _jsxDEV(TrashBanner, {}, void 0, false, {
                            fileName: "src/elements/DocumentFields/index.tsx",
                            lineNumber: 69,
                            columnNumber: 25
                        }, this),
                        BeforeFields,
                        /*#__PURE__*/ _jsxDEV(RenderFields, {
                            className: `${baseClass}__fields`,
                            fields: mainFields,
                            forceRender: true,
                            parentIndexPath: "",
                            parentPath: "",
                            parentSchemaPath: schemaPathSegments.join('.'),
                            permissions: docPermissions?.fields,
                            readOnly: readOnly
                        }, void 0, false, {
                            fileName: "src/elements/DocumentFields/index.tsx",
                            lineNumber: 71,
                            columnNumber: 11
                        }, this),
                        AfterFields
                    ]
                }, void 0, true, {
                    fileName: "src/elements/DocumentFields/index.tsx",
                    lineNumber: 68,
                    columnNumber: 9
                }, this)
            }, void 0, false, {
                fileName: "src/elements/DocumentFields/index.tsx",
                lineNumber: 67,
                columnNumber: 7
            }, this),
            hasSidebarFields ? /*#__PURE__*/ _jsxDEV("div", {
                className: `${baseClass}__sidebar-wrap`,
                children: /*#__PURE__*/ _jsxDEV("div", {
                    className: `${baseClass}__sidebar`,
                    children: /*#__PURE__*/ _jsxDEV("div", {
                        className: `${baseClass}__sidebar-fields`,
                        children: /*#__PURE__*/ _jsxDEV(RenderFields, {
                            fields: sidebarFields,
                            forceRender: true,
                            parentIndexPath: "",
                            parentPath: "",
                            parentSchemaPath: schemaPathSegments.join('.'),
                            permissions: docPermissions?.fields,
                            readOnly: readOnly
                        }, void 0, false, {
                            fileName: "src/elements/DocumentFields/index.tsx",
                            lineNumber: 88,
                            columnNumber: 15
                        }, this)
                    }, void 0, false, {
                        fileName: "src/elements/DocumentFields/index.tsx",
                        lineNumber: 87,
                        columnNumber: 13
                    }, this)
                }, void 0, false, {
                    fileName: "src/elements/DocumentFields/index.tsx",
                    lineNumber: 86,
                    columnNumber: 11
                }, this)
            }, void 0, false, {
                fileName: "src/elements/DocumentFields/index.tsx",
                lineNumber: 85,
                columnNumber: 9
            }, this) : null
        ]
    }, void 0, true, {
        fileName: "src/elements/DocumentFields/index.tsx",
        lineNumber: 58,
        columnNumber: 5
    }, this);
};

//# sourceMappingURL=index.js.map