'use client';
import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
import { getTranslation } from '@payloadcms/translations';
import { Button } from '../../elements/Button/index.js';
import { Popup, PopupList } from '../Popup/index.js';
export const AddNewButton = ({ allowCreate, baseClass, buttonStyle, className, collections, i18n, icon, label, onClick, permissions, relationTo })=>{
    if (!allowCreate) {
        return null;
    }
    const isPolymorphic = Array.isArray(relationTo);
    if (!isPolymorphic) {
        return /*#__PURE__*/ _jsxDEV(Button, {
            buttonStyle: buttonStyle,
            className: className,
            onClick: ()=>onClick(),
            children: label
        }, void 0, false, {
            fileName: "src/elements/RelationshipTable/AddNewButton.tsx",
            lineNumber: 45,
            columnNumber: 7
        }, this);
    }
    return /*#__PURE__*/ _jsxDEV("div", {
        className: `${baseClass}__add-new-polymorphic-wrapper`,
        children: /*#__PURE__*/ _jsxDEV(Popup, {
            button: /*#__PURE__*/ _jsxDEV(Button, {
                buttonStyle: buttonStyle,
                className: className,
                icon: icon,
                children: label
            }, void 0, false, {
                fileName: "src/elements/RelationshipTable/AddNewButton.tsx",
                lineNumber: 55,
                columnNumber: 11
            }, void 0),
            buttonType: "custom",
            horizontalAlign: "center",
            render: ({ close: closePopup })=>/*#__PURE__*/ _jsxDEV(PopupList.ButtonGroup, {
                    children: relationTo.map((relatedCollection)=>{
                        if (permissions.collections[relatedCollection]?.create) {
                            return /*#__PURE__*/ _jsxDEV(PopupList.Button, {
                                className: `${baseClass}__relation-button--${relatedCollection}`,
                                onClick: ()=>{
                                    closePopup();
                                    onClick(relatedCollection);
                                },
                                children: getTranslation(collections.find((each)=>each.slug === relatedCollection).labels.singular, i18n)
                            }, relatedCollection, false, {
                                fileName: "src/elements/RelationshipTable/AddNewButton.tsx",
                                lineNumber: 66,
                                columnNumber: 19
                            }, void 0);
                        }
                        return null;
                    })
                }, void 0, false, {
                    fileName: "src/elements/RelationshipTable/AddNewButton.tsx",
                    lineNumber: 62,
                    columnNumber: 11
                }, void 0),
            size: "medium"
        }, void 0, false, {
            fileName: "src/elements/RelationshipTable/AddNewButton.tsx",
            lineNumber: 53,
            columnNumber: 7
        }, this)
    }, void 0, false, {
        fileName: "src/elements/RelationshipTable/AddNewButton.tsx",
        lineNumber: 52,
        columnNumber: 5
    }, this);
};

//# sourceMappingURL=AddNewButton.js.map