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

class EcgView extends GetView<EcgViewController> {
  const EcgView(
      {Key? key,
      required this.width,
      required this.height,
      required this.initData})
      : super(key: key);

  final double width;
  final double height;
  final List<int> initData;

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

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