import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { CopyIcon } from '../../../../lib/icons/Copy.js';
import { useDeleteAccessCode } from '../../../../lib/seam/access-codes/use-delete-access-code.js';
import { Button } from '../../../../lib/ui/Button.js';
import { copyToClipboard } from '../../../../lib/ui/clipboard.js';
import { MenuItem } from '../../../../lib/ui/Menu/MenuItem.js';
import { MoreActionsMenu } from '../../../../lib/ui/Menu/MoreActionsMenu.js';
import { useToggle } from '../../../../lib/ui/use-toggle.js';
export function AccessCodeMenu(props) {
    return (_jsx(MoreActionsMenu, { menuProps: {
            backgroundProps: {
                className: 'seam-table-action-menu',
            },
        }, children: _jsx(Content, { ...props }) }));
}
function Content({ accessCode, onViewDetails, disableEditAccessCode, disableDeleteAccessCode, onEdit, }) {
    const [deleteConfirmationVisible, toggleDeleteConfirmation] = useToggle();
    const deleteAccessCode = useDeleteAccessCode();
    if (deleteConfirmationVisible) {
        return (_jsxs("div", { className: 'seam-delete-confirmation', children: [_jsx("span", { children: t.deleteCodeConfirmation }), _jsxs("div", { className: 'seam-actions', children: [_jsx(Button, { onClick: toggleDeleteConfirmation, disabled: deleteAccessCode.isLoading, children: t.cancelDelete }), _jsx(Button, { variant: 'solid', disabled: deleteAccessCode.isLoading, onClick: () => {
                                deleteAccessCode.mutate({
                                    access_code_id: accessCode.access_code_id,
                                });
                            }, children: t.confirmDelete })] })] }));
    }
    return (_jsxs(_Fragment, { children: [_jsx(MenuItem, { onClick: () => {
                    void copyToClipboard(accessCode.code ?? '');
                }, children: _jsxs("div", { className: 'seam-menu-item-copy', children: [_jsxs("span", { children: [t.copyCode, " - ", accessCode.code] }), _jsx(CopyIcon, {})] }) }), _jsx("div", { className: 'seam-divider' }), _jsx(MenuItem, { onClick: onViewDetails, children: t.viewCodeDetails }), !disableEditAccessCode && (_jsx(MenuItem, { onClick: onEdit, children: t.editCode })), !disableDeleteAccessCode && (_jsxs(_Fragment, { children: [_jsx("div", { className: 'seam-divider' }), _jsx(MenuItem, { onClick: (event) => {
                            event.stopPropagation(); // Prevent hiding menu on outside click
                            toggleDeleteConfirmation();
                        }, preventDefaultOnClick: true, className: 'seam-text-danger', children: t.deleteCode })] }))] }));
}
const t = {
    copyCode: 'Copy code',
    codeIssue: 'code issue',
    codeIssues: 'code issues',
    editCode: 'Edit code',
    viewCodeDetails: 'View code details',
    deleteCode: 'Delete code',
    deleteCodeConfirmation: 'Delete this code and data?',
    cancelDelete: 'Cancel',
    confirmDelete: 'Delete',
};
//# sourceMappingURL=AccessCodeMenu.js.map