import type { ReactNode } from 'react'
import type { MockUser } from '../../stores/sessionStore'
import { useSessionStore } from '../../stores/sessionStore'

interface PermissionGateProps {
  check: (user: MockUser) => boolean
  fallback?: ReactNode
  children: ReactNode
}

export function PermissionGate({ check, fallback = null, children }: PermissionGateProps) {
  const { currentUser } = useSessionStore()

  if (!currentUser || !check(currentUser)) {
    return <>{fallback}</>
  }

  return <>{children}</>
}
