const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');

const screenSource = fs.readFileSync(
  path.join(__dirname, '..', 'src', 'screens', 'ChatScreen.tsx'),
  'utf8'
);

test('exposes the chat composer send control as an accessible button', () => {
  assert.match(screenSource, /accessibilityRole="button"[\s\S]*?accessibilityLabel=\{createButtonAccessibilityLabel\('Send message'\)\}/);
  assert.match(screenSource, /accessibilityHint="Sends your typed text and any attached images to the selected agent\."/);
  assert.match(screenSource, /accessibilityState=\{\{ disabled: !composerHasContent \}\}/);
});

test('exposes the handsfree queue control as an accessible button', () => {
  assert.match(screenSource, /accessibilityRole="button"[\s\S]*?accessibilityLabel=\{createButtonAccessibilityLabel\('Queue message'\)\}/);
  assert.match(screenSource, /accessibilityHint="Adds your typed text and attached images to the queued-messages list without sending immediately\."/);
});

test('keeps the chat composer send control at a mobile-friendly minimum touch target', () => {
  assert.match(screenSource, /sendButton:\s*\{[\s\S]*?minHeight:\s*44,[\s\S]*?minWidth:\s*44,/);
  assert.match(screenSource, /sendButton:\s*\{[\s\S]*?alignItems:\s*'center',[\s\S]*?justifyContent:\s*'center',/);
  assert.match(screenSource, /queueButton:\s*\{[\s\S]*?minHeight:\s*44,[\s\S]*?minWidth:\s*44,/);
});

test('keeps the chat composer accessory controls at a mobile-friendly touch target size', () => {
  assert.match(screenSource, /ttsToggle:\s*\{[\s\S]*?width:\s*44,[\s\S]*?height:\s*44,[\s\S]*?borderRadius:\s*22,/);
});

test('exposes the edit-before-send toggle state to Expo Web accessibility APIs', () => {
  assert.match(screenSource, /accessibilityRole="switch"[\s\S]*?aria-checked=\{willCancel\}[\s\S]*?accessibilityState=\{\{ checked: willCancel \}\}/);
});

test('uses icon-first mobile composer controls with accessible labels', () => {
  assert.match(screenSource, /<Ionicons[\s\S]*?name="image-outline"/);
  assert.match(screenSource, /name=\{ttsEnabled \? 'volume-high-outline' : 'volume-mute-outline'\}/);
  assert.match(screenSource, /<Ionicons[\s\S]*?name="create-outline"/);
  assert.match(screenSource, /<Ionicons name="time-outline" size=\{18\} color=\{theme\.colors\.primary\} \/>/);
  assert.match(screenSource, /<Ionicons name="send-outline" size=\{18\} color=\{theme\.colors\.primaryForeground\} \/>/);
  assert.doesNotMatch(screenSource, /<Text style=\{styles\.queueButtonText\}>Queue<\/Text>/);
  assert.doesNotMatch(screenSource, /<Text style=\{styles\.sendButtonText\}>Send<\/Text>/);
});
