import 'package:flutter/material.dart';
import 'package:vitalapp/components/button.dart';

class DeviceConnectFail extends StatelessWidget {
  const DeviceConnectFail({
    super.key,
    this.connect,
  });
  final Function? connect;

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

  Widget _buildTitle(String title) {
    return FittedBox(
      child: Text(
        title,
        style: const TextStyle(color: Colors.red, fontSize: 24),
      ),
    );
  }

  Widget _buildContent() {
    if (connect == null) {
      return Row(
        children: [
          _buildTitle('设备连接失败，重连中'),
          const SizedBox(
            width: 16,
          )
        ],
      );
    } else {
      return Row(
        children: [
          _buildTitle('设备连接失败'),
          const SizedBox(
            width: 16,
          ),
          SizedBox(
            width: 150,
            child: VButton(
              child: Container(
                  child: const Text(
                '重连',
                style: TextStyle(fontSize: 20),
              )),
              onTap: () {
                connect!.call();
              },
            ),
          )
        ],
      );
    }
  }
}
