import 'package:flutter/material.dart';
import 'package:vitalapp/pages/check/widgets/exam_device_connect_status/bound_fail.dart';
import 'package:vitalapp/pages/check/widgets/exam_device_connect_status/bounding.dart';
import 'package:vitalapp/pages/check/widgets/exam_device_connect_status/connect.dart';
import 'package:vitalapp/pages/check/widgets/exam_device_connect_status/connect_success.dart';
import 'package:vitalapp/pages/check/widgets/exam_device_connect_status/connect_unbound_device.dart';
import 'package:vitalapp/pages/medical/models/worker.dart';
import 'package:vitalapp/pages/medical/widgets/twelve_ecg_view/widgets/ecg_reconnecting.dart';

class EcgDeviceStatus extends StatefulWidget {
  const EcgDeviceStatus({
    super.key,
    required this.connectStatus,
  });
  final WorkerStatus connectStatus;
  @override
  State<StatefulWidget> createState() {
    return _EcgDeviceStatusState();
  }
}

class _EcgDeviceStatusState extends State<EcgDeviceStatus> {
  WorkerStatus? _connectStatus;

  @override
  Widget build(BuildContext context) {
    return _buildContent();
  }

  @override
  void initState() {
    _connectStatus = widget.connectStatus;
    super.initState();
  }

  @override
  void didUpdateWidget(covariant EcgDeviceStatus oldWidget) {
    if (_connectStatus != widget.connectStatus) {
      setState(() {
        _connectStatus = widget.connectStatus;
      });
    }
    super.didUpdateWidget(oldWidget);
  }

  Widget _buildColumn(Widget status) {
    return Column(
      children: [
        const SizedBox(
          height: 8,
        ),
        status,
      ],
    );
  }

  Widget _buildContent() {
    switch (_connectStatus) {
      case WorkerStatus.connectionFailed:
        return const EcgDeviceConnectDisconnected();
      case WorkerStatus.connected:
        return _buildColumn(
          const DeviceConnectSuccess(),
        );
      case WorkerStatus.connecting:
        return _buildColumn(
          const DeviceConnecting(),
        );
      // case WorkerStatus.disconnected:
      //   return const EcgDeviceConnectDisconnected();
      case WorkerStatus.unboundDevice:
        return _buildColumn(
          const UnboundDevice(),
        );
      case WorkerStatus.boundingDevice:
        return _buildColumn(
          const BoundingDevice(),
        );
      case WorkerStatus.boundDeviceSuccess:
        return _buildColumn(
          const UnboundDevice(),
        );
      case WorkerStatus.boundDeviceFail:
        return _buildColumn(
          const BoundFail(),
        );
      default:
        return const SizedBox();
    }
  }
}
