import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:vitalapp/architecture/utils/nums.dart';
import 'package:vitalapp/components/dialog_number.dart';
import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_card.dart';
import 'package:vitalapp/pages/medical/controllers/waist.dart';

import 'side_bar.dart';

class WaistView extends GetView<WaistDeviceController> {
  const WaistView({super.key});

  @override
  Widget build(BuildContext context) {
    final state = controller.state;
    return ExamCard(
      titleText: const SizedBox(),
      content: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          Obx(
            () => SideBar(
              title: '腰围',
              value: state.waistlineDisplay,
              unit: 'cm',
              onTap: _onWaistlineTap,
            ),
          ),
          const Divider(indent: 30),
          Obx(
            () => SideBar(
              title: '臀围',
              value: state.hiplineDisplay,
              unit: 'cm',
              onTap: _onHiplineTap,
            ),
          ),
          const Divider(indent: 30),
          Obx(
            () => SideBar(
              title: '腰臀比',
              value: state.whrDisplay,
              unit: '',
            ),
          ),
        ],
      ),
    );
  }

  Future<void> _onWaistlineTap() async {
    final state = controller.state;
    String? result = await VDialogNumber(
      title: '腰围',
      initialValue: NumUtils.displayDouble(state.waistline),
    ).show();
    final newValue = double.tryParse(result ?? "");
    controller.onWaistlineChanged(newValue);
  }

  Future<void> _onHiplineTap() async {
    final state = controller.state;
    String? result = await VDialogNumber(
      title: '臀围',
      initialValue: NumUtils.displayDouble(state.hipline),
    ).show();
    final newValue = double.tryParse(result ?? "");
    controller.onHiplineChanged(newValue);
  }
}
