import 'package:flutter/material.dart';

import '../../shared/models/score_state.dart';
import '../../shared/widgets/destructive_cta.dart';
import '../../shared/widgets/live_badge.dart';
import '../../shared/widgets/metric_card.dart';
import '../../shared/widgets/score_overlay_bar.dart';
import '../../platform/streaming_preview.dart';

class CameraScreenLandscape extends StatelessWidget {
  const CameraScreenLandscape({
    super.key,
    required this.elapsed,
    required this.batteryLevel,
    required this.homeName,
    required this.awayName,
    required this.score,
    required this.lastDelta,
    required this.networkType,
    required this.bitrateMbps,
    required this.fps,
    required this.viewerCount,
    this.platformLabel = 'LIVE',
    required this.onStop,
  });

  final Duration elapsed;
  final int batteryLevel;
  final String homeName;
  final String awayName;
  final ScoreState score;
  final int? lastDelta;
  final String networkType;
  final double bitrateMbps;
  final int fps;
  final int viewerCount;
  final String platformLabel;
  final VoidCallback onStop;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.black,
      body: Stack(
        fit: StackFit.expand,
        children: [
          NativeStreamingPreview(showGrid: false, platformLabel: platformLabel),
          Positioned(
            top: 12,
            left: 12,
            child: LiveBadge(elapsed: elapsed, compact: true),
          ),
          Positioned(
            top: 12,
            right: 12,
            child: Row(
              children: [
                Icon(Icons.battery_std, size: 16, color: Colors.white70),
                const SizedBox(width: 4),
                Text(
                  '$batteryLevel%',
                  style: const TextStyle(color: Colors.white70, fontSize: 12),
                ),
              ],
            ),
          ),
          Positioned(
            bottom: 16,
            left: 16,
            child: ScoreOverlayBar(
              homeName: homeName,
              awayName: awayName,
              homePoints: score.homePoints,
              awayPoints: score.awayPoints,
              currentSet: score.currentSet,
              homeSets: score.homeSets,
              awaySets: score.awaySets,
              compact: true,
              lastDelta: lastDelta,
            ),
          ),
          Positioned(
            bottom: 16,
            left: 0,
            right: 100,
            child: Center(
              child: Row(
                mainAxisSize: MainAxisSize.min,
                children: [
                  MetricCard(
                    label: 'Segnale',
                    value: networkType,
                    icon: Icons.signal_cellular_alt,
                    expand: false,
                  ),
                  const SizedBox(width: 6),
                  MetricCard(
                    label: 'Mbps',
                    value: bitrateMbps.toStringAsFixed(1),
                    icon: Icons.speed,
                    expand: false,
                  ),
                  const SizedBox(width: 6),
                  MetricCard(
                    label: 'fps',
                    value: '$fps',
                    icon: Icons.movie,
                    expand: false,
                  ),
                  const SizedBox(width: 6),
                  MetricCard(
                    label: 'Spett.',
                    value: viewerCount > 0 ? '$viewerCount' : 'LIVE',
                    icon: Icons.visibility,
                    expand: false,
                  ),
                ],
              ),
            ),
          ),
          Positioned(
            bottom: 16,
            right: 16,
            child: DestructiveCta(
              label: 'INTERROMPI',
              compact: true,
              onPressed: onStop,
            ),
          ),
        ],
      ),
    );
  }
}
