'use client'

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

export const PRIORITY_BORDER: Record<number, string> = {
  1: 'border-l-4 border-l-priority-critical',
  2: 'border-l-4 border-l-priority-high',
  3: 'border-l-4 border-l-priority-medium',
  4: 'border-l-4 border-l-priority-low',
}

interface BacklogCardProps extends React.HTMLAttributes<HTMLDivElement> {
  title: string
  priority: number
  isSelected?: boolean
  isDragging?: boolean
  badge?: React.ReactNode
  actions?: React.ReactNode
}

export const BacklogCard = forwardRef<HTMLDivElement, BacklogCardProps>(function BacklogCard(
  { title, priority, isSelected, isDragging, badge, actions, className, ...rest },
  ref
) {
  return (
    <div
      ref={ref}
      className={cn(
        'bg-surface-container rounded border border-border px-3 py-2 select-none transition-colors cursor-pointer',
        PRIORITY_BORDER[priority],
        isSelected
          ? 'bg-primary-container border-primary text-primary-container-foreground'
          : 'hover:bg-surface-container-high',
        isDragging && 'opacity-40 shadow-lg',
        className,
      )}
      {...rest}
    >
      <p className="text-sm leading-snug line-clamp-2">{title}</p>
      {(badge || actions) && (
        <div className="flex items-center justify-between gap-1 mt-1.5">
          <div className="flex items-center gap-1">{badge}</div>
          {actions && <div className="flex items-center gap-1 shrink-0">{actions}</div>}
        </div>
      )}
    </div>
  )
})
