import type { CSSProperties } from 'react';
import type { BadgeVariant } from '@/components/ui/shared/Badge';
import type { LabTaskListItem, LabTaskStatus } from '@/types/cases';

export function canEditLabTaskStatus(
  task: Pick<LabTaskListItem, 'assignee'>,
  currentUserId: string | undefined,
  canEditTasks: boolean,
): boolean {
  if (!canEditTasks || !currentUserId) return false;
  if (!task.assignee) return true;
  return task.assignee.id === currentUserId;
}

export function labTaskStatusVariant(status: LabTaskStatus): BadgeVariant {
  return status === 'COMPLETED' ? 'success' : 'warning';
}

/**
 * Inline style for the closed status <select> so its text/border reflect the
 * current value (yellow = in progress, green = completed). Uses the same badge
 * token colors as the badges for consistency. Native <option> colors have
 * limited cross-browser support, so only the closed control is themed.
 */
export function labTaskStatusSelectStyle(status: LabTaskStatus): CSSProperties {
  const color =
    status === 'COMPLETED'
      ? 'var(--color-badge-success-fg)'
      : 'var(--color-badge-warning-fg)';
  const borderColor =
    status === 'COMPLETED'
      ? 'var(--color-badge-success-border)'
      : 'var(--color-badge-warning-border)';
  return { color, borderColor };
}
