import 'package:flutter/material.dart';

import 'guide_frame.dart';

/// Circular shooting guide overlay.
class GuideOverlay extends StatelessWidget {
  const GuideOverlay({super.key, required this.size});

  final Size size;

  @override
  Widget build(BuildContext context) {
    return CustomPaint(
      size: size,
      painter: _GuidePainter(),
    );
  }
}

class _GuidePainter extends CustomPainter {
  @override
  void paint(Canvas canvas, Size size) {
    final rect = GuideFrame.inViewport(size);
    final dim = Paint()..color = Colors.black.withOpacity(0.45);
    final path = Path()
      ..addRect(Offset.zero & size)
      ..addOval(rect)
      ..fillType = PathFillType.evenOdd;
    canvas.drawPath(path, dim);

    final border = Paint()
      ..style = PaintingStyle.stroke
      ..strokeWidth = 2
      ..color = Colors.white70;
    canvas.drawOval(rect, border);

    // Crosshair ticks
    final tick = Paint()
      ..style = PaintingStyle.stroke
      ..strokeWidth = 2
      ..color = const Color(0xFFEAB308);
    final c = rect.center;
    const len = 14.0;
    canvas.drawLine(Offset(c.dx - len, c.dy), Offset(c.dx + len, c.dy), tick);
    canvas.drawLine(Offset(c.dx, c.dy - len), Offset(c.dx, c.dy + len), tick);
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
}
