import { describe, expect, it } from 'vitest';

import {
  getSelectedZone,
  getZoneBehaviorHeading,
  getZonesSafetyConnection,
  toggleExpandedZone,
} from '@/business/zones/selectors';
import type {
  ZoneInfo,
  ZonesSafetyConnection,
} from '@/shared/types/app';

const zones: readonly ZoneInfo[] = [
  {
    color: 'green',
    name: 'Green Zone',
    description: 'Ready',
    behaviors: [],
    strategies: [],
    signs: [],
    bgClass: 'bg-green-100',
    textClass: 'text-green-700',
    borderClass: 'border-green-300',
  },
  {
    color: 'yellow',
    name: 'Yellow Zone',
    description: 'Heightened',
    behaviors: [],
    strategies: [],
    signs: [],
    bgClass: 'bg-yellow-100',
    textClass: 'text-yellow-700',
    borderClass: 'border-yellow-300',
  },
];

const safetyConnections: readonly ZonesSafetyConnection[] = [
  {
    zoneColor: 'yellow',
    title: 'Yellow safety',
    description: 'Intervene early',
  },
];

describe('zones selectors', () => {
  it('toggles expanded zones', () => {
    expect(toggleExpandedZone('green', 'green')).toBeNull();
    expect(toggleExpandedZone('green', 'yellow')).toBe('yellow');
    expect(toggleExpandedZone(null, 'yellow')).toBe('yellow');
  });

  it('selects the expanded zone record', () => {
    expect(getSelectedZone(zones, 'green')).toEqual(zones[0]);
    expect(getSelectedZone(zones, 'blue')).toBeNull();
    expect(getSelectedZone(zones, null)).toBeNull();
  });

  it('selects safety connection for the active zone', () => {
    expect(getZonesSafetyConnection(safetyConnections, 'yellow')).toEqual(safetyConnections[0]);
    expect(getZonesSafetyConnection(safetyConnections, 'green')).toBeNull();
    expect(getZonesSafetyConnection(safetyConnections, null)).toBeNull();
  });

  it('uses adult behavior heading only for the adult tab', () => {
    expect(getZoneBehaviorHeading('adult')).toBe('Adult Behaviors');
    expect(getZoneBehaviorHeading('overview')).toBe('What It Looks Like');
    expect(getZoneBehaviorHeading('student')).toBe('What It Looks Like');
  });
});
