import type {
  ZoneColor,
  ZoneInfo,
  ZonesSafetyConnection,
} from '@/shared/types/app';

export function toggleExpandedZone(
  currentZone: ZoneColor | null,
  nextZone: ZoneColor,
): ZoneColor | null {
  return currentZone === nextZone ? null : nextZone;
}

export function getSelectedZone(
  zones: readonly ZoneInfo[],
  expandedZone: ZoneColor | null,
): ZoneInfo | null {
  if (!expandedZone) {
    return null;
  }

  return zones.find((zone) => zone.color === expandedZone) ?? null;
}

export function getZonesSafetyConnection(
  safetyConnections: readonly ZonesSafetyConnection[],
  zoneColor: ZoneColor | null,
): ZonesSafetyConnection | null {
  if (!zoneColor) {
    return null;
  }

  return safetyConnections.find((connection) => connection.zoneColor === zoneColor) ?? null;
}

export function getZoneBehaviorHeading(activeTab: string): string {
  return activeTab === 'adult' ? 'Adult Behaviors' : 'What It Looks Like';
}
