import 'package:flutter/material.dart';
import 'package:vitalapp/pages/check/widgets/exam_device_connect_status/connect.dart';
import 'package:vitalapp/pages/check/widgets/exam_device_connect_status/connect_disconnected.dart';
import 'package:vitalapp/pages/check/widgets/exam_device_connect_status/connect_fail.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';

class DeviceStatus extends StatefulWidget {
  const DeviceStatus({
    super.key,
    required this.connectStatus,
  });
  final WorkerStatus connectStatus;

  @override
  State<StatefulWidget> createState() {
    return _DeviceStatusState();
  }
}

class _DeviceStatusState extends State<DeviceStatus> {
  WorkerStatus? _connectStatus;

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

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

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

  Widget _buildContent() {
    switch (_connectStatus) {
      case WorkerStatus.connectionFailed:
        return const DeviceConnectFail();
      case WorkerStatus.connected:
        return const DeviceConnectSuccess();
      case WorkerStatus.connecting:
        return const DeviceConnect();
      case WorkerStatus.disconnected:
        return const DeviceConnectDisconnected();
      case WorkerStatus.unboundDevice:
        return const UnboundDevice();
      default:
        return const SizedBox();
    }
  }
}
