// SPDX-License-Identifier: Apache-2.0
// Chanora design tokens for connection, voice, and latency states.
// Maps abstract server/voice/network state to Material 3 colour, icon,
// and label affordances.

import 'package:flutter/material.dart';

/// Tokenised visual mapping for a connection state.
class ConnectionTokens {
  final Color color;
  final Color? background;
  final IconData icon;
  final String label;

  const ConnectionTokens({
    required this.color,
    required this.icon,
    required this.label,
    this.background,
  });

  static ConnectionTokens disconnected(ColorScheme cs) => ConnectionTokens(
        color: cs.onSurfaceVariant,
        background: cs.surfaceContainerHighest,
        icon: Icons.cloud_off,
        label: 'Disconnected',
      );

  static ConnectionTokens connecting(ColorScheme cs) => ConnectionTokens(
        color: cs.primary,
        background: cs.primaryContainer,
        icon: Icons.sync,
        label: 'Connecting',
      );

  static ConnectionTokens synchronizing(ColorScheme cs) => ConnectionTokens(
        color: cs.secondary,
        background: cs.secondaryContainer,
        icon: Icons.hourglass_top,
        label: 'Synchronizing',
      );

  static ConnectionTokens connected(ColorScheme cs) => ConnectionTokens(
        color: cs.tertiary,
        background: cs.tertiaryContainer,
        icon: Icons.cloud_done,
        label: 'Connected',
      );

  static ConnectionTokens reconnecting(ColorScheme cs) => ConnectionTokens(
        color: cs.error,
        background: cs.errorContainer,
        icon: Icons.restart_alt,
        label: 'Reconnecting',
      );

  static ConnectionTokens lost(ColorScheme cs) => ConnectionTokens(
        color: cs.error,
        background: cs.errorContainer,
        icon: Icons.warning_amber,
        label: 'Connection Lost',
      );
}

/// Tokenised visual mapping for a voice transmit/mute state.
class VoiceTokens {
  final Color color;
  final Color? background;
  final IconData icon;

  const VoiceTokens({
    required this.color,
    required this.icon,
    this.background,
  });

  static VoiceTokens idle(ColorScheme cs) => VoiceTokens(
        color: cs.onSurfaceVariant,
        icon: Icons.mic_none,
      );

  static VoiceTokens pttHeld(ColorScheme cs) => VoiceTokens(
        color: cs.primary,
        background: cs.primaryContainer,
        icon: Icons.mic,
      );

  static VoiceTokens voiceActivity(ColorScheme cs) => VoiceTokens(
        color: cs.tertiary,
        background: cs.tertiaryContainer,
        icon: Icons.mic,
      );

  static VoiceTokens continuousTx(ColorScheme cs) => VoiceTokens(
        color: cs.primary,
        background: cs.primaryContainer,
        icon: Icons.settings_voice,
      );

  static VoiceTokens muted(ColorScheme cs) => VoiceTokens(
        color: cs.error,
        background: cs.errorContainer,
        icon: Icons.mic_off,
      );

  static VoiceTokens outputMuted(ColorScheme cs) => VoiceTokens(
        color: cs.error,
        icon: Icons.headset_off,
      );

  static VoiceTokens deafened(ColorScheme cs) => VoiceTokens(
        color: cs.error,
        background: cs.errorContainer,
        icon: Icons.hearing_disabled,
      );
}

/// Tokenised visual mapping for network latency/quality.
class LatencyTokens {
  final Color color;
  final String label;

  const LatencyTokens({required this.color, required this.label});

  static LatencyTokens good(ColorScheme cs) => LatencyTokens(
        color: cs.tertiary,
        label: 'Good',
      );

  static LatencyTokens warning(ColorScheme cs) => LatencyTokens(
        color: cs.error,
        label: 'Warning',
      );

  static LatencyTokens unknown(ColorScheme cs) => LatencyTokens(
        color: cs.outlineVariant,
        label: '—',
      );
}

/// Tokens for channel membership status.
class ChannelTokens {
  final IconData? icon;
  final String? label;

  const ChannelTokens({this.icon, this.label});

  static ChannelTokens inChannel(ColorScheme cs) => ChannelTokens(
        icon: Icons.headset_mic,
        label: 'Connected',
      );

  static ChannelTokens joining(ColorScheme cs) => ChannelTokens(
        icon: Icons.login,
        label: 'Joining...',
      );

  static ChannelTokens notInChannel(ColorScheme cs) => ChannelTokens(
        icon: null,
        label: null,
      );
}

/// Tokens for PTT capability display.
class PttTokens {
  final String label;
  final Color? color;

  const PttTokens({required this.label, this.color});

  static PttTokens focused(ColorScheme cs) => PttTokens(
        label: 'Keyboard PTT',
        color: cs.tertiary,
      );

  static PttTokens platformHook(ColorScheme cs) => PttTokens(
        label: 'Global PTT',
        color: cs.primary,
      );

  static PttTokens none(ColorScheme cs) => PttTokens(
        label: 'No PTT input',
        color: cs.error,
      );
}
