import { cn } from '@/lib/utils'

/**
 * ScopeDot — маленький цветной квадратик-маркер для PUBLIC/INTERNAL/RESTRICTED.
 * 8×8 (size=md) или 6×6 (size=sm).
 */
export type DataScope = 'PUBLIC' | 'INTERNAL' | 'RESTRICTED'

const SCOPE_COLORS: Record<DataScope, string> = {
  PUBLIC: 'bg-accent',     // terracotta/orange
  INTERNAL: 'bg-warn',     // amber
  RESTRICTED: 'bg-pink',   // brick red
}

const SCOPE_BG: Record<DataScope, string> = {
  PUBLIC: 'bg-accent-bg text-accent',
  INTERNAL: 'bg-warn-bg text-warn',
  RESTRICTED: 'bg-pink-bg text-pink',
}

export function ScopeDot({
  scope,
  size = 'md',
  className,
}: {
  scope: DataScope
  size?: 'sm' | 'md'
  className?: string
}) {
  return (
    <span
      aria-hidden
      className={cn(
        'inline-block rounded-sm shrink-0',
        size === 'md' ? 'size-2' : 'size-1.5',
        SCOPE_COLORS[scope],
        className,
      )}
    />
  )
}

const SCOPE_LABELS: Record<DataScope, string> = {
  PUBLIC: 'Публичный',
  INTERNAL: 'Внутренний',
  RESTRICTED: 'Ограниченный',
}

const SCOPE_SHORT: Record<DataScope, string> = {
  PUBLIC: 'PUB',
  INTERNAL: 'INT',
  RESTRICTED: 'RES',
}

export function ScopeBadge({
  scope,
  short,
  className,
}: {
  scope: DataScope
  short?: boolean
  className?: string
}) {
  return (
    <span
      className={cn(
        'inline-flex items-center gap-1.5 rounded-sm px-1.5 py-0.5 text-cell font-mono font-medium',
        SCOPE_BG[scope],
        className,
      )}
    >
      <ScopeDot scope={scope} size="sm" className="!bg-current" />
      {short ? SCOPE_SHORT[scope] : SCOPE_LABELS[scope]}
    </span>
  )
}

/** 3px вертикальная полоса для левого края card / row — quick visual scope hint. */
export function ScopeStrip({ scope, className }: { scope: DataScope; className?: string }) {
  return <span className={cn('block w-[3px] shrink-0', SCOPE_COLORS[scope], className)} aria-hidden />
}
