'use client';
import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
import { useModal } from '@faceless-ui/modal';
import React, { useState } from 'react';
import { useAuth } from '../../providers/Auth/index.js';
import { EditDepthProvider } from '../../providers/EditDepth/index.js';
import { SelectAllStatus, useSelection } from '../../providers/Selection/index.js';
import { useTranslation } from '../../providers/Translation/index.js';
import { Drawer } from '../Drawer/index.js';
import { ListSelectionButton } from '../ListSelection/index.js';
import { EditManyDrawerContent } from './DrawerContent.js';
import './index.scss';
export const baseClass = 'edit-many';
export const EditMany = (props)=>{
    const { count, selectAll, selectedIDs, toggleAll } = useSelection();
    return /*#__PURE__*/ _jsxDEV(EditMany_v4, {
        ...props,
        count: count,
        ids: selectedIDs,
        onSuccess: ()=>toggleAll(),
        selectAll: selectAll === SelectAllStatus.AllAvailable
    }, void 0, false, {
        fileName: "src/elements/EditMany/index.tsx",
        lineNumber: 28,
        columnNumber: 5
    }, this);
};
export const EditMany_v4 = /**
     * When multiple EditMany components are rendered on the page, this will differentiate them.
     */ ({ collection, count, ids, modalPrefix, onSuccess, selectAll, where })=>{
    const { permissions } = useAuth();
    const { openModal } = useModal();
    const { t } = useTranslation();
    const [selectedFields, setSelectedFields] = useState([]);
    const collectionPermissions = permissions?.collections?.[collection.slug];
    const drawerSlug = `${modalPrefix ? `${modalPrefix}-` : ''}edit-${collection.slug}`;
    if (count === 0 || !collectionPermissions?.update) {
        return null;
    }
    return /*#__PURE__*/ _jsxDEV("div", {
        className: [
            baseClass,
            `${baseClass}__toggle`
        ].filter(Boolean).join(' '),
        children: [
            /*#__PURE__*/ _jsxDEV(ListSelectionButton, {
                "aria-label": t('general:edit'),
                onClick: ()=>{
                    openModal(drawerSlug);
                    setSelectedFields([]);
                },
                children: t('general:edit')
            }, void 0, false, {
                fileName: "src/elements/EditMany/index.tsx",
                lineNumber: 68,
                columnNumber: 7
            }, this),
            /*#__PURE__*/ _jsxDEV(EditDepthProvider, {
                children: /*#__PURE__*/ _jsxDEV(Drawer, {
                    Header: null,
                    slug: drawerSlug,
                    children: /*#__PURE__*/ _jsxDEV(EditManyDrawerContent, {
                        collection: collection,
                        count: count,
                        drawerSlug: drawerSlug,
                        ids: ids,
                        onSuccess: onSuccess,
                        selectAll: selectAll,
                        selectedFields: selectedFields,
                        setSelectedFields: setSelectedFields,
                        where: where
                    }, void 0, false, {
                        fileName: "src/elements/EditMany/index.tsx",
                        lineNumber: 79,
                        columnNumber: 11
                    }, this)
                }, void 0, false, {
                    fileName: "src/elements/EditMany/index.tsx",
                    lineNumber: 78,
                    columnNumber: 9
                }, this)
            }, void 0, false, {
                fileName: "src/elements/EditMany/index.tsx",
                lineNumber: 77,
                columnNumber: 7
            }, this)
        ]
    }, void 0, true, {
        fileName: "src/elements/EditMany/index.tsx",
        lineNumber: 67,
        columnNumber: 5
    }, this);
};

//# sourceMappingURL=index.js.map