import { useState } from 'react'; export default function PermissionIndicator({ userRole, visibility, showTooltip = true }) { const [showDetails, setShowDetails] = useState(false); const getRoleInfo = (role) => { switch (role) { case 'owner': return { icon: '👑', label: 'Owner', color: '#f59e0b', permissions: ['View', 'Edit', 'Delete', 'Manage Users', 'Change Visibility'] }; case 'editor': return { icon: '✏️', label: 'Editor', color: '#10b981', permissions: ['View', 'Edit', 'Add/Remove Cards'] }; case 'viewer': return { icon: '👁️', label: 'Viewer', color: '#6b7280', permissions: ['View Only'] }; default: return { icon: '🔒', label: 'No Access', color: '#ef4444', permissions: [] }; } }; const getVisibilityInfo = (vis) => { switch (vis) { case 'public': return { icon: '🌍', label: 'Public', color: '#10b981', description: 'Anyone can view this collection' }; case 'invite-only': return { icon: '👥', label: 'Invite Only', color: '#f59e0b', description: 'Only invited users can access' }; case 'private': return { icon: '🔒', label: 'Private', color: '#6b7280', description: 'Only you can access this collection' }; default: return { icon: '❓', label: 'Unknown', color: '#6b7280', description: 'Visibility not set' }; } }; const roleInfo = getRoleInfo(userRole); const visibilityInfo = getVisibilityInfo(visibility); return (
{/* Role Badge */} {userRole && (
showTooltip && setShowDetails(true)} onMouseLeave={() => setShowDetails(false)} > {roleInfo.icon} {roleInfo.label}
{/* Role Tooltip */} {showDetails && showTooltip && (
{roleInfo.icon} {roleInfo.label} Permissions:
    {roleInfo.permissions.map((permission, index) => (
  • {permission}
  • ))}
)}
)} {/* Visibility Badge */} {visibility && (
showTooltip && setShowDetails(true)} onMouseLeave={() => setShowDetails(false)} > {visibilityInfo.icon} {visibilityInfo.label}
{/* Visibility Tooltip */} {showDetails && showTooltip && (
{visibilityInfo.icon} {visibilityInfo.label}

{visibilityInfo.description}

)}
)}
); } // Utility component for inline permission checks export function CanEdit({ userRole, children }) { const canEdit = ['owner', 'editor'].includes(userRole); return canEdit ? children : null; } export function CanManage({ userRole, children }) { const canManage = userRole === 'owner'; return canManage ? children : null; } export function PermissionGate({ userRole, requiredRole, children, fallback = null }) { const roleHierarchy = { viewer: 1, editor: 2, owner: 3 }; const userLevel = roleHierarchy[userRole] || 0; const requiredLevel = roleHierarchy[requiredRole] || 0; return userLevel >= requiredLevel ? children : fallback; }