import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:vitalapp/architecture/utils/advance_debounce.dart';
import 'index.dart';

class TwelveEcgView extends GetView<TwelveEcgViewController> {
  const TwelveEcgView({
    Key? key,
    required this.width,
    required this.height,
    required this.initData,
    required this.currentIndex,
    required this.isConclusion,
  }) : super(key: key);

  final double width;
  final double height;
  final List<int> initData;
  final int currentIndex;
  final bool isConclusion;

  // 主视图
  Widget _buildView() {
    return Center(
      child: ClipRect(
        child: RepaintBoundary(
          child: CustomPaint(
            foregroundPainter: EcgPainter(
              newPoints: controller.newPointsToDraw,
              oldPoints: controller.oldPointsToDraw,
              xDataCount: controller.xDataCount,
              yMaxList: controller.yMaxList,
              isInitPoints: controller.isInitPoints,
            ),
            painter: GridBackgroundPainter(10 * 25),
            size: Size(width, height),
          ),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<TwelveEcgViewController>(
      init: TwelveEcgViewController(
        initPoints: initData,
      ),
      id: "twelve_ecg_view",
      builder: (_) {
        return GestureDetector(
          onTap: () {
            if (isConclusion) {
              advanceDebounce(
                controller.openFullScreenDialog,
                "twelve_ecg_view.openFullScreenDialog",
                1500,
              );
            }
          },
          child: Center(
            child: _buildView(),
          ),
        );
      },
    );
  }
}
